|
36 | 36 | from nemo_automodel.components.speculative.eagle.peagle_attention import create_peagle_mask_mod |
37 | 37 |
|
38 | 38 | # flex_attention compiled for the CUDA training path. Inductor's flex backend is |
39 | | -# not available on CPU (it raises ``InductorError``), so ``_peagle_flex_attention`` |
40 | | -# dispatches to eager ``flex_attention`` there -- correct, just slower -- which |
41 | | -# keeps the P-EAGLE unit tests and CPU smoke checks runnable. The compiled |
| 39 | +# not available on CPU, and it currently requires query/key/value head dimensions |
| 40 | +# of at least 16. ``_peagle_flex_attention`` dispatches to eager |
| 41 | +# ``flex_attention`` for unsupported cases -- correct, just slower -- which keeps |
| 42 | +# P-EAGLE unit tests and small CPU/GPU smoke checks runnable. The compiled |
42 | 43 | # callable is lazy, so importing this module on CPU costs nothing. |
43 | 44 | _peagle_flex_attention_compiled = torch.compile( |
44 | 45 | flex_attention, |
45 | 46 | mode="max-autotune-no-cudagraphs", |
46 | 47 | ) |
47 | 48 |
|
48 | 49 |
|
| 50 | +def _peagle_compile_supported(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor) -> bool: |
| 51 | + """Return whether Inductor's flex-attention lowering supports these tensors.""" |
| 52 | + return q.is_cuda and q.shape[-1] >= 16 and k.shape[-1] >= 16 and v.shape[-1] >= 16 |
| 53 | + |
| 54 | + |
49 | 55 | def _peagle_flex_attention(q, k, v, *, block_mask, scale): |
50 | | - """Run the P-EAGLE flex attention, compiling only on CUDA.""" |
51 | | - flex = _peagle_flex_attention_compiled if q.is_cuda else flex_attention |
| 56 | + """Run the P-EAGLE flex attention, compiling only when Inductor supports it.""" |
| 57 | + flex = _peagle_flex_attention_compiled if _peagle_compile_supported(q, k, v) else flex_attention |
52 | 58 | return flex(q, k, v, block_mask=block_mask, scale=scale) |
53 | 59 |
|
54 | 60 |
|
|
0 commit comments