Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions specforge/algorithms/common/dflash_family_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
if hasattr(torch, "npu") and torch.npu.is_available():
FLEX_ATTENTION_AVAILABLE = False


_VALID_LOSS_TYPES = {
"dflash",
"dpace",
Expand Down Expand Up @@ -363,9 +362,20 @@ def _forward_draft_blocks(
# DFlash's dynamic short-query batches are training/prefill shaped,
# not autoregressive decoding. AUTO may route q_len < 128 to the
# more restrictive flex-decoding kernel, whose config set can be
# empty for DFlash's sparse BlockMask. Keep the general Triton
# empty for DFlash's sparse BlockMask. Force the general Triton
# Flex Attention kernel for every DFlash-family batch.
draft_kwargs["kernel_options"] = {"BACKEND": "TRITON"}
#
# The "BACKEND" kernel_option only exists on torch >= 2.11, where
# the inductor lowering sanitizes it out of the generated Triton
# constexprs. On older builds (including current torch ROCm wheels)
# the string leaks into the kernel as a bare identifier and fails to
# compile (NameError: 'TRITON' is not defined), so we fall back to
# FORCE_USE_FLEX_ATTENTION, which selects the same kernel and has
# been supported since torch 2.5.
if torch.__version__ >= "2.11":
draft_kwargs["kernel_options"] = {"BACKEND": "TRITON"}
else:
draft_kwargs["kernel_options"] = {"FORCE_USE_FLEX_ATTENTION": True}
output_hidden = self.draft_model(
position_ids=full_position_ids,
noise_embedding=noise_embedding,
Expand Down
7 changes: 6 additions & 1 deletion tests/test_modeling/test_dflash_sliding.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ def test_online_wrapper_forces_standard_triton_flex_backend(self):
loss_mask=torch.ones(1, 4),
)

self.assertEqual(layers[0].kernel_options, {"BACKEND": "TRITON"})
expected_kernel_options = (
{"BACKEND": "TRITON"}
if torch.__version__ >= "2.11"
else {"FORCE_USE_FLEX_ATTENTION": True}
)
self.assertEqual(layers[0].kernel_options, expected_kernel_options)


class TestDFlashSlidingConfig(unittest.TestCase):
Expand Down
Loading