Skip to main content

fastbsa

A CUDA block-sparse attention kernel for consumer Blackwell (sm_120), a drop-in replacement for the Triton BSA that ships with LongCat-Video.

The number

LongCat-Video 720p refinement at its shipped BSA config, on one RTX PRO 6000 Blackwell Server. Per DiT layer per denoising step, median of 50, against an autotuned Triton baseline.

phase LongCat Triton fastbsa
layout 8.20 ms 0 ms fused into the kernel
select 5.48 ms 5.55 ms
attend 132.85 ms 108.12 ms 1.22x
total 146.38 ms 113.98 ms 1.28x

End to end through the real model, the same 96 BSA calls cost 17.10 s on Triton and 11.43 s on fastbsa, a 1.50x speedup.

Install

pip install fastbsa

This compiles the extension against your own torch, so it needs torch >= 2.7, the CUDA 12.8 toolkit and an sm_120 card. A prebuilt sm_120 wheel is attached to each release; it is valid only for the torch version it was built against.

Use

import fastbsa
fastbsa.patch_longcat()

Or call the kernel directly:

from fastbsa import flash_attn_bsa_3d
out = flash_attn_bsa_3d(q, k, v, latent_shape_q, latent_shape_k, sparsity=0.9375,
                        chunk_3d_shape_q=(4, 4, 4), chunk_3d_shape_k=(4, 4, 4))

How it works

LongCat permutes Q, K and V into block-contiguous order before every call; fastbsa evaluates that index map inside the kernel's tile loop, so nothing moves through HBM. Block selection stays in shared memory instead of round-tripping a 446 MB score matrix through torch.topk. The attention kernel is hand-written for sm_120 with mma.sync and cp.async.

Selection reproduces LongCat's exactly, so output is validated against fp32 dense-masked attention. Tests run with pytest tests/.

License

Apache-2.0, see LICENSE. The test suite compares against LongCat-Video's own Triton kernel, vendored under tests/reference/ at the revision in tests/reference/UPSTREAM_REV and licensed under MIT by Meituan. It is test-only and is not part of the installed package.

Metadata

Release files for fastbsa 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastbsa 0.1.0
File Size Uploaded
fastbsa-0.1.0.tar.gz 37.0 kB Details

Release files / fastbsa-0.1.0.tar.gz

Download URL fastbsa-0.1.0.tar.gz
Size 37.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6ad06b135e8581b0d318b97b0f01f92ebf1d09fc7dda6981adb294550e462c46
BLAKE2b-256 checksum
How to use checksums
22514e9d4ee7fcbddbd7a05d87868fb86912d75f84dbd635825048372737c09f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page