Skip to content

Fea transformer hstu inference 456 - #491

Closed
Junyi-Zheng wants to merge 3 commits into
NVIDIA:mainfrom
Junyi-Zheng:fea-transformer-hstu-inference-456
Closed

Junyi-Zheng wants to merge 3 commits into
NVIDIA:mainfrom
Junyi-Zheng:fea-transformer-hstu-inference-456

Conversation

@Junyi-Zheng

Copy link
Copy Markdown
Contributor

Description

Related to #456.

Add an opt-in Transformer backbone to the existing HSTU recommendation inference workflow, while keeping HSTU as the default.

  • Implement Pre-LN softmax attention and a GELU FFN with causal history and independent candidate attention.
  • Reuse recommendation preprocessing, positional embeddings, postprocessing, and paged KV-cache interfaces.
  • Separate Transformer checkpoint loading from HSTU-specific weight transformations.
  • Propagate backbone selection through ranking inference, Triton, and both AOTI export entry points.
  • Add numerical, cache-consistency, checkpoint, and export regression tests, plus configuration and usage documentation.

Validation

  • CPU regression tests: 132 passed, 3 skipped.
  • Production-layer CPU AOTInductor compilation and replay passed.
  • isort, autoflake, codespell, and black passed for changed files; the configured mypy check passed.
  • git diff --check passed.

Limitations

CUDA-only tests were skipped because the local environment has no NVIDIA GPU. Native cache transfers, CUDA graph execution, complete GPU export, and Triton serving still require validation.

This is a reference padded-SDPA backend; GPU memory and performance have not been benchmarked. It requires its documented Transformer checkpoint layout.

Checklist

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

Reuse recommendation preprocessing and paged KV interfaces, separate checkpoint handling, and wire inference/export entry points. Add numerical and export regression coverage; document pending CUDA and serving validation.

Signed-off-by: Junyi Zheng <[email protected]>
Add public API docstrings and distinguish private layer metadata and capture buffers from the documented checkpoint and graph interfaces.

Signed-off-by: Junyi Zheng <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge.

Summary

Adds an opt-in Transformer backbone while keeping HSTU as the default.

  • Ranking inference can run a Transformer over recommendation histories.
  • Dense checkpoints load according to the selected backbone's weight layout.
  • Ranking inference, Triton, and export entry points accept a backbone choice.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Ranking inputs] --> B[Shared preprocessing]
  B --> C{Backbone selection}
  C --> D[HSTU layers]
  C --> E[Transformer layers]
  F[Paged KV cache] <--> D
  F <--> E
  D --> G[Shared candidate extraction]
  E --> G
  G --> H[Prediction heads]
Loading

Reviews (2) · Last reviewed commit: "Fix Transformer graph metadata refresh a..." · Reviewed by Greptile

@shijieliu

Copy link
Copy Markdown
Collaborator

hi @Junyi-Zheng thanks for your interests to recsys-examples!

@geoffreyQiu could you help review this PR? thanks!

@z52527 z52527 self-assigned this Oct 15, 2026
torch.testing.assert_close(layer._linear_proj_weight, proj)


def test_export_real_layer_dynamic_batch_and_tokens(tmp_path):

@z52527 z52527 Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: this fails for me in the repo's Docker image (torch 2.12.0a0 nv26.05). The exported layer rejects batch_size=1 at replay ("Guard failed: -1 + offsets.size()[0] >= 2"), so the ([2], [1]) case fails. The guard seems to come from tracing offsets[1:] - offsets[:-1] in _pad. The HSTU preprocessing exports and replays fine with batch_size=1, so this looks specific to the Transformer layer. Which torch version did you run this with?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed review and GPU reproductions! I’ve pushed fixes in eb6ffe0:

  1. Changed the CUDA append test to head_dim=64.
  2. Added total_history_lengths to metadata copying and extended the graph test to replay with changed metadata against eager results.
  3. Corrected action lengths, KJT inputs, and expected indexing, and switched preprocessing tests to BF16.
  4. Fixed the batch-size-one export failure by avoiding the derived offset-dimension guard.

My original tests used PyTorch 2.5.1. I reproduced the export failure on 2.12.0; after the fix, both versions pass 135 tests. The 3 CUDA tests remain skipped locally, and the exact NVIDIA 26.05 image still needs verification.

I’d appreciate a recheck in your environment when you have time. Thanks again!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fixes. I re-ran the validation command on eb6ffe0 on an RTX PRO 6000 (SM120) in the repo's 26.07 Docker image: 138 passed, and the three CUDA tests really ran on the GPU, so the four items from my first pass are resolved.

Refresh cached history lengths across graph replays and cover requests with changed metadata. Use the candidate batch dimension for offset gathers so PyTorch 2.12 exports accept a single user. Correct CUDA test head dimensions, action slots and dtype; document pending GPU validation.

Signed-off-by: Junyi Zheng <[email protected]>
position_encoding_config=position_encoding_config,
contextual_max_seqlen=num_contextual_features,
backbone=network_args.backbone,
transformer_ffn_dim=network_args.transformer_ffn_dim,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: the exporters now pass hstu_preprocessing_config, but this call doesn't (nor the one in triton/hstu_model/model.py L213). With a config that enables the item/contextual preprocessing MLPs (e.g. training/configs/benchmark_ranking.gin), the exported model has those MLPs and this one doesn't, so the same checkpoint fails to load here. Could this call and the Triton model pass it too, built the same way as training/trainer/utils.py L85-91?

z52527 added a commit to z52527/recsys-examples that referenced this pull request Nov 16, 2026
Brings in main up to 4466f9d (NVIDIA#478 exportable embedding collections, its
CI follow-ups, DynamicEmb fixes).

The one conflict is at the top of get_exportable_model_for_inference in
inference_aoti/export_inference_gr_ranking.py, where NVIDIA#478 added the
checkpoint_table_capacities lookup and NVIDIA#491 had added a docstring. It takes
main's lines and drops the docstring: no other function of either AOTI
exporter has one, and the Transformer branch's comment says the same.

NVIDIA#478 also renamed the function's dynamic_table_configs parameter to
embedding_collection_configs. The Transformer branch still passes the old
name; the next commit adapts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Runchu Zhao <[email protected]>
@shijieliu

Copy link
Copy Markdown
Collaborator

merged in #531 . Thanks!

@shijieliu shijieliu closed this Nov 17, 2026
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