Skip to content

feat(hstu): enable HSTU + DynamicEmb E2E training on Blackwell (sm_100) - #399

Merged
shijieliu merged 20 commits into
NVIDIA:mainfrom
JacoCheung:junzhang/hstu_blackwell_enable
Jun 15, 2026
Merged

shijieliu merged 20 commits into
NVIDIA:mainfrom
JacoCheung:junzhang/hstu_blackwell_enable

Conversation

@JacoCheung

@JacoCheung JacoCheung commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Enables HSTU + DynamicEmb E2E training on NVIDIA Blackwell (sm_100). Three commits:

  1. HSTU attention kernel on sm_100 — bump FBGEMM submodule so Path A hstu_varlen_fwd_80/90 resolves on Blackwell; bump cutlass-dsl to the 4.4.1 line (earliest one whose AST preprocessor accepts hstu_blackwell relative imports); route sm10 attention through FusedHSTUAttention.
  2. E2E training pipeline on sm_100 — add 10.0 to TORCH_CUDA_ARCH_LIST for FBGEMM Path A / dynamicemb / commons / kvcache_manager; nvcomp tarball arch select for arm64 vs x86; slurm_job.sub exports RANK/WORLD_SIZE so torchrec's local-size detection doesn't fall back on multi-tray; arm64 skips inference-only FlexKV / NVE.
  3. Base image 26.02 → 26.04 — nvcr pytorch 26.04 ships cutlass-dsl 4.4.1 directly, so the in-Dockerfile uninstall/reinstall drops out. FBGEMM submodule pinned to immutable tag. TorchRec install bundled into the same Dockerfile stage as FBGEMM (FBGEMM C++ ops version-coupled); FBGEMM stage uses python3 not python so tritonserver base (no python alias) also builds.

Verified

test_pipeline -k "contextual_feature_names1" passes on:

Arch Result
arm64 (GB200) 8 passed
x86 (B200) 8 passed

Covers DynamicEmb on/off × prefetch/native sparse pipeline × max_num_candidates 0/10, bf16, checkpoint save/load. The -k filter 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

  • CI passes on existing arch (A100 / H100 / L20).
  • B200 smoke job in MR !130 passes on landing.

@greptile-apps

greptile-apps Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR enables HSTU + DynamicEmb end-to-end training on NVIDIA Blackwell (sm_100) across three coordinated commits: routing sm10 attention through FusedHSTUAttention, bumping the FBGEMM submodule and base image from 26.02→26.05, and adding sm_100 to every CUDA architecture list throughout the build pipeline.

  • Blackwell attention path: adds FusedHSTULayerFunction forward/backward branches for sm10 that call the hstu_blackwell CUTLASS kernel (forward) and hstu_varlen_bwd_100 (backward), with explicit head_dim ∈ {64, 128} and num_contextuals=None guards, plus _blackwell_num_contexts_or_none() to coerce contextual counts to None before the kernel call.
  • Dockerfile restructure: introduces a dedicated base_fbgemm stage so the slow FBGEMM+TorchRec build (~55 min) can be cached as a pre-built image; arm64 nvcomp tarball selection via uname -m; 10.0 added to every TORCH_CUDA_ARCH_LIST; triton circular-import workaround added to all Triton op files for torch 26.04; FlexKV/NVE page-size logic parameterized for Blackwell's 128-token page requirement.
  • SLURM: exports RANK, LOCAL_RANK, WORLD_SIZE, LOCAL_WORLD_SIZE from SLURM variables so torchrec local-size detection works correctly on multi-tray deployments.

Confidence Score: 4/5

The 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

