File size: 2,692 Bytes
11d8066 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Text classification: reassembling pool checkpoints
Each text-classification cell `<arch>__<dataset>` has
| file | content |
|---|---|
| `zoo/<dataset>/<arch>/<model_id>.pth` | base checkpoint (full `model_state_dict`, training config, val metric; word-level models also store the vocabulary `stoi`) |
| `ckpt/text_classification/<arch>__<dataset>/<model_id>/collect_000.pth ... collect_199.pth` | 200 pool checkpoints |
| `metadata/configs/text_classification/<cell>/<model_id>/config.json` | base training config |
| `metadata/configs/text_classification/<cell>/<model_id>/collect_config.json` | collection protocol |
| `metadata/registry/text_classification.json` | one record per cell: base training info, collect config, per-checkpoint logs, pool statistics |
## The token embedding is not in the pool files
The pool is collected by continuing training from the converged base model with a fresh AdamW (small learning rate,
`collect_lr` in `collect_config.json`) and saving one checkpoint every `save_every` steps. During collection the
vocabulary **token-embedding matrix is frozen**, so it is identical in all 200 pool members and in the base model.
It is therefore stored only once, in the base checkpoint, and left out of every pool file.
A pool file is a dict with
- `model_state_dict`: every tensor of the model except the frozen keys (float32);
- `frozen_keys`: the omitted keys, e.g. `["bert.embeddings.word_embeddings.weight"]`; for `t5small` the three tied copies
`transformer.shared.weight`, `transformer.encoder.embed_tokens.weight`, `transformer.decoder.embed_tokens.weight`;
- `frozen_source`: the local path of the base checkpoint at collection time (on the Hub it is the `ckpt_path` of the
registry record, `zoo/<dataset>/<arch>/<model_id>.pth`);
- `collect_step`, `train_step`, `val_metric`, `val_loss`.
The parameters a generator has to produce are `generated_params` in the registry record (total minus `frozen_params`).
## Reassembling a full model
```python
from assemble import assemble
sd = assemble("zoo/agnews/bertbase/bertbase_010.pth",
"ckpt/text_classification/bertbase__agnews/bertbase_010/collect_000.pth")
model.load_state_dict(sd, strict=True)
```
`assemble(base_ckpt_path, pool_ckpt_path)` copies each key in `frozen_keys` from the base's `model_state_dict` into the
pool `model_state_dict` and returns the full state_dict. The same function applies to generated weights: fill the
generated tensors, then add the frozen keys from the base checkpoint. For every cell the collection script checked that
the reassembled `collect_000.pth` reproduces its logged validation metric (`training_info.assemble_check` in the registry).
|