Repository navigation
Medical SFT
Stage 2 starts from a native Stage 1 checkpoint, builds a fresh AdamW optimizer and trains all parameters using answer-only causal-LM labels. This is full-parameter SFT—not LoRA, QLoRA or a frozen base.
See finetune_medical.py and medical_data.py.
Medical examples use Question as prompt and Response as completion for the English FreedomIntelligence/medical-o1-reasoning-SFT dataset. The SFT loader constructs system/user/assistant headers, masks the system and user tokens with label -100, and supervises completion tokens (including EOS). The dataset's Complex_CoT field is not used by this schema.
Prerequisites: The Stage 1 checkpoint exists; the Stage 2 configuration matches the checkpoint architecture; the same tokenizer is used for both stages.
python -m scripts.finetune_medical `
--strategy single `
--device cuda `
--config configs/healthcare_moe_single.json `
--tokenizer artifacts/healthcare_tokenizer.json `
--pretrained checkpoints/healthcare_pretrained_5000/last.pt `
--source hf `
--dataset FreedomIntelligence/medical-o1-reasoning-SFT `
--dataset-config en `
--hf-split train `
--schema question_response `
--num-workers 0 `
--seq-len 128 `
--batch-size 1 `
--grad-accum 4 `
--steps 2000 `
--lr 0.00002 `
--warmup-steps 100 `
--eval-every 200 `
--save-every 500 `
--out checkpoints/healthcare_medical_sft_2000Checkpoint naming: If you trained Stage 1 under a different --out, substitute its actual last.pt file. A path ending in step_XXXXXXXX is not the right choice for a single-process .pt checkpoint.
-
--pretrained path/to/Stage1/last.pt: first SFT invocation; loads pretrained model weights only and starts a fresh SFT optimizer. -
--resume path/to/Stage2/last.pt: later SFT invocation; restores SFT weights, optimizer and saved step. -
Never supply both
--pretrainedand--resume. The script intentionally rejects that combination.
The SFT run evaluates answer-only cross-entropy and perplexity on deterministic held-out question partitions. See Checkpoints and Resume and Evaluation and Validation.
Foundations
Data and Training
Operation and Quality
- Checkpoints and Resume
- Evaluation and Validation
- Testing and Reproducibility
- Troubleshooting
- Long Context and Limitations
Architecture diagrams