Skip to content

Add an example for disabling contextual mask in training - #395

Merged
shijieliu merged 3 commits into
NVIDIA:mainfrom
geoffreyQiu:fix_consistency
May 27, 2026
Merged

shijieliu merged 3 commits into
NVIDIA:mainfrom
geoffreyQiu:fix_consistency

Conversation

@geoffreyQiu

@geoffreyQiu geoffreyQiu commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Add disable_contextual_mask in HSTUConfig to compute HSTU attention kernel without contextual mask, with respect to Meta implementation.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@greptile-apps

greptile-apps Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a disable_contextual_mask boolean flag to HSTUConfig (and the NetworkArgs gin dataclass) that, when set to True, passes None instead of jd.contextual_seqlen as num_contextuals to the HSTU attention kernel, effectively omitting the contextual mask — aligning with the Meta reference implementation. The change is also accompanied by Black-style formatting cleanups across several corelib/dynamicemb/benchmark files and removal of unused imports.

  • Feature: disable_contextual_mask is wired consistently through all three HSTU layer variants (FusedHSTULayer, HSTULayer native, and the debug HSTULayer), the config factory get_hstu_config, the trainer utility create_hstu_config, and the NetworkArgs dataclass; the kuairand_1k_ranking.gin example enables the flag.
  • Cleanup: Four benchmark/utility files receive purely mechanical Black-compatible reformats and unused-import removals (bisect, sys, numpy) with no logic changes.

Confidence Score: 5/5

Safe to merge — the new flag is off by default, all three layer implementations are updated consistently, and the only example that enables it is the kuairand ranking config.

The flag is additive and defaults to False, so existing configs are unaffected. The pattern is applied identically across FusedHSTULayer, native HSTULayer, and the debug HSTULayer, and the plumbing through NetworkArgs, HSTUConfig, and create_hstu_config is complete. Benchmark file changes are purely cosmetic.

No files require special attention.

Important Files Changed

Filename Overview
examples/hstu/configs/hstu_config.py Adds disable_contextual_mask field to HSTUConfig dataclass and get_hstu_config() factory; field is wired through correctly to the return value.
examples/hstu/modules/fused_hstu_layer.py Stores _disable_contextual_mask from config and conditionally passes None instead of jd.contextual_seqlen to num_contextuals in the forward call; logic is correct and consistent.
examples/hstu/modules/native_hstu_layer.py Mirrors the same _disable_contextual_mask pattern as FusedHSTULayer; change is consistent with the other layer implementations.
examples/hstu/modules/debug/debug_hstu_layer.py Applies the same _disable_contextual_mask conditional to num_contextuals in the debug layer; correctly keeps all three layer variants in sync.
examples/hstu/utils/gin_config_args.py Adds disable_contextual_mask: bool = False to NetworkArgs and documents it alongside two previously-undocumented fields (scaling_seqlen, embedding_backend) in the docstring.
examples/hstu/training/configs/kuairand_1k_ranking.gin Sets NetworkArgs.disable_contextual_mask = True in the kuairand example config, enabling the new behaviour for this training example.
examples/hstu/training/trainer/utils.py Threads disable_contextual_mask from NetworkArgs into create_hstu_config; straightforward plumbing change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["gin config / NetworkArgs\ndisable_contextual_mask=True/False"] --> B["create_hstu_config (utils.py)"]
    B --> C["get_hstu_config (hstu_config.py)\nHSTUConfig.disable_contextual_mask"]
    C --> D1["FusedHSTULayer.__init__\n_disable_contextual_mask"]
    C --> D2["NativeHSTULayer.__init__\n_disable_contextual_mask"]
    C --> D3["DebugHSTULayer.__init__\n_disable_contextual_mask"]
    D1 --> E1{"_disable_contextual_mask?"}
    D2 --> E2{"_disable_contextual_mask?"}
    D3 --> E3{"_disable_contextual_mask?"}
    E1 -->|"True"| F1["num_contextuals=None"]
    E1 -->|"False"| G1["num_contextuals=jd.contextual_seqlen"]
    E2 -->|"True"| F2["num_contextuals=None"]
    E2 -->|"False"| G2["num_contextuals=jd.contextual_seqlen"]
    E3 -->|"True"| F3["num_contextuals=None"]
    E3 -->|"False"| G3["num_contextuals=jd.contextual_seqlen"]
    F1 & G1 --> H["HSTU Attention Kernel\n(contextual mask disabled or active)"]
    F2 & G2 --> H
    F3 & G3 --> H
Loading

Reviews (3): Last reviewed commit: "Additional code cleanup" | Re-trigger Greptile

@JacoCheung

Copy link
Copy Markdown
Collaborator

hstu Blackwell does not support context mask as well

@JacoCheung

Copy link
Copy Markdown
Collaborator

/build

@JacoCheung

JacoCheung commented May 26, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #52588300 -- failed

Job Status Log
pre_check ❌ failed view
train_build ✅ success view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ❌ failed view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success view
unit_test_1gpu_h100 ✅ success view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 10/14 jobs passed

View full pipeline

@geoffreyQiu

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented May 26, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Pipeline #52646048 -- success

Job Status Log
pre_check ✅ success view
train_build ✅ success view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ✅ success 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 ✅ success view

Result: 13/14 jobs passed

View full pipeline

@shijieliu
shijieliu merged commit 9d473de into NVIDIA:main May 27, 2026
@JacoCheung
JacoCheung self-requested a review May 27, 2026 07:29
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.

3 participants