Skip to content

Prebuilt wheels: drop -lineinfo, unreachable SASS and flash-attn PTX; add extension-free mamba-ssm - #14142

Merged
danielhanchen merged 5 commits into
mainfrom
wheel-slim
Oct 19, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
wheel-slim

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Shrinks the prebuilt causal-conv1d, mamba-ssm and flash-attn wheels further without changing the machine code any GPU runs.

Why

After fatbin compression the wheels are still larger than they need to be:

  • causal-conv1d and mamba-ssm compile with -lineinfo. It only feeds profilers a source line table; cuobjdump -sass shows identical instructions without it, and it is more than half of every cubin.
  • Their setup.py hardcodes SASS for sm_87 (Jetson Orin), sm_110 (Jetson Thor) and sm_121 (GB10 / DGX Spark). Those are integrated Arm GPUs, so x86 wheels can never use it.
  • flash-attn at our pin embeds compute_120 PTX next to the SASS. It can only JIT for GPUs newer than sm_120; upstream 2.8.1 ships SASS only.

Changes

  1. .github/scripts/patch_cuda_targets.py: edits each package's setup.py by asserting on exact text (like patch_mamba_cxx20.py): removes -lineinfo, keeps only the requested SASS, removes flash-attn's PTX line. Unknown or missing targets fail loudly; running it twice is a no-op.
  2. Per-platform target lists in prebuilt_wheels.py: x86 wheels keep sm 75;80;90;100;103;120, linux_aarch64 and win_arm64 keep the full upstream list. flash-attn keeps sm 80;90;100;120.
  3. A targets-gate step after the size gate reads the fatbin headers in every built .so / .pyd (ELF and PE, no cuobjdump needed): every requested SASS present, nothing else, no PTX. Checked against cuobjdump on the published flash-attn Linux wheel and on the Windows causal-conv1d wheel; both current wheels fail the new gate as expected.
  4. Size gates lowered to the new expected sizes; ccache tag changed with the target list.

Expected sizes (installed, extrapolated from compiled translation units)

Package Now x86 after Arm after
flash-attn 229 MB ~176 MB ~176 MB
causal-conv1d 117 MB ~31 MB ~47-53 MB
mamba-ssm 241 MB ~62 MB ~88 MB

Per translation unit (MB, nvcc 13.1, compression on):

File Now Trimmed
causal_conv1d bwd (95% of the package) 108.4 24.8
selective_scan fwd bf16 14.78 3.36
selective_scan bwd bf16 25.78 5.55
flash-attn hdim128 fwd 3.75 2.87

Tests

tests/python/test_prebuilt_cuda_wheels_targets.py (new) plus the existing prebuilt suites: 230 passed. The patch was also run against the real pinned setup.py files.

After merge, the release needs one republish (Windows torch 2.10 to 2.12, then all platforms for 2.13 / 2.14). A machine code diff of old vs new wheels per kept arch and a T4 / L4 kernel A/B follow the build.

Extension-free mamba-ssm wheel

