Repository navigation
Pretraining from Scratch
Stage 1 initializes a native Mixtral-style decoder LM with random weights and trains all model parameters on screened healthcare documents using next-token prediction plus an MoE auxiliary load-balancing term. It does not load pretrained language-model weights.
The following PowerShell command uses the 38.8M-parameter model config documented in Model Configuration, which ships as configs/healthcare_moe_single.json.
python -m scripts.pretrain_healthcare `
--strategy single `
--device cuda `
--config configs/healthcare_moe_single.json `
--tokenizer artifacts/healthcare_tokenizer.json `
--source hf `
--dataset common-pile/pubmed_filtered `
--seq-len 128 `
--batch-size 1 `
--grad-accum 4 `
--steps 5000 `
--repeat `
--lr 0.0003 `
--warmup-steps 500 `
--eval-every 1000 `
--save-every 1000 `
--out checkpoints/healthcare_pretrained_5000Expected schedule: 5,000 optimizer updates; 128 tokens per sequence; batch size 1; gradient accumulation 4; nominally 512 processed tokens per optimizer update and 2,560,000 processed tokens over the run. Repeated corpus passes do not imply unique examples.
- Validates configuration against tokenizer vocabulary and maximum sequence length.
- Initializes the model from random weights and a fresh AdamW optimizer.
- Streams allowlisted healthcare documents, applies eligibility rules, packs token sequences and appends EOS.
- Runs forward/backward passes and optimizer updates with scheduled learning rate.
- Emits training cross-entropy and measured tokens/sec, optionally evaluates held-out pretraining text.
- Saves a checkpoint and, on successful completion, a
training_manifest.jsoncontaining dataset/configuration details.
The example uses single-process execution and does not need torchrun. Separate DDP/FSDP2 strategies are experimental alternatives described by the code, not implied by this example.
checkpoints/healthcare_pretrained_5000/
last.pt
training_manifest.json # written at successful completion
The checkpoint contains model weights, optimizer state, step and model configuration. Its last.pt file is overwritten at checkpoint intervals; it is not a directory named for every step.
To reuse the pretrained model for medical SFT, continue with Medical SFT.
Foundations
Data and Training
Operation and Quality
- Checkpoints and Resume
- Evaluation and Validation
- Testing and Reproducibility
- Troubleshooting
- Long Context and Limitations
Architecture diagrams