Skip to content

fix: cast x buffer offset to int64 to prevent int32 overflow - #980

Open
Chessing234 wants to merge 1 commit into
state-spaces:mainfrom
Chessing234:fix/selective-scan-x-buffer-int32-overflow
Open

fix: cast x buffer offset to int64 to prevent int32 overflow#980
Chessing234 wants to merge 1 commit into
state-spaces:mainfrom
Chessing234:fix/selective-scan-x-buffer-int32-overflow

Conversation

@Chessing234

Copy link
Copy Markdown
Contributor

Summary

  • Cast the x buffer pointer offset to int64_t in the forward and backward selective scan CUDA kernels before multiplying by n_chunks * dstate.
  • Prevents signed int32 overflow when batch * dim * n_chunks * dstate exceeds INT32_MAX, which previously wrapped to a negative offset and silently corrupted memory or caused illegal CUDA accesses.

Fixes #884

Test plan

  • Build CUDA extensions with MAMBA_FORCE_BUILD=TRUE pip install --no-cache-dir --force-reinstall . --no-build-isolation
  • Run selective scan forward/backward with large batch, dim, n_chunks, and dstate where the product exceeds 2^31-1
  • Verify gradients match a smaller configuration that does not overflow
  • Confirm no regression on default/smaller model configs

Made with Cursor

@Chessing234
Chessing234 force-pushed the fix/selective-scan-x-buffer-int32-overflow branch from ff0b91b to f617d69 Compare August 5, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] int32 signed overflow in buffer x

1 participant