When a run builds mamba-ssm, a CPU-only job also builds mamba_ssm-2.3.2.post1-py3-none-any.whl from the same pinned commit without its CUDA extension (about 224 KB, one file for every OS / torch / Python). Mamba-2 hybrids need only its Triton ops once unsloth-zoo runs their causal conv on Triton (unslothai/unsloth-zoo#1865); Mamba-1 models keep the CUDA wheel.

  • pure-gate: exact filename, no .so / .pyd / .dll / .dylib, Root-Is-Purelib: true, Tag: py3-none-any, then --no-deps install and import of mamba_ssm, mamba_chunk_scan_combined and selective_state_update in a fresh venv; the same import on windows-latest with triton-windows.
  • Sign and publish wait for it like any other planned wheel; runs without mamba-ssm are unchanged. Release notes and SHA256SUMS list it.
  • A local build at the pin is reproducible (identical sha256 across two builds) and passes the gate. 246 prebuilt wheel tests pass.

Measured on real builds (linux_x86_64, cp313, torch 2.13.0+cu130)

Built locally from this branch exactly as the workflow does (nvcc 13.1 here; runners use 13.0):

Wheel Download Installed
causal-conv1d, published today 207.1 MB 262.8 MB
causal-conv1d, compressed only (current republish) 111.3 MB ~122 MB
causal-conv1d, this PR 29.2 MB 39.9 MB
mamba-ssm, published today 349.7 MB 359.3 MB
mamba-ssm, compressed only (current republish) 233.0 MB ~241 MB
mamba-ssm, this PR 53.6 MB 63.0 MB
  • size-gate and targets-gate pass on both (SASS exactly 75;80;90;100;103;120, no PTX); the targets-gate fails the published wheel as expected.
  • Against an untrimmed build with the same nvcc and flags, every kernel's SASS is identical on every kept arch (causal-conv1d 1242 kernels, mamba-ssm 1440, all six archs).
  • T4 and L4, published vs this PR, 6 interleaved repeats: conv forward / backward / decode update, selective scan and the Triton SSD control all within the repeat spread; outputs bitwise equal except selective scan dB / dC, which differ only at the run-to-run level of its atomic backward.

flash-attn was not built locally (6 to 8 hours); its change is the PTX drop only, checked by the targets-gate in the workflow.

…attn PTX

causal-conv1d and mamba-ssm build with -lineinfo, which changes no SASS
(checked with cuobjdump -sass) and is more than half of every cubin. Their
SASS for sm_87, sm_110 and sm_121 targets integrated Arm GPUs, so the x86
wheels drop it while the Arm wheels keep the full list. flash-attn's
compute_120 PTX can only JIT for GPUs newer than sm_120, so it goes too.

A new targets-gate step checks each built wheel with cuobjdump: every
requested SASS present, nothing else, no PTX. Size gates are lowered to the
new expected sizes and the ccache tag changes with the target list.
cuobjdump only reads its host's object format, so a Linux cuobjdump reports a
Windows .pyd as having no device code, and it names PTX entries sm_XX.ptx, which
the compute_XX.ptx pattern never matched. Scan the embedded fatbin containers
directly instead: the same answer on ELF and PE, no toolkit binary needed.
Checked against cuobjdump on the published flash-attn 2.8.4 Linux wheel (96 x
sm_80/90/100/120 SASS plus compute_120 PTX) and on the Windows causal-conv1d
wheel (nine SASS targets).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-19T07:39:44.621184Z 03fcfcb New commits
🔒 Security Review ✅ Completed 2026-10-18T16:01:04.446152Z c87e4a3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: c87e4a3cc6

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c87e4a3cc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Mamba-2 hybrids on transformers 5 only need mamba_ssm's Triton ops plus a causal
conv, which unsloth-zoo runs in Triton, so one py3-none-any mamba_ssm wheel
(224 KB) serves every torch, Python and OS. Whenever a run builds mamba-ssm, a
CPU-only job builds it from the same pin with MAMBA_KEEP_CUDA_BUILD unset,
gates it (exact name, no compiled code, pure WHEEL tag), imports the Triton ops
from a --no-deps install on Linux and on Windows with triton-windows, and hands
it to the existing sign and publish steps. SOURCE_DATE_EPOCH comes from the
pinned commit, so rebuilds are byte identical. Runs without mamba-ssm skip it.
@danielhanchen danielhanchen changed the title Prebuilt CUDA wheels: drop -lineinfo, unreachable SASS and flash-attn PTX Prebuilt wheels: drop -lineinfo, unreachable SASS and flash-attn PTX; add extension-free mamba-ssm Oct 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 9413cb894f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit a9819dd into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the wheel-slim branch October 19, 2026 11:40
danielhanchen added a commit that referenced this pull request Oct 20, 2026
…nsloth-zoo runs their conv on Triton (#14160)

Stacked on #13971. Pairs with unslothai/unsloth-zoo#1865 and the
extension-free mamba-ssm wheel added in #14142.

Mamba-2 hybrids (Nemotron-H, Falcon-H1, Granite-4.0-H, Bamba, Zamba2,
Mamba2) install a 224 KB mamba-ssm wheel without its CUDA extension
instead of the 230 to 594 MB mamba-ssm + causal-conv1d CUDA wheels, when
unsloth-zoo can run their causal conv on Triton.

## Why

On transformers 5.x these models only use mamba-ssm's Triton ops, never
`selective_scan_cuda`. With unsloth-zoo#1865 the causal conv runs on
Triton too. On a Colab T4 (torch 2.10, Falcon-H1-0.5B fp16 LoRA, three
interleaved rounds) that route matches the CUDA wheels: train step +1.4%
(inside the CUDA arm's own spread), decode +1.7% / +1.9%, prefill +0.7%,
identical peak memory.

## Changes

- `ssm_runtime.py` / training worker / export: the pure wheel is used,
and causal-conv1d skipped, only when the config resolves to one of those
six model types, no remote code is needed, torch is a CUDA build with
Triton, transformers is 5.15 or newer, and the installed unsloth-zoo
source carries the Triton drop-ins. `UNSLOTH_MAMBA_CUDA_KERNELS=1` keeps
the CUDA wheels.
- No source build on that route. If the pure wheel is unusable (definite
404, install failure, import failure), the load falls back to today's
CUDA route (causal-conv1d, then CUDA mamba-ssm with the existing
resolver and source build policy). The failure memo is keyed per wheel
source, so a failed pure attempt never blocks the CUDA wheel, and both
routes take the per-env lock one after the other.
- `wheel_utils.mamba_ssm_pure_wheel_url()`.

## Tests

`test_ssm_mamba2_triton.py` (24 tests; the fallback ones exercise the
real `_install_kernel` with lock, memo and cleanup, only network and pip
faked). 509 passed across the clef, export, kernel_install, SSM and
training worker suites.

Not covered: ROCm and macOS stay on the existing route by design;
Windows triton-windows untested on a GPU; Mamba-1 models and
transformers older than 5.15 keep the CUDA wheels.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant