Commit 906c15d
fix(test): disable torch.compile in MTP num_speculative_steps test (#714)
## Summary
- Fix flaky `TestMTPParams::test_varying_num_speculative_steps` by
disabling `torch.compile` on the model instance for this parametrized
test
- Add `torch_compile` parameter to `make_mtp_model()` test helper to
support unwrapping the dynamo-compiled forward
## Root cause
The MTP forward method is wrapped with `torch.compile` at class
definition time. When `test_varying_num_speculative_steps` runs
parametrized cases `[1, 2, 5]` in the same process, `torch.compile`
first traces the forward loop with `effective_steps=1`. Subsequent cases
trigger recompilation for different loop iteration counts, and the
inductor-generated kernels produce NaN losses in bfloat16 on the tiny
test model.
Test ordering across the full CI suite determines the initial compile
cache state (e.g. whether `TestTraining` MTP tests with
`effective_steps=3` ran first), making the failure flaky rather than
consistent.
Evidence:
- Each parametrized case passes **in isolation**
- Running in reversed order `[5, 2, 1]` passes (larger loop compiles
first, smaller recompilations are stable)
- `TORCH_COMPILE_DISABLE=1` → all pass
- `float32` instead of `bfloat16` → 0/60 failures across 20 seeds
## Validation
| | Failures | Runs |
|---|---|---|
| **Without fix** | 16/30 | 8 of 10 runs had failures |
| **With fix** | 0/30 | 10 of 10 runs clean |
## Test plan
- [x] `test_varying_num_speculative_steps[1]` passes
- [x] `test_varying_num_speculative_steps[2]` passes
- [x] `test_varying_num_speculative_steps[5]` passes
- [x] Full `test_model_forward.py` suite passes (134 tests)
- [x] `make quality` (ruff) passes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Orestis Zambounis <orestis.zambounis@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 153ffae commit 906c15d
2 files changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
| |||
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
| |||
0 commit comments