Skip to content

attention: guarded identity online-softmax rescale skip on CUDA and Metal - #4520

Closed
ashhart wants to merge 3 commits into
mainfrom
lead/softmax-identity-skip
Closed

ashhart wants to merge 3 commits into
mainfrom
lead/softmax-identity-skip

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

Online softmax rescales its running state by exp(old_max - new_max) after each key tile; when the maximum doesn't change that factor is exactly 1. This skips the identity work in the served online-softmax updates on CUDA and Metal, behind guards: the shortcut runs only when the maximum is finite and every skipped operand or fast result is finite, so signed zeros, subnormals, NaN payloads and infinities behave as before. TF_CUDA_SOFTMAX_IDENTITY_GUARD / TF_METAL_SOFTMAX_IDENTITY_GUARD (compile-time, default 1) build the unguarded variant from the same sources so the GPU contract compares the two.

Not landing yet

This changes every served attention kernel's default, and the finite checks may cost what they save, so it lands only after the full kernel contract on sm_121, sm_120, M3 Ultra and M5 Ultra (guarded vs unguarded byte equality, planted controls red) and paired whole-request A-B-B-A per family with tokens compared. Kill on any byte or token difference, any slower cell, or under 3% whole-request gain.

@joshuaswarren

Copy link
Copy Markdown
Contributor

Attempted the sm_120 kernel contract on this head (d60f2a4b, RTX 5060 Ti eGPU, aarch64 Linux, driver 615.78.08, zig 0.17.0, /opt/cuda/bin/nvcc, -Dsm=120) — the runner does not compile, so the contract cannot run:

zig/tests/cuda/contract_qwen_vision_attn.zig:197:91: error: expected type '[:0]const u8', found '[]const u8'
            item.* = .{ .rig = .{ .gpu = gpu, .s = s }, .f = try self.mod.function(symbols[i]), ...
zig/src/cuda/module.zig:40:41: note: parameter type declared here
    pub fn function(self: Module, name: [:0]const u8) Error!Function {

contract_qwen_vision_attn.zig is new on this branch (absent on main); symbols[i] needs a sentinel-terminated slice there. I'll rerun kernel-contract on the next head once the runner builds.

Port the shared block-attention fold to attn_fold.cuh, restore MiniMax legacy nonfinite behavior, drop DeepSeek sites without flag-zero metadata identity, preserve tensor-core shared-memory shape, and regenerate all affected serving pins.
@ashhart
ashhart force-pushed the lead/softmax-identity-skip branch from fc50e94 to 0507849 Compare November 27, 2026 07:09
@ashhart

ashhart commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Closing this experiment: exact, but it does not speed anything up.

After two independent reviews we kept only the guard sites whose bit-identity could be proven (nine disputed CUDA sites were restored to main), then ran GB10 A/Bs against main with base/new/new/base ordering:

  • Flash Next NVFP4: tokens identical (0 of 8 rows differ); prompt and decode throughput within -0.7% to +0.4%, i.e. flat.
  • Qwen3.8-27B NVFP4: tokens identical (0 of 8 rows differ); prompt throughput 1.0% to 2.6% lower in every cell, decode 0.2% to 0.6% lower.

Skipping the identity rescale costs a compare and a branch per tile, and on these kernels the saved multiply-and-exponential is not the limiting work. The branch stays available if a kernel ever becomes limited by that rescale.

  • Synthena

@ashhart ashhart closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants