Repository navigation
remove the dead non-Triton attention path from TritonSelfAttention - #8349
Conversation
`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>
There was a problem hiding this comment.
💡 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, |
There was a problem hiding this comment.
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 👍 / 👎.
|
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. |
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>
|
Thanks @delock — done in e93ef3f, following your example diff. Removed PR title and description updated to match. cc @tjruwase |
|
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>
e93ef3f to
a2f8b3c
Compare
|
Thanks @delock — amended. The DCO check was failing because the sign-off name ( |
Problem
TritonSelfAttention.forwardhad a fallback branch that calledself.ds_compute_attention(...), reachable only whenalibi is not Noneor whenthe caller passed
use_triton_attention=False. The call site misspelled thekeyword as
toke_idx=, so the branch raisedTypeError: 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:
TritonSelfAttention.ds_compute_attentionSoftmaxContextOpimport andself.score_context_funcuse_triton_attention=Trueparameter fromforward(grep over therepo finds no other reference to it —
attention.pywas the only file)alibi is not Nonecase now raisesNotImplementedError("TritonSelfAttention does not support alibi")Net
-37/+2in one file.minus_infis kept — it is still used by the Tritonkernel at
attention.py:300.python -m py_compileandpyflakesare clean on the result (the onepyflakesnote,v_offsetassigned but never used at line 255, ispre-existing in the Triton kernel and untouched here).
🤖 Generated with Claude Code