Filename Overview
examples/hstu/ops/fused_hstu_op.py Adds sm10 forward and backward branches; forward correctly raises on unsupported head_dim, but the backward's pytorch_hstu_mha fallback for head_dim not in {64,128} is dead code since the forward already raises before any output is produced.
examples/hstu/modules/hstu_attention.py Extends create_hstu_attention to route sm10 to FusedHSTUAttention; FusedHSTUAttention.forward still converts integer num_contextuals=0 to a non-None tensor before passing to hstu_attn_varlen_func (pre-existing gap, noted in prior review).
docker/Dockerfile Splits build into base_fbgemm + devel + build stages; upgrades pytorch base 26.02→26.05; adds arm64 nvcomp arch selection; fixes PYNVE_DISABLE_AVX512 to skip on arm64; adds 10.0 to all CUDA arch lists.
examples/hstu/test/hstu_attn/test_fbgemm_hstu_smoke.py Adds Blackwell-specific pytest.skip guards for unsupported head_dim/contextual combinations; adds test_fused_hstu_op_b200_smoke for full fwd+bwd on sm10; gradient correctness assertions now run for all architectures.
examples/hstu/modules/hstu_processor.py Routes sequence_embeddings cat+view through torch.compiler.is_compiling() to select a compiler-friendly stack+flatten path during torch.compile, avoiding illegal view operations on non-contiguous tensors.
examples/hstu/training/benchmark/scripts/slurm_job.sub Exports RANK/LOCAL_RANK/WORLD_SIZE/LOCAL_WORLD_SIZE from SLURM variables in both srun-with-wrapper and srun-without-wrapper paths; GPU-to-task ratio concerns noted in prior review threads.
examples/commons/utils/perf.py Adds GB200 and B200 to all perf spec dictionaries (tflops, clock_mhz, memory_bandwidth, nvlink); well-covered by the new test_perf.py unit tests.
examples/hstu/ops/pt_ops/torch_addmm.py Adds optional pre-allocated out/silu_out buffers and keep_unfused_out flag; default behavior (all new params at defaults) is identical to before; when keep_unfused_out=False with out=None, z_out is set to silu_out which may also be None.
examples/hstu/training/benchmark/scripts/generate_gin_config.py Makes contextual features optional via --include-contextual flag; adds --kv_channels and --num_attention_heads CLI args; contextual embedding section refactored into an f-string block using in-scope variables.

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
Loading

Reviews (17): Last reviewed commit: "Fix HSTU inference export and Blackwell ..." | Re-trigger Greptile

@JacoCheung
JacoCheung force-pushed the junzhang/hstu_blackwell_enable branch 5 times, most recently from f3ab011 to 7612cfe Compare May 20, 2026 03:09
Comment thread examples/hstu/ops/fused_hstu_op.py Resolved
@JacoCheung

Copy link
Copy Markdown
Collaborator Author

pytorch-26.04 has triton bug. Need newer base image(26.05), which is not publicly available.

@JacoCheung
JacoCheung marked this pull request as draft May 26, 2026 01:26
@JacoCheung

Copy link
Copy Markdown
Collaborator Author

Another constraint is blackwell does not support contextual features. Waiting for #395 .

@JacoCheung
JacoCheung force-pushed the junzhang/hstu_blackwell_enable branch 3 times, most recently from a7f45b5 to e972f7f Compare June 1, 2026 09:37
JacoCheung and others added 14 commits June 9, 2026 09:18
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]>
@shijieliu
shijieliu force-pushed the junzhang/hstu_blackwell_enable branch from 521089e to 85eb3df Compare June 9, 2026 01:18
@JacoCheung
JacoCheung force-pushed the junzhang/hstu_blackwell_enable branch 4 times, most recently from 604e4b1 to fa6c1a6 Compare June 12, 2026 09:52
Squash AOTI action interleave export, Blackwell paged inference addmm support, smoke-test review fixes, and Blackwell inference KV-cache page-size handling.
@JacoCheung
JacoCheung force-pushed the junzhang/hstu_blackwell_enable branch from fa6c1a6 to f8d877c Compare June 12, 2026 10:17
@JacoCheung
JacoCheung marked this pull request as ready for review June 15, 2026 02:40
@JacoCheung
JacoCheung requested a review from shijieliu June 15, 2026 02:41
@shijieliu
shijieliu merged commit 15184ab into NVIDIA:main Jun 15, 2026
@JacoCheung

Copy link
Copy Markdown
Collaborator Author

inference does not work yet. Need another PR to fix.

@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build devel

@JacoCheung

JacoCheung commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #54794723 -- failed

Job Status Log
build_devel_x86 ✅ success view
build_devel_arm64 ✅ success view
build_tritonserver_devel_x86 ✅ success view
build_tritonserver_devel_arm64 ✅ success view
manifest_devel ✅ success view
manifest_tritonserver_devel ✅ success view
pre_check ❌ failed view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
tritonserver_build_x86 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ✅ success view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ❌ failed view

Result: 18/23 jobs passed

View full pipeline

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.

2 participants