Grizzlykw's picture
Upload folder using huggingface_hub
a840bec verified
|
Raw History Blame Contribute Delete
3.39 kB
# training
> For contributors retraining or modifying the distillation pipeline. If you're *using* ternlight in an app, see [`packages/ternlight/`](../packages/ternlight). For shipped model artifacts, see [`models/`](../models).
Python pipeline that produces the `.bin` model file consumed by the Wasm engine. Two stages:
```
training/
β”œβ”€β”€ distill/ Stage 1 β€” distillation training (Python, GPU)
β”‚ β”œβ”€β”€ prep/ Phase 1 β€” data preparation (one-time setup)
β”‚ β”‚ β”œβ”€β”€ prepare.py entry point: read config, build cache
β”‚ β”‚ └── ingest.py helpers: loaders, dedup, tokenize, encode, split, manifest, stats
β”‚ β”œβ”€β”€ train.py Phase 2/3 entry point
β”‚ β”œβ”€β”€ trainer.py the training loop
β”‚ β”œβ”€β”€ model.py StudentEncoder + attention + FFN + transformer block
β”‚ β”œβ”€β”€ quantization.py BitLinear swap, embedding ternarization, zero-frac monitor
β”‚ β”œβ”€β”€ loss.py distillation + contrastive
β”‚ β”œβ”€β”€ evaluate.py Phase 4 entry point: go/no-go scorecard (Task 1, 2, 3)
β”‚ β”œβ”€β”€ data.py cross-phase: TernDataset, collate_fn, save_cache, load_cache
β”‚ β”œβ”€β”€ config.py cross-phase: pydantic schemas + YAML loader
β”‚ β”œβ”€β”€ configs/ per-tier configs (micro.yaml, micro-fp32.yaml, small.yaml, smoke.yaml)
β”‚ └── corpora/ local eval data (general.jsonl, tech.jsonl)
└── pack/ Stage 2 β€” bit-pack .pt β†’ .bin (Python, CPU)
β”œβ”€β”€ pack.py read .pt, ternarize embedding, pack 2 bits/weight, write .bin
└── verify.py round-trip a packed .bin and compare against the .pt
```
## When to touch what
- **New training run** β€” edit `distill/configs/*.yaml`, run `distill/train.py`
- **New data source / dedup / sampling logic** β€” `distill/prep/ingest.py`
- **New loss function** β€” `distill/loss.py`
- **Architecture change** β€” `distill/model.py`, then update `distill/configs/*.yaml`
- **Quantization change (training-time or post-train)** β€” `distill/quantization.py` (must stay in sync with `pack/pack.py` β€” they apply the same math at different stages)
- **Bit-packing / .bin format change** β€” `pack/pack.py`
- **Eval methodology change** β€” `distill/evaluate.py` for go/no-go; `eval/regression/` (at repo root) for ongoing quality regression
## Outputs
```
distill/runs/<run-name>/
└── checkpoint_ep<N>.pt float32 shadow weights + config + optimizer state
(NOT committed β€” see .gitignore)
↓ pack.py
pack/out/model.bin packed ternary + projection (the shipped artifact)
(also NOT committed β€” attached to GitHub Release)
↓ scripts/release-model.sh
github.com/.../releases/v0.1.0 per-version model binary download
↓ at npm publish time
packages/semantic/model.bin bundled into the published package
```
## Math reference
What the model actually computes β€” forward pass, backprop, distillation dynamics β€” is documented in [../docs/model-internals.md](../docs/model-internals.md). Read that before changing the training code.
## Status
Pre-alpha. Source code migration from `tern-distill-prototype/poc/` (β†’ `distill/`) and `tern-distill-prototype/export/` (β†’ `pack/`) pending.