Repository navigation
Conversation
ds_attention passes 1/sqrt(sqrt(head_dim)); attention_unfused used it directly as QK^T scale (head_dim^(-1/4)). The correct softmax scale is head_dim^(-1/2), requiring alpha = norm_factor * norm_factor. The fallback binding in the same file (line 378) already does this — this fix aligns attention_unfused with it. Signed-off-by: Guokai Ma <guokai.ma@intel.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ceef30ff39
ℹ️ 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".
| float alpha = norm_factor; | ||
| // ds_attention passes 1/sqrt(sqrt(head_dim)); square it back to the | ||
| // 1/sqrt(head_dim) softmax scale, matching the fallback binding below. | ||
| float alpha = norm_factor * norm_factor; |
There was a problem hiding this comment.
Add an integration test for the changed attention scale
This changes an inference-level attention result but adds no test coverage (the commit's stated test plan is still unchecked). Add and execute a real-device integration test that compares this path's output against an independent attention reference, including the relevant head dimensions, before merging.
AGENTS.md reference: AGENTS.md:L36-L37
Useful? React with 👍 / 👎.
| float alpha = norm_factor; | ||
| // ds_attention passes 1/sqrt(sqrt(head_dim)); square it back to the | ||
| // 1/sqrt(head_dim) softmax scale, matching the fallback binding below. | ||
| float alpha = norm_factor * norm_factor; |
There was a problem hiding this comment.
Add the required Signed-off-by trailer
Commit 10ac5597212375b3a0c04a9bad296eb378c65b98 is a non-merge commit, and git log -1 --format='%b' confirms that its message contains no Signed-off-by: trailer. Add the required DCO sign-off before merging.
AGENTS.md reference: AGENTS.md:L8-L9
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The corrected C++ path lacks regression coverage, and its new comment inaccurately describes non-default configurations.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Corrects attention scaling by squaring norm_factor before the unfused QKᵀ operation.
Changes:
- Applies the expected softmax scaling.
- Documents alignment with the other attention binding.
| File | Description |
|---|---|
csrc/transformer/inference/csrc/pt_binding.cpp |
Corrects unfused attention scaling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| float alpha = norm_factor; | ||
| // ds_attention passes 1/sqrt(sqrt(head_dim)); square it back to the | ||
| // 1/sqrt(head_dim) softmax scale, matching the fallback binding below. | ||
| float alpha = norm_factor * norm_factor; |
| // ds_attention passes 1/sqrt(sqrt(head_dim)); square it back to the | ||
| // 1/sqrt(head_dim) softmax scale, matching the fallback binding below. |
Add test_softmax_context_int8 comparing the legacy int8 attention binding against an independently scaled reference softmax(q@k^T * norm_factor^2) @ v for head_dim 64/128/256 and seq_len 16/128, and clarify that norm_factor is the caller-provided pre-square scale so the comment stays accurate under non-default configurations (use_mup, inverse-layer scaling). Verified on RTX 4080 with torch 2.12.1+cu130: the test fails on the pre-fix binding and passes after the alpha squaring fix. Signed-off-by: Guokai Ma <guokai.ma@intel.com>
d0dc79f to
82ecffe
Compare
|
close as this does not block #8381 works |


Summary
attention_unfusedinpt_binding.cppusesnorm_factordirectly as the QK^T scale, butds_attention.pypasses1/sqrt(sqrt(head_dim))which ishead_dim^(-1/4). The correct softmax scale ishead_dim^(-1/2), requiring the value to be squared.The bug
Same file, two bindings — one squares, one doesn't. The one that doesn't is a bug.
How norm_factor is computed (ds_attention.py)
The binding is expected to square it back to
head_dim^(-1/2).Impact
For
head_dim=64: correct scale is 1/8, buggy scale is 1/2.83 — a 2.8× difference in QK^T score magnitude, causing significantly different softmax distributions.Test plan
F.scaled_dot_product_attentionreference