Skip to content

remove the dead non-Triton attention path from TritonSelfAttention - #8349

Merged
delock merged 4 commits into
deepspeedai:masterfrom
Anai-Guo:fix-triton-attn-toke-idx-typo
Sep 1, 2026
Merged

delock merged 4 commits into
deepspeedai:masterfrom
Anai-Guo:fix-triton-attn-toke-idx-typo

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TritonSelfAttention.forward had a fallback branch that called
self.ds_compute_attention(...), reachable only when alibi is not None or when
the caller passed use_triton_attention=False. The call site misspelled the
keyword as toke_idx=, so the branch raised
TypeError: ds_compute_attention() got an unexpected keyword argument 'toke_idx'
on every entry — i.e. it had never executed.

Fix

Per @delock's review, the branch is dead rather than broken, so it is removed
instead of repaired:

  • delete TritonSelfAttention.ds_compute_attention
  • drop the now-unused SoftmaxContextOp import and self.score_context_func
  • drop the use_triton_attention=True parameter from forward (grep over the
    repo finds no other reference to it — attention.py was the only file)
  • the remaining alibi is not None case now raises
    NotImplementedError("TritonSelfAttention does not support alibi")

Net -37/+2 in one file. minus_inf is kept — it is still used by the Triton
kernel at attention.py:300.

python -m py_compile and pyflakes are clean on the result (the one
pyflakes note, v_offset assigned but never used at line 255, is
pre-existing in the Triton kernel and untouched here).

🤖 Generated with Claude Code

`TritonSelfAttention.ds_compute_attention` declares `token_idx`, but the
non-Triton branch of `forward` passes it as `toke_idx=token_idx`, so every
call down that path raises

    TypeError: ds_compute_attention() got an unexpected keyword argument 'toke_idx'

That branch is taken whenever `use_triton_attention` is False or `alibi` is
not None (the ALiBi models, e.g. BLOOM), so the path is unreachable today.

The sibling implementation this class was copied from,
`DeepSpeedSelfAttention.forward` in `ds_attention.py:173`, spells the same
keyword correctly as `token_idx=token_idx`.

Signed-off-by: Anai-Guo <antai12232931@outlook.com>
@Anai-Guo
Anai-Guo requested a review from tohtana as a code owner August 29, 2026 07:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 083f1398b2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

alibi=alibi,
is_prompt=is_prompt,
toke_idx=token_idx,
token_idx=token_idx,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required Signed-off-by trailer

This is a one-parent, non-merge commit, but its commit message contains no Signed-off-by trailer, so it violates the repository's explicit commit requirement and may fail the DCO/CI gate. Recreate the commit with --signoff using the configured author identity.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

@delock

delock commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Hi @Anai-Guo this is a dead path, can you help remove it? You can reference the following example. Thanks!

Example removal diff (net -40/+3, single file)
diff --git a/deepspeed/ops/transformer/inference/triton/attention.py b/deepspeed/ops/transformer/inference/triton/attention.py
index c2f735b..a409756 100644
--- a/deepspeed/ops/transformer/inference/triton/attention.py
+++ b/deepspeed/ops/transformer/inference/triton/attention.py
@@ -10,7 +10,7 @@ import triton
 import triton.language as tl
 from deepspeed.accelerator import get_accelerator
 from deepspeed import comm as dist
-from deepspeed.ops.transformer.inference.op_binding import LinearOp, VectorMatMulOp, SoftmaxContextOp, QKVGemmOp
+from deepspeed.ops.transformer.inference.op_binding import LinearOp, VectorMatMulOp, QKVGemmOp
 from deepspeed.ops.transformer.inference.triton import (
     softmax,
     score_4d_matmul,
@@ -91,7 +91,6 @@ class TritonSelfAttention(nn.Module):
 
         triton_autotune = self.config.triton_autotune and self.config.layer_id == 0
         self.qkv_func = QKVGemmOp(config)
-        self.score_context_func = SoftmaxContextOp(config)
         self.linear_func = LinearOp(config)
         self.vector_matmul_func = VectorMatMulOp(config)
 
@@ -125,32 +124,6 @@ class TritonSelfAttention(nn.Module):
             context_4d_matmul(output, qkv, head_size)
         Fp16Matmul._update_autotune_table()
 
-    def ds_compute_attention(self, qkv_out, input_mask, layer_past, alibi, is_prompt, token_idx, position_ids):
-        if isinstance(qkv_out, list):
-            qkv_out = qkv_out[0]
-
-        no_masking = input_mask is None
-
-        if no_masking:
-            input_mask = torch.empty(1)
-
-        attn_key_value = self.score_context_func(
-            query_key_value=qkv_out,
-            attn_mask=((1 - input_mask).to(qkv_out.dtype) *
-                       minus_inf) if input_mask.dtype == torch.int64 else input_mask,
-            heads=self.num_attention_heads_per_partition,
-            norm_factor=(1 / self.norm_factor if self.config.scale_attention else 1.0),
-            no_masking=no_masking,
-            layer_id=self.config.layer_id,
-            num_layers=TritonSelfAttention.num_layers,
-            alibi=alibi,
-            is_prompt=is_prompt,
-            token_idx=token_idx,
-            position_ids=position_ids)
-
-        context_layer, key_layer, value_layer = attn_key_value
-        return context_layer, key_layer, value_layer
-
     def forward(
             self,
             input,
@@ -164,7 +137,6 @@ class TritonSelfAttention(nn.Module):
             norm_w=None,
             norm_b=None,
             alibi=None,
-            use_triton_attention=True,
             **kwargs):
 
         if not self.config.pre_layer_norm:
@@ -184,7 +156,7 @@ class TritonSelfAttention(nn.Module):
                                     beta=norm_b)
             qkv = qkv_out[0]
 
