Start by reproducing the mismatch with a minimal, deterministic setup (fixed seed, small batch) and compare intermediate activations and gradients layer-by-layer against the reference. Then isolate and fix issues one at a time, validating each fix with unit tests and loss curves before moving on.
Pro tip: Before diving into code, write down the expected tensor shapes and mathematical operations for each component; many bugs are shape mismatches or incorrect broadcasting that a quick dimensional analysis reveals.
Create a minimal reproducible example with fixed random seeds and a small dataset. Confirm the mismatch exists and measure the exact discrepancy in loss and outputs.
Check that input data, tokenization, masking, and labels are identical to the reference. Ensure no unintended shuffling or normalization differences.
Instrument the model to dump intermediate activations and gradients. Compare each component (embeddings, attention, feed-forward, layer norm) against the reference implementation.
Address one bug at a time, writing unit tests for each component. After each fix, re-run the comparison to ensure the loss curve converges toward the reference.
Once all components match, run the full training script and compare final metrics, convergence speed, and generalization to the reference.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.