mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #224] Fix nonpositive scale ordering in CUDA INT8 attention #239
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#239
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-kitchen/pull/224
Author: @Tokha233
Created: 9/30/2026
Status: 🔄 Open
Base:
main← Head:cuda/nonpositive-attention-scale📝 Commits (3)
96b7062Fix nonpositive scale ordering in CUDA INT8 attention556fb21Merge main and separate attention scale and decode template flagsc664daeSync nonpositive attention scale fix with Kitchen 0.2.40📊 Changes
3 files changed (+63 additions, -15 deletions)
View changed files
📝
comfy_kitchen/backends/cuda/sage_attention/qk_int_sv_i8_cuda.cuh(+20 -14)📝
comfy_kitchen/backends/cuda/sage_attention/sage_attn_launcher.cu(+11 -0)📝
tests/test_int8_attention.py(+32 -1)📄 Description
The ordinary unmasked CUDA INT8 attention kernel can return all-zero output for a negative attention scale when the last KV tile is partial. This patch applies nonpositive scaling before the maximum reduction and before padding masks, while retaining the existing positive-scale specialization.
Cause and change
For a negative
scale,max(QK) * scaleis notmax(QK * scale). The raw-score padding sentinel also becomes a large positive logit after multiplication by a negative scale; at zero scale padding becomes a valid zero logit. Select a separate specialization forscale <= 0, pre-scale the logits, and apply the padding mask in the scaled domain. Masked/prepared routes and positive-scale arithmetic remain unchanged.The existing long/partial-tile test also used an automatically selected BF16 SDPA oracle that returns NaNs for zero/negative scales on the tested build. Use explicit FP32
SDPBackend.MATHand assert its finiteness, without relaxing the existing NRMSE < 0.03 threshold. Add 96 regression combinations covering FP16/BF16, D64/128/256, GQA, single/full/partial KV tiles, both CTA_K sizes and both probability paths; each checks direct and prequantized entry points.RTX 5090 D v2 validation
CUDA 13.0.88, PyTorch 2.12.0+cu130, baseline
19ea55b, patch96b7062. Recompiled the affected launcher TU (the only include site of the changed header) with the baseline CMake flags and unchanged baseline objects.This isolates the inherited failure reported during #218 validation; it does not depend on that performance PR. Other GPU architectures were not runtime-tested here.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.