mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[GH-ISSUE #178] int8_attention: OverflowError past 299,520 key rows (int32 strides), reachable on long-video workloads #57
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#57
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?
Originally created by @shootthesound on GitHub (Sep 15, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/178
int8_attentionraisesOverflowError: sage_sdpa: tensor strides exceed int32 range; reduce batch/seq/head dimensionsonce the key sequence passes 299,520 rows at 56 heads × 128, with batch size 1.This is reachable on ordinary long-video work rather than an exotic shape. It came up generating a 50-second MiniMax H3 video at 720p: the packed sequence is 314,437 rows, and the call that fails is the one where the text and reference rows attend to the whole timeline.
Where the boundary is
Bisected on a 5090:
The interesting part: 299,520 works and 299,521 fails, but neither stride exceeds int32. At 299,521 the batch stride is 2,147,425,792, still under the limit — so something internal (padding to
cta_k, or a derived stride) crosses it first. 299,520 is exactly64 × 4680, i.e.CTA_K-aligned, which fits that guess but I have not verified it.Also worth noting: batch is 1 here, so
stride(0)is never used to index anything. If the check is on the batch stride specifically, skipping it whenbatch == 1might be a cheap fix for the common single-batch inference case.Repro
Needs about 14 GB of VRAM, since the overflow is a function of element count.
What it means in practice
The limit is a row count, so it arrives sooner the larger the frame — for MiniMax H3 at 24 fps, roughly 101 s at 832×480 but only 47 s at 720p. Video models are exactly the workload that reaches it, and a hard raise means a long render dies at the last step rather than degrading.
For what it is worth, the error is a good one: it refuses rather than computing something wrong, and
OverflowErroris specific enough to catch. We now do catch it, remember the width, and send those rows to PyTorch attention while everything narrower keeps using Kitchen — so this is not blocking us. But an attention backend quietly having a maximum sequence length is worth documenting even if it is not raised, and int64 offsets (or thebatch == 1shortcut) would remove it.Related: #177, which is about the masked path's cost on the same workload.
Environment
comfy-kitchen0.2.31 · RTX 5090, driver 616.86 · torch 2.9.1+cu130 · Python 3.10 · Windows 11Related: the memory cost is not obvious either
Mentioning it here since it is the same call path.
_int8_attention_cudaallocatesq_int8,k_int8,v_int8and their scales on top of the bf16 tensors it is handed. On one block of thesame workload — 4096 queries against a 58,000-key window, 56 heads of 128 — that is roughly:
Which is a fair trade for 3.4× and not a bug. But it does mean a workload can be fast enough and
still not fit, and the failure mode is a hard
OutOfMemoryErrormid-render rather than anythingrecoverable from inside the kernel. A note in the docs that the int8 path trades memory for speed
would have saved us a render; we now catch it and fall back to PyTorch for the affected calls.
@potoior commented on GitHub (Oct 22, 2026):
I'd like to take a look at this — planning to reproduce the boundary with synthetic tensors on a local GPU (batch 1, 56 heads, 128 dim), verify whether it's the unused batch stride or a CTA_K-padded derived stride that actually crosses int32 first, and fix accordingly. PR once I've confirmed.
@potoior commented on GitHub (Oct 22, 2026):
Verified on current main that this is fixed — and added regression coverage in #267.
The check the report bisected (0.2.31's
tensor strides exceed int32 range) was replaced inb54f851("Support larger shapes in cuda int8 attention", Sep 28), which was never linked here. The launcher now bounds only the offsets the kernel actually computes in 32-bit: within-head tile offsets (kv_len * head_dimagainst int32) and the per-product batch/head base strides (each checked against uint32, with a 64-bitOffsetkernel variant selected when a product would exceed it).Reproduced the report's shapes on an NVIDIA Thor (sm_110, torch 2.11.0+cu130, comfy-kitchen main), compared against
scaled_dot_product_attention(nrmse < 0.03):Offsetvariant)The remaining hard limit is the within-head int32 offset check:
kv_len * head_dim > 2^31, i.e. roughly 16.7 M key rows at head_dim 128, which raises a cleanoverflow_errorinstead of computing something wrong — beyond any current hardware. The HIP backend is not affected: it passes every stride as int64.The 64-bit head-base path had no test coverage at all before; #267 locks all of the above in as regression tests (with VRAM guards).