Repository navigation
refactor: migrate to fbgemm_gpu_hstu, remove legacy HSTU compat layer - #321
Conversation
Greptile SummaryThis PR completes the migration of the HSTU attention kernels from the legacy in-tree Key changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[FusedHSTUAttention.forward] -->|hstu_attn_varlen_func| B[hstu package\nauto-dispatch]
B -->|SM 8.x| C[torch.ops.fbgemm.hstu_varlen_fwd_80]
B -->|SM 9.0| D[torch.ops.fbgemm.hstu_varlen_fwd_90]
E[FusedHSTULayerFunction.forward\nCUTLASS path] -->|SM 8| C
E -->|SM 9| D
F[PagedHSTUInferLayer.forward] -->|hstu_attn_varlen_func\n+ paged KV kwargs| B
G[create_hstu_attention] -->|SM in 8,9| A
G -->|other SM| H[TorchHSTUAttention\nfallback]
G -->|TRITON backend| I[TritonHSTUAttention]
C --> J[CUTLASS Ampere kernel]
D --> K[CUTLASS Hopper kernel]
|
3c95fd9 to
6ec37e9
Compare
72fd215 to
213ddbd
Compare
…y HSTU kernels
Add support for the new unified FBGEMM HSTU attention package (fbgemm_gpu_hstu,
import name: hstu) alongside the existing corelib/hstu packages (hstu_attn,
hopper). The new package is prioritized at import time; if unavailable, the
legacy interfaces are used as fallback.
- Dockerfile: install fbgemm_gpu_hstu from jiayus-nvidia/FBGEMM fork
- hstu_attention.py: add _make_new_hstu_compat wrapper to bridge API
differences (seqused_q/k, positional arg reordering, dynamic defaults)
and _import_hstu_attn_func for priority-based import
- paged_hstu_infer_layer.py: try-except import with SimpleNamespace shim
- fused_hstu_op.py: adapter classes mapping legacy C-extension signatures
to torch.ops.fbgemm.hstu_varlen_{fwd,bwd}_{80,90}
- test_hstu_attn_smoke.py, test_paged_hstu_attn_kernel.py: updated imports
to use priority-based fallback
Made-with: Cursor
Mark corelib/hstu as deprecated in its README with migration instructions and link to the new unified package at jiayus-nvidia/FBGEMM. Add a note in the training README where corelib/hstu is referenced. Made-with: Cursor
- Guard Hopper varlen_bwd against empty *args to prevent IndexError - Use from-import style in paged_hstu_infer_layer to catch AttributeError - Add runtime guard for unsupported paged KV-cache kwargs in compat wrapper - Add pytest.skip() when kernel function is None in test_hstu_attn_smoke - Add blank line after except ImportError block in fused_hstu_op Made-with: Cursor
Docker build is non-interactive so pip uninstall prompts for Y/n confirmation and fails with EOFError. Made-with: Cursor
…ule directly - Remove _NewHSTUAmpereCompat, _NewHSTUHopperCompat classes and _make_new_hstu_compat / _import_hstu_attn_func wrappers - Update all call sites to use hstu.hstu_attn_varlen_func directly - Replace git clone with FBGEMM submodule for fbgemm_gpu_hstu in Dockerfile - Update README docs with --recursive clone and submodule install instructions Made-with: Cursor
…e newline - Replace hard top-level imports with pytest.importorskip for fbgemm_gpu and hstu in test files to avoid collection ERRORs on environments without those packages - Add trailing newline to .gitignore (POSIX compliance) Made-with: Cursor
hstu_varlen_bwd_90 expects 11 Optional[Tensor] fp8 descale parameters (q/qt/k/kt/v/do/dot/cu_qt/cu_kt/cu_q_block/cu_kv_block) between func and output_dtype. Without them, output_dtype (int) was passed to q_descale (Optional[Tensor]), causing RuntimeError on H100. Made-with: Cursor
Made-with: Cursor
…OOM during build Made-with: Cursor
…tention class The new hstu_attn_varlen_func auto-dispatches by GPU arch internally, so FusedHSTUAttention and FusedHSTUAttentionHopper had identical forward() implementations. Collapse into a single FusedHSTUAttention for both SM 8/9. Made-with: Cursor
- Add dtype assert for Hopper fwd/bwd output_dtype mapping - Add kv_cache signature check in paged attn test - Fix stale docstring in paged_hstu_infer_layer Made-with: Cursor
6439b89 to
43618e4
Compare
Summary
Migrate the HSTU attention kernel from the in-tree
corelib/hstupackage (per-architecture C-extensionshstu_attn_2_cuda/hstu_hopper_cuda) to the standalonefbgemm_gpu_hstupackage (import hstu), which provides a unified API and auto-dispatches to the appropriate kernel by GPU architecture (SM 8.0 / 9.0).What changed (vs
main)Dockerfile
corelib/hstuinstallation steps.COPY third_party/FBGEMMfrom git submodule andpip installoffbgemm_gpu_hstuwithHSTU_ARCH_LIST="8.0 9.0 10.0".HSTU attention modules
hstu_attention.py: replacedfrom hstu_attn import hstu_attn_varlen_funcwithfrom hstu import hstu_attn_varlen_funcand updated all call sites to the new positional API (addedseqused_q,seqused_k,scaling_seqlenas positional args).paged_hstu_infer_layer.py: same import migration and API update, including paged KV-cache paths.fused_hstu_op.py: replaced calls to legacyhstu_attn_2_cuda/hstu_hopper_cudaC-extensions with direct calls totorch.ops.fbgemm.hstu_varlen_{fwd,bwd}_{80,90}, dispatching bysm_major_version. Added FP8 descaleNoneplaceholders for SM 9.0 backward.Tests
test_hstu_attn_smoke.py,test_paged_hstu_attn_kernel.py: updated imports, usepytest.importorskipfor graceful skips.test_fbgemm_hstu_smoke.py(new): forward + backward smoke test comparing new HSTU kernel against PyTorch reference.Documentation
corelib/hstu/README.md: added deprecation notice pointing tofbgemm_gpu_hstu.examples/hstu/training/README.md: added migration note, updated clone commands to--recursive.Submodule
.gitmodules: addedthird_party/FBGEMM→jiayus-nvidia/FBGEMM(pinned commit04df5361; will switch to upstream once standalone-building fix is merged).Test plan
CI