Commit 2b32624
fix(compile): skip in-place weight trims when streaming (on_layer_compiled)
The ONNX streaming path (compile_to_onnx) installs an on_layer_compiled callback
that extracts each layer's weights and NULLs the tensors per layer, bounding peak
memory to one dense layer's worth. The post-loop trim_unused_heads /
trim_unused_slots then sliced those now-None tensors -> 'NoneType' object is not
subscriptable (heads) / 'bool' object has no attribute 'any' (slots), but only for
graphs with UNUSED heads/slots (n < n_heads); small graphs where every head is used
took the no-slice branch, so the onnxruntime-skipped compile_to_onnx tests never
caught it. The DOOM forward (sparse attention: ~1-6 of 40 heads/layer used) trips it.
Skip both in-place trims when on_layer_compiled is set: the streamed sparse export
already drops the zero heads/slots, so the in-memory trim is both impossible (weights
freed) and redundant. Non-streaming compile_headless is unchanged.
Adds tests/compile/forward/test_streaming_trim.py (no onnxruntime needed) — fails
without the fix (TypeError at attn.py:161), passes with it. Validated: full
forward-compile dir green (235 passed); compile_to_onnx of the DOOM token-I/O forward
now completes at 2.18GB peak / 55MB ONNX (was an OOM via dense compile_headless).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 729f6c1 commit 2b32624
2 files changed
Lines changed: 90 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
945 | 945 | | |
946 | 946 | | |
947 | 947 | | |
948 | | - | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
949 | 954 | | |
950 | 955 | | |
951 | 956 | | |
| |||
987 | 992 | | |
988 | 993 | | |
989 | 994 | | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
1001 | 1009 | | |
1002 | 1010 | | |
1003 | 1011 | | |
| |||
0 commit comments