Skip to content

SWITCH LoRA kernel: int32 index overflow -> CUDA illegal memory access on large intermediate_size (granite-4.1-30b) #160

Open

Description

@thinkahead

Summary

Serving a composed adapter on granite-4.1-30b crashes at inference with a CUDA illegal memory access from the SWITCH fused-LoRA Triton kernel. Compose succeeds; the crash is on the first forward.

File "granite_switch/kernels/switch_lora_kernel.py", line 435, in switch_lora_expand
    _switch_lora_expand_kernel[grid](...)
RuntimeError: Triton Error [CUDA]: an illegal memory access was encountered

granite-4.1-3b and granite-4.1-8b are unaffected.

Root cause

In the expand kernels the packed lora_B element offset is

lb_off_X + a*(N*X) + rX[:, None] + n_range[None, :]*X

computed in int32. With a large N (= intermediate_size) this exceeds 2^31 and the kernel does an out-of-bounds load.

  • granite-4.1-30b: intermediate_size = 32768 → overflow.
  • granite-4.1-8b: intermediate_size = 12800 → stays under the int32 limit (hence only the 30B class crashes).
  • The trigger is intermediate_size, not hidden_size (8B and 30B are both 4096) or layer count.

Reproduce

  1. compose_granite_switch --base-model ibm-granite/granite-4.1-30b --adapters <any adapter>
  2. Serve the composed checkpoint under vLLM and run a single generation → illegal memory access.

Proposed fix

Promote the index tensor operands to int64 so the offset arithmetic is 64-bit — n_range / h_range / m_range and the per-tier r16..r512 ranges via .to(tl.int64) — in the three LBPACK kernels (_switch_lora_expand_kernel, _accum_slice_delta, _switch_lora_shrink_expand_kernel). The lb_off_* scalars can stay Python ints; promotion happens because a tensor operand in each sum is int64. (tl.int64(x) is not callable — the cast must be tensor.to(tl.int64).)

Validation

On H200: granite-4.1-3b load+generate unchanged (no regression on the common path), and granite-4.1-30b loads and generates where it previously crashed; a 12-domain 30B eval sweep then ran with zero illegal-memory failures.

PR with the fix: thinkahead/granite-switch fix/switch-kernel-int64-overflow.

Activity

  1. added a commit that references this issue on Nov 16, 2026
    c3c1a3b
  2. yairallouche commented on Nov 17, 2026

    @yairallouche
    Collaborator

    Root-cause correction, for the record: the int32 term that overflows 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³¹ (8B, at ~25.6k width, would need ~83.8k tokens). The lora_B offset only overflows when sum(NA_r * r) > 2^31 / N, which no realistic checkpoint reaches. The int64 casts in #161 fix both; #161 now also has a kernel comment and a regression test (tests/unit/test_switch_kernel_int64_offsets.py).

  3. added a commit that references this issue on Nov 22, 2026
    3044b26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions