Skip to content

Improve AOTI compilation of hstu model - #380

Merged
shijieliu merged 10 commits into
NVIDIA:mainfrom
geoffreyQiu:junyiq/aoti
May 15, 2026
Merged

shijieliu merged 10 commits into
NVIDIA:mainfrom
geoffreyQiu:junyiq/aoti

Conversation

@geoffreyQiu

Copy link
Copy Markdown
Collaborator
  • Better support for dynamic inference shape with torch export & AOTI compilation
  • Add fix for NVE embedding table dynamic shape tracing
  • Add training model to inference model conversion
  • Add benchmark for AOTI compiled model.

@greptile-apps

greptile-apps Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves torch.export and AOTI compilation support for the HSTU ranking model by introducing a new dynamic-shape-aware forward path, a C++ Meta kernel for expand_table_ids, a new permute_and_split op, and a training-to-inference model conversion pipeline (apply_inference). It also refactors ExportableEmbedding to handle separate static and dynamic embedding collections, and adds a Python-side benchmark for the compiled model.

  • New ops and export fixes: expand_table_ids now has a C++ Meta kernel replacing the Python fake; concat_2D_jagged_tensors_fwd_exportable accepts tensor arguments for dynamic-shape tracing; permute_and_split is added to split features between static/dynamic collections without data-dependent Python control flow.
  • Training-to-inference pipeline: apply_inference (and helpers) convert a loaded training model into an exportable inference model, reusing existing module weights.
  • Benchmarking: Python and AOTI-compiled model benchmark loops added to export_inference_gr_ranking.py; a run_one_round C++ benchmark function added to the C++ inference binary.

Confidence Score: 4/5

Safe to merge for development; the static/dynamic config swap in apply_inference_sparse and per-feature D2H syncs in permute_and_split warrant attention before production deployment.

The conversion pipeline is largely correct and collections are wired properly for the forward path. However, apply_inference_sparse passes model_parallel configs as static and data_parallel configs as dynamic — opposite of what the collection assignments imply — leaving stored configs out of sync with their collections. Additionally, permute_and_split issues O(num_features) blocking D2H synchronizations on every inference forward pass.

examples/hstu/modules/exportable_embedding.py (apply_inference_sparse arg ordering and return type); examples/commons/ops/cuda_ops/csrc/kjt_aux_op.cpp (per-feature D2H syncs in permute_and_split_impl)

Important Files Changed

Filename Overview
corelib/dynamicemb/dynamicemb/exportable_tables.py Renamed InferenceEmbeddingTable to InferenceEmbeddingCollection; added load_from_embedding_table for static weights; added apply_inference_embedding_collection using exec() for nested module replacement.
examples/hstu/modules/exportable_embedding.py Major refactor splitting embeddings into static/dynamic collections; apply_inference_sparse has a wrong return-type annotation and swapped config arguments relative to the collection arguments.
examples/commons/ops/cuda_ops/csrc/kjt_aux_op.cpp New permute_and_split op added (CPU+CUDA). The impl uses jagged_offsets.to(kCPU) and per-feature .sum().item() calls causing O(num_features) blocking D2H synchronizations on the inference hot path.
examples/commons/ops/cuda_ops/JaggedTensorOpFunction.py Added is_compiling branch wrapping scalar values in 1-element tensors for torch.export dynamic-shape tracing.
examples/hstu/model/inference_ranking_gr.py Added apply_inference() converting training model to inference in three steps. Type annotation for dynamic_table_configs says Dict[str, int] but semantically it is Dict[str, bool].
examples/hstu/inference/export_inference_gr_ranking.py Refactored to load training model and convert via apply_inference(); added benchmark loops; duplicate import time statement present.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Training Model RankingGR] --> B[apply_inference_embedding_collection]
    B --> C[InferenceEmbeddingCollection static + dynamic]
    A --> D[apply_inference_sparse]
    D --> E[ExportableEmbedding]
    A --> F[apply_inference_hstu_dense]
    F --> G[InferenceDenseModule HSTUBlock + MLP reused]
    E --> H[InferenceRankingGR]
    G --> H
    H --> I[torch.export + AOTI]
    I --> J[model.pt2]
    J --> K[Python benchmark]
    J --> L[C++ benchmark run_one_round]
Loading

Reviews (9): Last reviewed commit: "Apply fix" | Re-trigger Greptile

Comment thread examples/hstu/modules/hstu_processor.py Resolved
@geoffreyQiu

This comment was marked as outdated.

@geoffreyQiu
geoffreyQiu force-pushed the junyiq/aoti branch 2 times, most recently from 733b668 to 147d6ac Compare May 14, 2026 06:54
@geoffreyQiu

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented May 14, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #51257931 -- failed

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

Result: 6/14 jobs passed

View full pipeline

- Clearify torch.Tensor inputs for concat_2D_jagged_tensors related functions
- Fix input of `List[torch.Tensor]` in test_jagged_tensor.py
- Fix import order for `apply_inference_sparse`
- Fix minimum batch size for exporting hstu model
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