mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[GH-ISSUE #136] INT8 GEMM kernels index the output in int32: illegal memory access once m*n >= 2**31 (MiniMax H3 at high resolution x length) #44
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#44
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 @mjungnickel18 on GitHub (Aug 24, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/136
Summary
Both Triton INT8 GEMM kernels in
comfy_kitchen/backends/triton/quantization.py(
_int8_matmul_dequant_kerneland_int8_matmul_dequant_per_row_kernel) compute theoutput address with int32 arithmetic. As soon as
m * n >= 2**31the offset wraps andthe kernel faults with
CUDA error: an illegal memory access was encountered, whichaborts the whole ComfyUI process.
stride_cmisn, so the largest store offset is(m-1)*n + (n-1)and it crosses2**31exactly whenm*ndoes.mis the packed sequence length andnthe projectionwidth, which is why the failure depends on resolution x length rather than on either
one alone.
This is what takes MiniMax H3 down on a 24 GB card above a certain size. It is independent
of dynamic VRAM, pinned memory and the attention backend.
Minimal reproduction (no model, no weights)
One
mper process, because the CUDA context is unusable after the fault:n = 21504, k = 5376are the real MiniMax H3 QKV projection dimensions (the same shapesas in #98).
Measured boundary, three different
n:The crossing sits at
m*n = 2**31in all three cases. Below the boundary the results arenumerically fine (~1 % against a bf16 reference, i.e. plain quantization error), so this is
a hard fault at a fixed index limit and not a gradual accuracy problem.
Stack trace
With
CUDA_LAUNCH_BLOCKING=1the fault is pinned to the kernel launch itself rather thanto a later synchronize:
Without it the error surfaces one frame later, in
triton/testing.py do_bench -> di.synchronize(), which makes it look like an autotuner problem. It is not — theautotuner is simply the first thing that launches the kernel.
Real-world impact (MiniMax H3, RTX 3090 24 GB)
Text-to-video with
minimax_h3_fl2va_pruned_int8_convrotand--enable-triton-backend:1024x576 at 15 s — more frames, fewer pixels — always worked, which matches the
m*nlawrather than a frame-count or VRAM limit.
Ruled out here by direct test:
--disable-dynamic-vram,--disable-pinned-memory,comfy-kitchen 0.2.30 vs 0.2.31 (the kernel file is byte-identical between the two), and the
w4a8 and GGUF weight variants — w4a8 goes through the same
int8_linearand fails at thesame shapes.
Suggested fix
Casting the offsets to int64 in both kernels is enough:
With that applied locally,
m = 200,000, n = 21504runs clean and the output isnumerically correct (~1 % against the reference, the same as below the old boundary), and
both H3 sizes above complete end to end. I have not measured the throughput cost of the
wider index arithmetic; if it turns out to matter, gating the int64 path on
m * n >= 2**31would leave the fast path untouched.Related: #98 (same tall-M H3 shapes, but about config selection and performance) and #64
(same error text on AMD gfx1151, different backend).
Environment