Skip to content

Commit b84db2f

Browse files
authored
fix(speculative): guard PEAGLE flex attention compile (#2443)
Signed-off-by: Alexandros Koumparoulis <akoumparouli@nvidia.com>
1 parent b42152d commit b84db2f

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

nemo_automodel/components/speculative/eagle/peagle_draft.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,25 @@
3636
from nemo_automodel.components.speculative.eagle.peagle_attention import create_peagle_mask_mod
3737

3838
# 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
4243
# callable is lazy, so importing this module on CPU costs nothing.
4344
_peagle_flex_attention_compiled = torch.compile(
4445
flex_attention,
4546
mode="max-autotune-no-cudagraphs",
4647
)
4748

4849

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+
4955
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
5258
return flex(q, k, v, block_mask=block_mask, scale=scale)
5359

5460

tests/unit_tests/speculative/test_peagle.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@
5151
reason="P-EAGLE forward uses flex_attention, which has no CPU autograd support in the CI torch build.",
5252
)
5353

54-
# P-EAGLE's draft forward runs flex_attention, whose autograd is not implemented
55-
# on CPU in the CI torch build (even the forward errors once the inputs require
56-
# grad). Tests that drive the draft forward therefore run on CUDA and are skipped
57-
# when it is unavailable; the pure-tensor / mask-mod / config tests stay on CPU.
58-
_DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
59-
_gpu_only = pytest.mark.skipif(
60-
not torch.cuda.is_available(),
61-
reason="P-EAGLE forward uses flex_attention, which has no CPU autograd support in the CI torch build.",
62-
)
63-
6454

6555
def _build_tiny_draft_model(
6656
*, parallel_drafting: bool = False, mask_token_id: int = 0, device: str = _DEVICE

0 commit comments

Comments
 (0)