Repository navigation
fix(kernels): int64 index offsets in SWITCH LoRA expand (int32 overflow on large intermediate_size, granite-4.1-30b) - #161
Conversation
|
Thanks for tracking this down and for the clear write-up. The fix is good: moving the index math to int64 resolves the 30B crash, and we'd like to merge it. Before we do, we have two small requests. 1. Root cause in the description We think the overflow comes from the The term that does overflow is Your patch already casts
That way a later cleanup won't drop the 2. Regression test Could you add a GPU test that runs the expand kernel with Alternative If you don't have time for either, that's fine. Just say so here, and we'll open a follow-up issue for the test and the doc fix and handle them ourselves. In that case we'll merge this PR as it is after our GPU test suite and benchmark pass. Thanks again! |
|
/gpu-test |
✅ GPU tests passed —
|
❌ GPU tests failed —
|
|
/gpu-test |
2 similar comments
|
/gpu-test |
|
/gpu-test |
|
@yairallouche please note this branch is old, it does not have the new tests from pr 167- thats why it takes nearly 4 hours to run tests, @thinkahead you should probably pull latest from main to get the short tests - you need it anyway to make the branch mergeable |
…2 overflow on large intermediate_size
The SWITCH fused-LoRA expand kernels compute the packed lora_B element
offset as `lb_off_X + a*(N*X) + rX + n_range*X`. These index expressions
were int32, so with a large `N` (= intermediate_size) the offset exceeds
2^31 and the kernel issues an out-of-bounds load:
switch_lora_kernel.py _accum_slice_delta / _switch_lora_expand_kernel
RuntimeError: Triton Error [CUDA]: an illegal memory access was encountered
This reproduces on granite-4.1-30b (intermediate_size=32768) for any
composed adapter at inference time; compose succeeds, the crash is on the
first forward. granite-4.1-3b and -8b (intermediate_size 12800) stay under
the int32 limit, which is why only the 30B class is affected. The trigger
is intermediate_size, not hidden_size (both 8B and 30B are 4096) or layer
count.
Fix: promote the index tensor operands to int64 so the whole offset
arithmetic is 64-bit — `n_range`/`h_range`/`m_range` and the per-tier
`r16..r512` ranges via `.to(tl.int64)` — across the three LBPACK kernels
(`_switch_lora_expand_kernel`, `_accum_slice_delta`,
`_switch_lora_shrink_expand_kernel`). The `lb_off_*` scalars stay Python
ints; promotion happens because a tensor operand in each sum is now int64.
(Note: `tl.int64(x)` is not callable — the cast must be `tensor.to(tl.int64)`.)
Validated on BlueVela (H200): granite-4.1-3b load+generate unchanged (no
regression on the common path), and granite-4.1-30b now loads and
generates where it previously hit the illegal memory access; a 12-domain
30B eval sweep then ran with zero illegal-memory failures.
Signed-off-by: Alexei Karve <[email protected]>
…ion test The int64 casts fix generative-computing#160, but the term that actually outgrows int32 is the x_ext row offset m * stride_xe_m, not the packed lora_B offset: on granite-4.1-30b the gate/up row width is ~65.5k, so a forward of ~32.8k tokens passes 2^31. The lora_B offset only gets there with sum(NA_r * r) > 2^31 / N, which no realistic checkpoint reaches. Say so in the kernel, so a later cleanup does not drop the m_range casts. The new GPU test drives switch_lora_expand and switch_lora_expand_swiglu at the 30B gate/up width with a last row-tile past the int32 limit, and checks the first and last tiles against a torch reference. It needs ~7 GB of free GPU memory and skips otherwise. Signed-off-by: yairallouche <[email protected]> Signed-off-by: Alexei Karve <[email protected]>
c3c1a3b to
3044b26
Compare
|
Rebased onto latest |
|
/gpu-test |
✅ GPU tests passed —
|
What
Fixes an int32 index overflow in the SWITCH fused-LoRA expand kernels that causes a CUDA illegal memory access when serving a composed adapter on large-
intermediate_sizebases (granite-4.1-30b).Fixes #160.
Why
The expand kernels address
x_extasm * stride_xe_m + col, computed in int32. On granite-4.1-30b the shared-MLP gate/up row width is2 × 32768 + shrink columns≈ 65.5k, so once a forward pass reaches about 32.8k tokens (a large prefill or vLLM's profiling run),m * stride_xe_mpasses 2³¹ and the kernel loads from a wrapped address:granite-4.1-8b (
intermediate_size12800, row width ≈ 25.6k) would need about 83.8k tokens in one forward, which is why only the 30B class crashes. The trigger isintermediate_size× tokens per forward, nothidden_size(8B and 30B are both 4096) or layer count.The packed
lora_Boffsetlb_off_r + a·N·r + n·r + kis a much smaller term: it only passes 2³¹ whenΣ(NA_r · r) > 2³¹ / N(32,768 at N = 65,536, e.g. 64 adapters at rank 512 on one module), which no realistic checkpoint reaches. The casts below cover it anyway.How
Promote the index tensor operands to int64 (
m_range/n_range/h_rangeandr16..r512via.to(tl.int64)) in_switch_lora_expand_kernel,_accum_slice_delta,_switch_lora_expand_swiglu_kerneland_switch_lora_shrink_expand_kernel. Every pointer sum includes one of these, so the whole offset is 64-bit. Results are unchanged on shapes that already fit int32. A comment in the kernel records which term overflows, so a later cleanup does not drop them_rangecasts.Tests
tests/unit/test_switch_kernel_int64_offsets.py(GPU, needs ~7 GB free, skipped otherwise) runsswitch_lora_expandandswitch_lora_expand_swigluat the 30B gate/up width with a last row-tile past the int32 limit, and checks the first and last tiles against a torch reference.Validation
On H200:
Notes
tl.int64(x)is not callable (it's a dtype) — the cast istensor.to(tl.int64).tl.dot, but the adapter benchmark should confirm there is no decode/switching speedup regression on small models.