Repository navigation
feat(hstu): enable HSTU + DynamicEmb E2E training on Blackwell (sm_100) - #399
Conversation
Greptile SummaryThis PR enables HSTU + DynamicEmb end-to-end training on NVIDIA Blackwell (sm_100) across three coordinated commits: routing sm10 attention through
Confidence Score: 4/5The core Blackwell training path is functional and tested on both GB200 and B200; the main open risk is the pre-existing unguarded num_contextuals flow in FusedHSTUAttention that was flagged in a prior review and remains unaddressed. The sm10 forward correctly guards head_dim and coerces contextuals to None before the kernel call. The SLURM and Dockerfile changes are structurally sound and tested on both arm64/x86 Blackwell hardware. The one outstanding concern — FusedHSTUAttention.forward converts integer num_contextuals=0 to a non-None tensor before hstu_attn_varlen_func, bypassing the _blackwell_num_contexts_or_none guard — was flagged in a prior review pass and remains unaddressed; a user who configures contextual features with the CUTLASS backend on Blackwell would hit a kernel assertion at runtime. examples/hstu/modules/hstu_attention.py — FusedHSTUAttention.forward integer-to-tensor conversion of num_contextuals bypasses the Blackwell contextual guard; examples/hstu/ops/fused_hstu_op.py — unreachable pytorch_hstu_mha backward fallback. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["hstu_attn_varlen_func call"] --> B{"sm_major_version?"}
B -->|8| C["hstu_varlen_fwd_80\n(Ampere CUTLASS)"]
B -->|9| D["hstu_varlen_fwd_90\n(Hopper CUTLASS)"]
B -->|10| E{"head_dim in {64,128}?"}
E -->|Yes| F["_blackwell_num_contexts_or_none\nassert num_contexts is None"]
F --> G["hstu.hstu_attn_varlen_func\n(Blackwell CUTLASS)"]
E -->|No| H["raise ValueError"]
G --> I{"Backward"}
I --> J["hstu_varlen_bwd_100\n(sm100_ops)"]
I -.->|dead code| K["pytorch_hstu_mha fallback\n(unreachable: fwd raised)"]
style K fill:#ffcccc,stroke:#ff0000,stroke-dasharray: 5 5
style H fill:#ffcccc,stroke:#ff0000
Reviews (17): Last reviewed commit: "Fix HSTU inference export and Blackwell ..." | Re-trigger Greptile |
f3ab011 to
7612cfe
Compare
|
pytorch-26.04 has triton bug. Need newer base image(26.05), which is not publicly available. |
|
Another constraint is blackwell does not support contextual features. Waiting for #395 . |
a7f45b5 to
e972f7f
Compare
Path B fbgemm_gpu_hstu sm_100 forward+backward smoke validated on GB200:
1 passed in 26.83s
pytest -xvs examples/hstu/test/hstu_attn/test_fbgemm_hstu_smoke.py
→ test_fbgemm_hstu_fwd_bwd[0-10-4-64-200-32]
Three minimum changes:
- third_party/FBGEMM: 65bad42a → 5f13f139
Branch jiayus-nvidia/FBGEMM:junzhang/dev_with_export_and_patch, off upstream
dev with two cherry-picks from torch_exportable_cuda13 (setup.py fix +
register_fake for torch.export) and one new commit dropping the
load_library < (10,0) gate so register_fake can resolve
fbgemm::hstu_varlen_fwd_{80,90} on Blackwell. hstu_blackwell/* kept on
relative imports so the same source installs under both Path A
(fbgemm_gpu.experimental.hstu.*) and Path B (top-level hstu.*).
- docker/Dockerfile: bump nvidia-cutlass-dsl 4.3.0 → 4.4.1 (uninstall + fresh
install, since 4.x layout changes break a straight upgrade). 4.4.1 is the
earliest version whose AST preprocessor handles `from . import X` —
verified by reading ast_preprocessor.py source from both wheels.
- docker/Dockerfile: HSTU_ARCH_LIST 8.0 9.0 → 8.0 9.0 10.0 (Path B build).
- examples/hstu/modules/hstu_attention.py: route sm10 through
FusedHSTUAttention (cutlass backend) instead of the print-and-fallback
TorchHSTUAttention path.
- test_fbgemm_hstu_smoke.py: skip sm10-unsupported cases (head_dim not in
{64,128}, num_contextuals>0) and run BWD section.
Extends the kernel-only enablement to the full E2E training stack (DynamicEmb + commons jagged ops + kvcache_manager + multi-node SLURM launcher). HSTU attention kernel itself is enabled in the previous commit. - docker/Dockerfile Layer 3: add 10.0 to fbgemm_gpu Path A's TORCH_CUDA_ARCH_LIST (DynamicEmb's torch_binding stage links against Path A's libs, so sm_100 has to be in there). - docker/Dockerfile build stage: thread TORCH_CUDA_ARCH_LIST with 10.0 into dynamicemb / examples/commons / corelib/recsys_kvcache_manager setup.py invocations so their CUDA C++ ops compile for sm_100. - docker/Dockerfile build stage: nvcomp tarball URL now picks linux-sbsa on aarch64 (GB200), linux-x86_64 on x86_64. The x86_64-only tarball used to fail to link with libnvcomp_static.a on GB200. - corelib/dynamicemb/CMakeLists.txt: add 100 to CMAKE_CUDA_ARCHITECTURES default. - corelib/dynamicemb/setup.py: add -gencode arch=compute_100,code=sm_100 to nvcc flags. - examples/hstu/training/benchmark/scripts/slurm_job.sub: export RANK / LOCAL_RANK / WORLD_SIZE / LOCAL_WORLD_SIZE from SLURM env. On multi-tray runs (e.g. NVL72 18×4) torchrec.get_local_size() falls back to torch.cuda.device_count() if LOCAL_WORLD_SIZE is unset, which mismatches the actual tasks-per-node and produces DynamicEmb sharding placement errors.
…nstall
- docker/Dockerfile:
* Bump nvcr.io/nvidia/pytorch base from 26.02-py3 to 26.04-py3.
26.04 already ships nvidia-cutlass-dsl 4.4.1, the earliest version
whose AST preprocessor handles 'from . import X' in hstu_blackwell.
* Drop the uninstall + reinstall of nvidia-cutlass-dsl{,-libs-base,
-libs-cu13} that PR NVIDIA#379 (Beam search) added to handle the 4.3.x
shipped by 26.02. On 26.04 it's a same-version round-trip that costs
~1-2 min of build time with no correctness benefit.
* Keep the cute_arch import check as a light verification.
* Keep the quack-kernels / apache-tvm-ffi / torch-c-dlpack-ext install
(added by PR NVIDIA#379, needed by beam search regardless of base version).
- .gitmodules: add 'branch = recsys-examples-v26.05' for third_party/FBGEMM
so the submodule tracks the immutable tag (jiayus-nvidia/FBGEMM:
recsys-examples-v26.05 → commit 5f13f139) instead of the moving
junzhang/dev_with_export_and_patch branch tip. Submodule SHA is
unchanged.
Hoist the slow Path A fbgemm_gpu build (~55 min) out of devel into a
dedicated base_fbgemm stage at the top of the Dockerfile. The new layout:
BASE_IMAGE -> base_fbgemm -> devel -> build
base_fbgemm contains a single RUN that installs scikit-build + the
explicit cutlass-DSL build deps, clones FBGEMM v1.5.0, and runs the
fbgemm_gpu setup.py against TORCH_CUDA_ARCH_LIST='7.5 8.0 9.0 10.0'.
Everything else (system setup, Megatron-LM, pip deps, TorchRec,
flash-attention cute, FlexKV/NVE, HSTU Path B) now lives in devel,
which FROMs ${BASE_FBGEMM_IMAGE}.
Override BASE_FBGEMM_IMAGE via --build-arg to consume a pre-built
fbgemm image and skip the ~55 min compile (CI side: build_fbgemm
stage gated on BUILD_FBGEMM=1 produces it).
Dockerfile comments also trimmed — removed running session/PR-history
references and cutlass-dsl version-bump notes.
TorchRec links FBGEMM C++ ops at install time, so the two are version- coupled. Moving TorchRec into base_fbgemm keeps them in lockstep and removes one layer from the devel stage.
nvcr.io/nvidia/tritonserver:25.11-py3 ships only python3, no python alias. Stage 1 base_fbgemm runs before stage 2's 'ln /bin/python3 /bin/python' (which is in the tritonserver-only branch of Layer 1), so 'python setup.py install' fails with command not found. Switching to 'python3 setup.py' works on both bases (pytorch base has both python and python3; tritonserver only python3).
Pin was added when base was an older pytorch image; 26.04 now ships a newer triton (3.7+). Downgrading to 3.6.0 breaks torch._higher_order_ops.triton_kernel_wrap which references 'create_tma_experimental_metadata' (new in triton 3.7+), causing ImportError during unit_test_1gpu_a100 (job 322376439).
tritonserver:25.11-py3 lacks python alias, cmake/patchelf, and torch itself. FBGEMM Path A (stage 1) needs all three before it can run 'python3 setup.py install' (setup.py does 'import torch' at line 21). Move the TRITONSERVER_BUILD bootstrap (python symlink, cmake/patchelf apt install, pandas/rich/cloudpickle/psutil/cython pip, torch pip via cu130 index) from stage 2 Layer 1 to stage 1 'Layer 0-pre'. Pytorch base skips this branch. stage 2 Layer 1 now only handles apt liburing/xxhash/ssl + arch symlinks (unchanged for both bases). ARG TRITONSERVER_BUILD kept in stage 2 as a guard for future re-use; current Layer 1 no longer references it. Stage 3 still gates the libcuda symlink / dynamicemb cmake on TRITONSERVER_BUILD, unchanged.
FBGEMM v1.5.0 fbgemm_gpu/setup.py line 24 imports 'tabulate'. pytorch base image happens to ship it; tritonserver base does not, so the stage-1 FBGEMM Path A build fails with ModuleNotFoundError on tritonserver. Add tabulate to the Layer 0a pip install alongside setuptools-git- versioning and scikit-build.
nvcr/pytorch:26.04-py3 has a circular import in torch._higher_order_ops. triton_kernel_wrap: when wrap_triton() is first called it lazy-loads triton_kernel_wrap, which at line 24 imports torch._inductor.dependencies; that triggers full _inductor / _dynamo init which transitively executes torch._dynamo.variables.functions line 2881 'from torch._higher_order_ops. triton_kernel_wrap import (create_tma_experimental_metadata, ...)' while triton_kernel_wrap is still partially initialised -> ImportError. Pre-loading torch._inductor.dependencies at the top of every triton-using module forces the cycle to resolve in a sequence that avoids the partial- init lookup (entry is via _inductor instead of triton_kernel_wrap). Verified on s4124-0071 against devel_pt26.04_v1.5.0: - test_addmm.py 12 passed (was 12F before) - test_hstu_layer.py 192 passed - test_hstu_op.py 3536 passed (16 skipped) - test_hstu_preprocess.py 8 passed - test_ln_mul_dropout.py 34 passed - test_ln_silu.py 8 passed - test_triton_silu.py 27 passed
tabulate is a FBGEMM v1.5.0 setup.py import that nvcr/pytorch:26.04-py3 already ships but nvcr/tritonserver:25.11-py3 does not. Move from the unconditional Layer 0a pip install into the TRITONSERVER_BUILD=1 bootstrap block alongside the other tritonserver-specific deps. Pytorch base no longer pays the (tiny) pip dependency-check cost; both bases land at the same effective state going into FBGEMM Path A.
…E env Previously arm64 skipped the entire FlexKV + NVE block. Restore the x86 build chain on both archs; only difference is the PYNVE build env: arm64: AVX512 doesn't exist, leave PYNVE_DISABLE_AVX512 unset x86: PYNVE_DISABLE_AVX512=1 (existing behavior) Also bump FlexKV/NVE TORCH_CUDA_ARCH_LIST to include 10.0 (Blackwell), matching stage 1 / stage 3. Drop the post-install 'from flexkv.kvmanager import KVManager' check: that import dlopens C++ extensions linked to libcuda, which is not guaranteed to be visible inside the buildkit container (it relies on runtime nvidia-container-toolkit driver injection that may not apply on arm64 builders). setup.py returning 0 already verifies the build.
nvcr.io/nvidia/tritonserver:25.11-py3 doesn't ship ninja. Without it, torch BuildExtension silently falls back to distutils' serial _compile (MAX_JOBS unused), so HSTU's ~150 .cu files build one-at-a-time. On a4u8g-0015 the running build_tritonserver_devel_x86 takes ~3h with a single nvcc; ninja restores >100 parallel nvcc — observed in container test: nvcc=108, cc1plus=135 within seconds of launch. Co-Authored-By: Claude Opus 4.7 <[email protected]>
521089e to
85eb3df
Compare
604e4b1 to
fa6c1a6
Compare
Squash AOTI action interleave export, Blackwell paged inference addmm support, smoke-test review fixes, and Blackwell inference KV-cache page-size handling.
fa6c1a6 to
f8d877c
Compare
|
inference does not work yet. Need another PR to fix. |
|
/build devel |
|
❌ Pipeline #54794723 -- failed
Result: 18/23 jobs passed |
Summary
Enables HSTU + DynamicEmb E2E training on NVIDIA Blackwell (sm_100). Three commits:
hstu_varlen_fwd_80/90resolves on Blackwell; bump cutlass-dsl to the 4.4.1 line (earliest one whose AST preprocessor acceptshstu_blackwellrelative imports); route sm10 attention through FusedHSTUAttention.slurm_job.subexports RANK/WORLD_SIZE so torchrec's local-size detection doesn't fall back on multi-tray; arm64 skips inference-only FlexKV / NVE.python3notpythonso tritonserver base (no python alias) also builds.Verified
test_pipeline -k "contextual_feature_names1"passes on:Covers DynamicEmb on/off × prefetch/native sparse pipeline × max_num_candidates 0/10, bf16, checkpoint save/load. The
-kfilter excludes the context-mask cases the sm_100 kernel doesn't yet support.CI
Companion CI MR (multi-arch base_fbgemm + devel manifests, plus B200 smoke job, separate tritonserver FBGEMM cache): !130
(internal: https://gitlab-master.nvidia.com/Devtech-Compute/distributed-recommender/-/merge_requests/130 )
Test plan