-        if use_triton_attention and (alibi is None):
+        if alibi is None:
             context_layer = _triton_attention(qkv=qkv,
                                               input_mask=input_mask,
                                               scale=self.scale,
@@ -196,16 +168,7 @@ class TritonSelfAttention(nn.Module):
                                               triangular=self.triangular_masking)
             key_layer, value_layer = qkv[:, :, self.hidden_size:2 * self.hidden_size], qkv[:, :, 2 * self.hidden_size:]
         else:
-            is_prompt = kwargs.get("first_token", qkv_out[0].shape[1] > 1)
-            token_idx = kwargs.get("token_idx", None)
-            position_ids = kwargs.get("position_ids", None)
-            context_layer, key_layer, value_layer = self.ds_compute_attention(qkv_out=qkv_out,
-                                                                              input_mask=input_mask,
-                                                                              layer_past=layer_past,
-                                                                              alibi=alibi,
-                                                                              is_prompt=is_prompt,
-                                                                              token_idx=token_idx,
-                                                                              position_ids=position_ids)
+            raise NotImplementedError("TritonSelfAttention does not support alibi")
         output = self.vector_matmul_func(input=context_layer, weight=self.attn_ow)
 
         inp_norm = qkv_out[-1]

cc @tjruwase for this change.

Anai-Guo added a commit to Anai-Guo/DeepSpeed that referenced this pull request Aug 30, 2026
Per maintainer review on PR deepspeedai#8349: rather than fixing the `toke_idx` typo
that made this branch raise TypeError, drop the branch entirely.

`TritonSelfAttention.forward` only ever ran `_triton_attention`; the
`ds_compute_attention` fallback was reachable only via `alibi is not None`
or the `use_triton_attention=False` keyword, which nothing in the tree
passes. Removing it also drops the now-unused `SoftmaxContextOp` binding
and `self.score_context_func`. The ALiBi case now raises
NotImplementedError instead of a confusing TypeError.

Signed-off-by: Anai-Guo <antai12232931@outlook.com>
@Anai-Guo Anai-Guo changed the title fix(triton): correct the toke_idx typo that makes TritonSelfAttention's non-Triton branch unreachable remove the dead non-Triton attention path from TritonSelfAttention Aug 30, 2026
@Anai-Guo

Copy link
Copy Markdown
Contributor Author

Thanks @delock — done in e93ef3f, following your example diff.

Removed ds_compute_attention, the SoftmaxContextOp import and self.score_context_func, and the use_triton_attention parameter (a repo-wide search finds no other reference to it, so no caller breaks); the alibi is not None case now raises NotImplementedError. Net -37/+2 in the one file. minus_inf is kept because the Triton kernel at line 300 still uses it.

PR title and description updated to match. cc @tjruwase

@delock

delock commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Hi @Anai-Guo , thanks for your follow up. Can you amend your signoff to fix the DCO failure? Thanks!

Per maintainer review on PR deepspeedai#8349: rather than fixing the `toke_idx` typo
that made this branch raise TypeError, drop the branch entirely.

`TritonSelfAttention.forward` only ever ran `_triton_attention`; the
`ds_compute_attention` fallback was reachable only via `alibi is not None`
or the `use_triton_attention=False` keyword, which nothing in the tree
passes. Removing it also drops the now-unused `SoftmaxContextOp` binding
and `self.score_context_func`. The ALiBi case now raises
NotImplementedError instead of a confusing TypeError.

Signed-off-by: Tai An <antai12232931@outlook.com>
@Anai-Guo
Anai-Guo force-pushed the fix-triton-attn-toke-idx-typo branch from e93ef3f to a2f8b3c Compare August 31, 2026 04:19
@Anai-Guo

Copy link
Copy Markdown
Contributor Author

Thanks @delock — amended. The DCO check was failing because the sign-off name (Anai-Guo) did not match the commit author name (Tai An); the trailer now reads Signed-off-by: Tai An <antai12232931@outlook.com>, matching the author exactly. DCO is green on a2f8b3c. Same tree, no code changes.

@delock
delock enabled auto-merge August 31, 2026 06:46
@delock
delock added this pull request to the merge queue Sep 1, 2026
Merged via the queue into deepspeedai:master with commit 5b6da2b Sep 1, 2026
12 of 13 checks passed
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants