Document the conditioning-tutorial checkpoints
Browse files
README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: stip
|
| 4 |
+
tags:
|
| 5 |
+
- jax
|
| 6 |
+
- flax
|
| 7 |
+
- stochastic-interpolants
|
| 8 |
+
- tutorial
|
| 9 |
---
|
| 10 |
+
|
| 11 |
+
# STIP tutorial checkpoints
|
| 12 |
+
|
| 13 |
+
Small checkpoints used by the [`stip`](https://github.com/instadeepai/stip) tutorial
|
| 14 |
+
notebooks, so that a tutorial can demonstrate sampling without spending ten
|
| 15 |
+
minutes training first. They are toy models (a two-layer MLP, ~50k parameters,
|
| 16 |
+
trained for 1500 steps on a 4-component 2D Gaussian mixture) and have no
|
| 17 |
+
use outside the notebooks.
|
| 18 |
+
|
| 19 |
+
Checkpoints are [Orbax](https://orbax.readthedocs.io) directories written by
|
| 20 |
+
`stip`'s own `TrainingIOHandler`, holding `params`, `opt_state`, `ema_params` and
|
| 21 |
+
`extra` (EMA decay and step count) as separately-restorable items.
|
| 22 |
+
|
| 23 |
+
## `conditioning_and_guidance/`
|
| 24 |
+
|
| 25 |
+
Used by `tutorials/notebooks/4.conditioning_and_guidance.ipynb`. Both models are
|
| 26 |
+
`VelocityGenerativeModel`s over two modalities — `coordinates` (continuous, 2D)
|
| 27 |
+
and `index` (discrete, 4 categories) — with a `FlowMatchingOneSidedInterpolant`.
|
| 28 |
+
|
| 29 |
+
| Path | Model | Role in the notebook |
|
| 30 |
+
|---|---|---|
|
| 31 |
+
| `conditioning_and_guidance/joint_model` | Unconditional cross-modal MLP | Intrinsic guidance (Section 4): conditioning a model that was never trained to be conditional |
|
| 32 |
+
| `conditioning_and_guidance/context_model` | The same MLP plus a label context path, trained with 20% context dropout | Context conditioning and classifier-free guidance (Sections 5-7) |
|
| 33 |
+
|
| 34 |
+
### Loading
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from flax import nnx
|
| 38 |
+
from huggingface_hub import snapshot_download
|
| 39 |
+
from stip.training.checkpointer import Checkpointer, CheckpointerConfig
|
| 40 |
+
|
| 41 |
+
path = snapshot_download(
|
| 42 |
+
"InstaDeepAI/STIP-tutorials", allow_patterns="conditioning_and_guidance/joint_model/*"
|
| 43 |
+
)
|
| 44 |
+
gen_model = ... # build the same model structure as the notebook
|
| 45 |
+
graphdef, params = nnx.split(gen_model, nnx.Param)
|
| 46 |
+
checkpointer = Checkpointer(
|
| 47 |
+
CheckpointerConfig(
|
| 48 |
+
checkpoint_dir=f"{path}/conditioning_and_guidance/joint_model",
|
| 49 |
+
max_to_keep=None, # read-only: never mutate a downloaded directory
|
| 50 |
+
)
|
| 51 |
+
)
|
| 52 |
+
gen_model = nnx.merge(graphdef, checkpointer.restore_ema(params))
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
`restore_ema` reads only `ema_params` and `extra`, and applies the same bias
|
| 56 |
+
correction the training loop uses for evaluation.
|
| 57 |
+
|
| 58 |
+
## Reproducing
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
uv run python tutorials/scripts/train_conditioning_checkpoints.py
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
The script mirrors the notebook's model definitions and PRNG chain, so it
|
| 65 |
+
reproduces these exact weights. A checkpoint pins the parameter structure: if a
|
| 66 |
+
notebook's network changes, re-run the script and re-upload.
|