Skip to content

Pretraining from Scratch

Sudhanshu Shukla edited this page Nov 23, 2026 · 3 revisions

Stage 1 — 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.

See pretrain_healthcare.py.

Example: 5,000 optimizer steps

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_5000

Expected 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.

What the script does

  1. Validates configuration against tokenizer vocabulary and maximum sequence length.
  2. Initializes the model from random weights and a fresh AdamW optimizer.
  3. Streams allowlisted healthcare documents, applies eligibility rules, packs token sequences and appends EOS.
  4. Runs forward/backward passes and optimizer updates with scheduled learning rate.
  5. Emits training cross-entropy and measured tokens/sec, optionally evaluates held-out pretraining text.
  6. Saves a checkpoint and, on successful completion, a training_manifest.json containing 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.

Outputs

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.

Clone this wiki locally