Skip to content

[FEA] Support configurable indexing and NVE layers for exportable embedding collections - #478

Merged
shijieliu merged 32 commits into
NVIDIA:mainfrom
geoffreyQiu:feature/exportable-embedding-table-fusion
Nov 13, 2026
Merged

shijieliu merged 32 commits into
NVIDIA:mainfrom
geoffreyQiu:feature/exportable-embedding-table-fusion

Conversation

@geoffreyQiu

Copy link
Copy Markdown
Collaborator

Summary

Extend DynamicEmb exportable inference embedding collections with configurable indexing and NVE storage.

The conversion API now accepts an InferenceEmbeddingCollectionConfig for each physical embedding collection instead of selecting the implementation through use_dynamic.

What changed

  • Add configurable FusedIdentityIndexer, LinearHashMapIndexer, and BitConcatIndexer.
  • Support NVE GPU, LinearUVM, and hierarchical layers.
  • Construct hierarchical tables directly through their parameter server using fused keys and embeddings.
  • Keep data-backed indexer state and NVHashMap contents outside the exported PT2 package as sidecars.
  • Support Redis-backed hierarchical-table incremental updates through the update coordinator and runtime subscriber.
  • Add Python and C++ loading paths for exported indexer state.
  • Add an end-to-end export, AOTI replay, sidecar loading, and incremental-load example.
  • Update HSTU inference conversion and export call sites to pass the new collection configuration.

Verified combinations

Indexer NVE layer/backend
FusedIdentityIndexer GPU
LinearHashMapIndexer LinearUVM
LinearHashMapIndexer Hierarchical NVHashMap
LinearHashMapIndexer Hierarchical Redis
BitConcatIndexer Hierarchical NVHashMap
BitConcatIndexer Hierarchical Redis

BitConcatIndexer is intentionally limited to hierarchical layers. Its table-ID and feature-ID bit widths are fixed by the model configuration.

Validation

  • Passed the NVE 26.07 end-to-end GPU workflow.
  • Verified all six embedding-collection combinations.
  • Verified eager and Python AOTI execution.
  • Verified C++ AOTI replay with sidecar loading.
  • Verified Redis incremental loading through the coordinator/subscriber path.
  • The example includes the NVE 26.05-compatible four-combination path; separate 26.05 GPU validation remains pending.

Commit organization

The draft is organized into three commits so it can later be split if needed:

  1. Reusable DynamicEmb exportable-embedding implementation.
  2. End-to-end DynamicEmb example and verification workflow.
  3. HSTU integration with the new APIs.

Checklist

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

@geoffreyQiu
geoffreyQiu force-pushed the feature/exportable-embedding-table-fusion branch from a63329d to 70063d5 Compare September 4, 2026 04:35
@geoffreyQiu
geoffreyQiu force-pushed the feature/exportable-embedding-table-fusion branch 15 times, most recently from a23418e to 2c154a9 Compare September 17, 2026 10:41
@geoffreyQiu
geoffreyQiu force-pushed the feature/exportable-embedding-table-fusion branch 2 times, most recently from 23b814b to fe41b36 Compare October 26, 2026 08:34
@geoffreyQiu
geoffreyQiu marked this pull request as ready for review October 28, 2026 02:49
@geoffreyQiu

Copy link
Copy Markdown
Collaborator Author

/build devel=1

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The changes reach shared DynamicEmb inference and live embedding-update workflows.

The PR needs a clear restriction or working update path for Redis hash collections with embedded indexer state before merging.

Findings

  1. P1 Embedded hash updates fail ▶

Summary

Adds configurable indexers and NVE storage for exportable embedding collections.

  • Each inference collection can choose how IDs map and where embeddings live.
  • Exported models can load their indexer mappings from sidecar files.
  • Redis-backed collections can apply embedding and indexer updates while serving.
  • DynamicEmb collections can load checkpoint values for CPU Host inference.
  • HSTU inference passes a storage and indexer choice for each collection.
  • KV-cache waits use the task IDs returned by FlexKV.
  • Build and supporting edits leave their user-visible behavior unchanged.

Previous threads were supplied without comment numbers, so they remain context rather than numbered classifications. geoffreyQiu accepted responsibility for keeping BitConcat IDs within their configured bit widths. geoffreyQiu also deferred source-archive packaging because supported installs use full checkouts or built wheels.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Source[Checkpoint rows] --> Indexer[Configured indexer]
  Indexer --> Storage[NVE embedding storage]
  Indexer --> Sidecar[Optional indexer sidecar]
  Storage --> Export[Exported model and NVE resources]
  Sidecar --> Replay[Python or C++ replay]
  Export --> Replay
  Delta[Training delta] --> Coordinator[Update coordinator]
  Coordinator --> Redis[Redis backing table]
  Coordinator --> Subscriber[Runtime subscriber]
  Subscriber --> Cache[NVE cache tiers]
  Subscriber --> Mapping[Updated indexer snapshot]
Loading

Reviews (11) · Last reviewed commit: "fix(dynamicemb): preserve explicit erase..." · Reviewed by Greptile

@geoffreyQiu
geoffreyQiu force-pushed the feature/exportable-embedding-table-fusion branch from e7ab447 to 6782c3c Compare October 28, 2026 13:49
Comment thread corelib/dynamicemb/setup.py Resolved
Comment thread corelib/dynamicemb/README.md Resolved
@geoffreyQiu
geoffreyQiu force-pushed the feature/exportable-embedding-table-fusion branch from 95cb7aa to 1f6176b Compare November 3, 2026 16:23
Comment thread corelib/dynamicemb/setup.py Resolved
geoffreyQiu and others added 13 commits November 13, 2026 18:18
Promote the eager/Python AOTI/C++ AOTI process workflow to the existing entry point and remove the in-process runner and duplicate example directory. Keep shared fixtures, assertions and transport helpers in workflow_utils.py.

Preserve NVE 26.05 initial replay and existing Redis launcher behavior. Verified five demo modes on A100, unchanged modern worker phases, exact output parity, and focused pre-commit checks.
Add DYNAMICEMB_CPU_ONLY to build CPU indexers, Python bindings, sidecar
loading and Host updates without training, TorchRec or CUDA execution
modules. Isolate CPU build outputs from the default CUDA build and share
operator schemas and Meta kernels so CPU graph export works.

Support Python and C++ AOT replay with CPU-only PyTorch and stock
driverless NVE. Keep the standalone CPU indexing target and document
NVE's minimal build options and the build-to-test workflow. Native
compilation still uses the CUDA toolkit; deployment requires only
cudart from CUDA, with no GPU or driver.

Validation: 86 CPU tests passed (52 GPU cases skipped); Python/C++ AOT
replay and incremental updates passed for all three Host indexers.
Standalone CPU indexing/export, CUDA operator build/registration smoke
and pre-commit passed. Existing demo behavior and synchronization are
unchanged.

Co-authored-by: mjiang2 <[email protected]>
Carry erased_keys through the example coordinator IPC payload. Keep older payloads without that field readable. Cover erase-only delivery through a real coordinator subprocess for BitConcat and LinearHashMap, including warm caches and Redis retirement.
@shijieliu
shijieliu force-pushed the feature/exportable-embedding-table-fusion branch from 353d510 to 2b96389 Compare November 13, 2026 10:18
@shijieliu
shijieliu merged commit a994d00 into NVIDIA:main Nov 13, 2026
1 check passed
shijieliu added a commit that referenced this pull request Nov 15, 2026
…without MPS (#556)

* [FIX] HSTU: the TP layer norm takes a rank's empty batch

HSTUSequenceDataset pads a rank's share of the last global batch with empty
samples, so when the eval set does not fill that batch a DP rank can get no
sample at all: its TP ranks run the model on T = 0 tokens, and
TPLayerNormMulDropout's u.view(T, -1) cannot infer -1 from 0 elements
("cannot reshape tensor of 0 elements into shape [0, -1]"). That failed
unit_test_tp_4gpu's pretraining (kuairand_1k_ranking_tp2.gin) at its first
eval, on rank 3. u.flatten(1) gives [0, H*D]. pytorch_norm_mul_dropout, the
unfused path, had the same reshape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>

* [FIX] KVCache: FlexKV starts no MPS daemon unless asked

FlexKVStorage takes enable_mps=False, and every caller passes 0, but FlexKV
reads FLEXKV_ENABLE_MPS (default 1) into GLOBAL_CONFIG_FROM_ENV when
flexkv.common.config is first imported, which this module's own imports do:
the variable set in _init_client came too late, and KVManager ran
nvidia-cuda-mps-control -d in every FlexKV run. On the CI's shared DGX A100
hosts that daemon broke CUDA for new processes of other jobs' containers on
the same host ("No CUDA-capable device is detected", "Could not find an
active GPU backend"), seconds after a FlexKV test started it (e.g.
inference_test_nve_2605_1gpu and unit_test_1gpu_a100 on luna-prod-78-80gb
on Nov 13), and once a FlexKV run found another job's daemon ("An instance
of this daemon is already running"). _init_client now sets enable_mps in
GLOBAL_CONFIG_FROM_ENV too, as it does for enable_layerwise_transfer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>

---------

Signed-off-by: aleliu <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
shijieliu added a commit to shijieliu/recsys-examples that referenced this pull request Nov 16, 2026
Brings in main 4466f9d: NVIDIA#528 (hierarchical dist), NVIDIA#550, NVIDIA#553, NVIDIA#555, NVIDIA#478
(exportable embedding collections with NVE layers), NVIDIA#554 and NVIDIA#556.

Conflicts:
- corelib/dynamicemb/CMakeLists.txt: main (NVIDIA#478) adds the RPATH, NVE_ROOT
  and DYNAMICEMB_PYTHON_MODULE_DIR lines above the C++ standard; kept them,
  with this branch's C++20 (PyTorch 2.14's headers need it).
- corelib/dynamicemb/setup.py: main's file. It already has this branch's
  CUDA_HOME import and sm_103-aware default archs (from NVIDIA#528); the conflict
  was only main's new `import torch` and `Extension` imports.
- corelib/dynamicemb/README.md: main's new inference build section, after
  this branch's FBGEMM 1.9.0 / TorchRec 1.9.2 lines.

docker/Dockerfile merged cleanly: NVIDIA#478's build stage rebuilds the default
NVE from the submodule with the same pip command and settings as the devel
stage, and builds torch_binding_build through the CMakeLists above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>
shijieliu added a commit to shijieliu/recsys-examples that referenced this pull request Nov 16, 2026
example/exportable_embedding/cpp, which the image's build stage compiles
against PyTorch, and example/host_embedding asked for C++17 and CUDA 17.
PyTorch 2.14's headers need C++20, as for the other targets this branch
moved (cpp_inference, nve_init_hook, recsys_kvcache_manager). host_embedding
is not built in the image, but builds against the same PyTorch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aleliu <[email protected]>
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]>
z52527 added a commit to z52527/recsys-examples that referenced this pull request Nov 16, 2026
…xport

NVIDIA#478 renamed get_exportable_model_for_inference's dynamic_table_configs (a
table name to is-dynamic dict) to embedding_collection_configs (one
InferenceEmbeddingCollectionConfig per collection) and changed
apply_inference_embedding_collection the same way. After the merge of main,
the Transformer branch still passed the removed name, so a no-cache export
with backbone="transformer" raised NameError before building the model.

Pass the configs by keyword, as main's apply_inference does; NVIDIA#478 added no
other step there. No test builds this exporter's model, so the test suite
does not cover the branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Runchu Zhao <[email protected]>
shijieliu pushed a commit that referenced this pull request Nov 16, 2026
…531)

* Add reference Transformer backbone to HSTU inference

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]>

* Document Transformer interfaces and mark internal state private

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]>

* Fix Transformer graph metadata refresh and dynamic export

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]>

* fix(hstu): wait for layerwise KV onload in the Transformer layer

Layerwise KV onload (#498) made the per-layer wait of PagedHSTUInferLayer a
per-backend choice: a FlexKV transfer is waited for with wait_layer when it is
layerwise, other backends with stream_wait_layer. The Transformer layer still
called stream_wait_layer for every backend, which returns at once for FlexKV,
so with layerwise FlexKV onload it read its KV pages before they arrived. Use
the same choice as the HSTU layer.

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

* feat(docker): build DeepGEMM from a third_party submodule

The FP8 projections of the Transformer inference backbone multiply with
DeepGEMM's fp8_gemm_nt. Pin deepseek-ai/DeepGEMM at b64107f on its nv_dev
branch: main has no SM120 kernels, nv_dev has them. The host extension is
ABI-bound to the torch it is built against, so the image builds it against
its own torch, with --no-deps so pip cannot replace that torch; the GEMM
kernels are JIT compiled at first use. nv_dev's deep_jit includes elfutils
headers, hence libdw-dev.

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

* feat(hstu): FP8 DeepGEMM projections for the Transformer inference backbone

NetworkArgs.transformer_fp8_linear (transformer_fp8_linear in
get_inference_hstu_config) runs the qkv, proj, ffn.0 and ffn.2 projections
of the Transformer inference layer as DeepGEMM FP8 GEMMs with 1x128 activation
and 128x128 weight scales.

- Selected when HSTUBlockInference is built: the Triton model captures its
  per-layer CUDA graphs in the constructor, before the checkpoint is loaded,
  so a layer converted afterwards would keep replaying bf16 kernels.
- The checkpoint stays bf16. The dense checkpoint loader requantizes the FP8
  weights in place, next to the HSTU cached-weight refresh, so graphs captured
  before loading read the loaded weights. The requantization runs in inference
  mode because the graph warmup creates the FP8 tensors as inference tensors.
- Quantization is fused into the neighbouring kernels: the two LayerNorms and
  the bias + GELU write FP8 from Triton kernels; only the attention output is
  quantized by a standalone kernel.
- Projections whose widths are not multiples of 128 stay bf16 with a warning.
  FP8 needs bf16 and an SM90+ GPU and cannot be exported; the exporters reject
  it instead of silently exporting bf16. DeepGEMM is imported only when FP8 is
  requested.

Tests compare against the bf16 layer, including the paged KV cache, CUDA graph
replay of new requests and a checkpoint loaded after graph capture. Helpers
shared with other Transformer layer tests move to transformer_test_utils.py.

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

* feat(hstu): FA4 attention for the Transformer inference backbone

The reference attention pads every user to the longest one and builds a dense
mask for SDPA, so time and memory grow with users x max_seq_len^2: on SM120,
32 users x 100 tokens take 11.9 ms and 1.3 GiB, one user x 3200 tokens 0.7 ms.
NetworkArgs.transformer_attention = "fa4" replaces it with one FlashAttention 4
varlen kernel over the packed tokens.

- Mask: FA4's causal mask, aligned to the end of each user's keys, plus a
  score_mod that hides the other candidates from a candidate; it reads each
  user's candidate count from an aux tensor. A mask_mod would turn off FA4's
  causal block skipping.
- Paged KV cache: the history is gathered from the pages into packed K/V,
  followed by this call's candidates, because candidates are never cached and
  FA4 cannot read pages on SM120.
- Selected when HSTUBlockInference is built, alone or with the FP8
  projections, and captured by the per-layer CUDA graphs. Not exportable.
- FA4 4.0.0b17's varlen scheduler runs spare CTAs for the batch index past the
  last user; they read cu_seqlens[batch + 1] and, through the score_mod,
  candidates[batch], one element out of bounds. Garbage there gave such a CTA
  a length: illegal addresses, and rows of neighbouring tensors overwritten.
  The offsets and candidate counts are passed as views with a repeated last
  element behind them, which makes that CTA empty; compute-sanitizer memcheck
  reports no errors on the eager, CUDA graph and cache paths.
- The image installs fa4-v4.0.0.beta17 into the base image's flash_attn
  package: it is the newest release accepting the base image's CUTLASS DSL
  4.5, and gets the SM120 fix of beta21 (no TMA store of O in the SM80-derived
  kernel) applied in the Dockerfile.

Tests check FA4 against the padded SDPA attention and, independently, read the
kept (query, key) pairs back from FA4 with zero queries and one-hot values and
compare with a step-by-step fp32 attention, with and without a cache.

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

* feat(hstu): benchmark the Transformer inference variants

transformer_e2e_benchmark.py times the bf16 Transformer with its reference
attention against FP8 projections, FA4 attention and both, for
HSTUBlockInference.predict and InferenceDenseModule.forward, with eager layers
and with the per-layer CUDA graphs, using the timing loop of
paged_hstu_with_kvcache_benchmark.py. It also reports the cosine similarity of
the logits against bf16. transformer_fp8_layer_benchmark.py is a diagnostic of
the part of a layer outside attention, which FP8 changes.

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

* fix(hstu): check the sequence lengths before the FA4 attention

The reference attention asserts on the device that each user's sequence
fits max_seq_len and that its candidate and cached counts are valid. The
FA4 attention bounds the kernel and the packed K/V by max_seq_len without
these checks: with a cached sequence longer than max_seq_len, the packed
K/V holds users * max_seq_len rows while the key offsets reach past them.

Move the checks into TransformerInferLayer._checked_lengths and run them
in both attentions, with the reference's messages. The FA4 test replaces
the device asserts with host checks, since a failed device assert ends
the CUDA context of the later tests; the reference's two cache checks,
untested so far, are tested on the CPU.

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

* feat(docker): install FA4 4.0.0b21 from its PyPI wheel

The image cloned fa4-v4.0.0.beta17 and patched one line of its forward
kernel: no TMA store of O on SM120, whose SM80-derived kernel otherwise
fails to compile, varlen and fixed-length. 4.0.0b21 is the first release
with that fix, so install its wheel instead: one pip line, no clone, no
patch. The wheel holds only flash_attn/cute, next to the base image's
FlashAttention 2. It asks for CUTLASS DSL 4.6 and quack 0.5.3; --no-deps
keeps the image's 4.5.2 and 0.4.1, with which all FA4 tests pass on SM120.

4.0.0b21 still runs spare varlen CTAs that read one element past
cu_seqlens (compute-sanitizer without the end sentinels), so the
sentinels stay.

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

* fix(hstu): skip the FP8 quantization and FA4 tests on older GPUs

On an A100 the quantization kernel tests failed instead of skipping:
Triton's float8e4nv, which the kernels write, needs SM89 or newer, and
the file only checked for a GPU. FA4 has the same kind of limit: it
rejects a score_mod on SM8x, so the FA4 attention needs SM90 or newer
and its tests would fail there too. Skip each file below the
architecture it needs, as the FP8 layer tests already do below SM90,
and state the FA4 requirement next to the FP8 one in transformer.md.

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

* fix(hstu): document that the FA4 attention needs finite padding

On an H100 the FA4 padding test failed: its NaN rows past the last user
turned every output NaN. FA4's SM90 kernel loads whole K/V tiles past a
user's end and weighs those rows by zero, and 0 * NaN is NaN; the SM120
kernel zero-fills them. The padding of a CUDA graph bucket is finite in
practice, since the dense module's static input buffer starts random
and then only holds finite activations, so state that the padding must
be finite instead of zeroing V before every FA4 call, which costs 1-3%
of the dense forward on an H100. The test fills the padding with large
random rows: any weight on them would show in the output.

compute-sanitizer finds no spare-CTA reads on SM90; the end sentinels
stay for SM120.

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

* fix(hstu): count the users of an exported Transformer request

The no-cache exporter rebuilds the HSTUBatch with the example request's
batch_size, which the exported program keeps as a constant while it
declares batches of 1 to 8 users. The Transformer layer sliced the
offsets and candidate counts with that constant. Exported from a 2-user
example, a 5-user request gave users 2-4 wrong logits (users 0-1
matched), and a 1-user request indexed past its offsets (device-side
assert).

In export mode, take the user count from the request's candidate
counts, as _sequence_bounds already does. Outside export mode the given
batch_size stays, which the CUDA graph buffers, padded past the request,
need. Programs exported from a 2-user example now match eager inference
for 1, 2, 5 and 8 users.

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

* fix(hstu): run a cached module's forward without the cache eagerly

forward_nokvcache replayed the module's CUDA graphs whenever it had
them. A module built with a KV cache captures graphs that append to the
cache and attend over it through static metadata, which a forward
without the cache leaves at the last cached request's values: the
request's K/V went into other pages and attention read a stale
history. With the Transformer backbone the replay trips its length
check (negative cached prefix length, a device-side assert). main's
flexkv benchmark already times forward_nokvcache on such a module, and
forward() of a non-exportable module now routes there too, where it
used to fail on a tuple unpack.

Replay the graphs only when they were captured without a cache, and
otherwise pass use_cudagraph=False, since predict replays them by
default. The flexkv benchmark's no-cache timing now runs eagerly.

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

* test(hstu): run the block forward for the HSTU backbone too

test_hstu_process_inference ran HSTUBlockInference.forward, and the
dense module on top of it, only for the Transformer backbone. With the
HSTU backbone that forward now runs the layers through predict; main's
per-layer layer(jd) could not run there, since PagedHSTUInferLayer has
no forward ("missing the required forward function"). Check both
backbones. The checkpoint round trip stays Transformer-only: HSTU
checkpoints use the training layout.

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

* refactor(hstu): share the Transformer layer's qkv projection and bounds

Fp8FusedTransformerInferLayer copied TransformerInferLayer.forward_input
to swap in its fused LayerNorm, quantization and FP8 qkv projection,
and the offsets and candidates of a request were sliced in three places
across the two files, so a fix to the parent (like the export-mode user
count) had to be repeated in the copy. The parent now computes the
projection in a _mixed_qkv hook, which project_qkv and forward_input
call and the fused layer overrides, and the request's user count,
offsets and candidates in _request_bounds, which _compute and
forward_input share. test_quantization_kernels_per_layer still counts
the fused kernels of one forward.

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

* fix(hstu): check the dtype of FP8 and FA4 in the inference config

transformer_fp8_linear needs bf16 and FA4 attention bf16 or fp16, but
the config accepted any dtype: FP8 failed when its layers were built,
and FA4 only at its first call ("inputs must be float16 or bfloat16"),
which in the Triton model is the CUDA graph warmup. InferenceHSTUConfig
now rejects both combinations when it is built.

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

* test(hstu): keep the Transformer test helpers out of the test modules

transformer_test_utils imported jagged and manager_metadata from
test_transformer_inference and relied on that import to put corelib on
sys.path, while test_transformer_inference imported the dense-module
helpers back inside two tests to avoid the import cycle. The FP8 and FA4
tests also took corelib's copy_kvcache_metadata through that test module.

Move offsets, make_metadata, jagged and manager_metadata into the helper
module, import them and the dense-module helpers at the top of the CPU
test module, and import copy_kvcache_metadata from corelib. Comments
that pointed at "the PR's" helpers now name them.

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

* refactor(hstu): requantize FP8 weights from a load_state_dict post-hook

The dense checkpoint loader looked up refresh_fp8_weights on every
Transformer layer with getattr, and Fp8Linear separately rebuilt its FP8
weight in forward when the bf16 weight's private _version changed. A
replayed CUDA graph runs no Python, so only the loader's call reached
graphs captured before a load: loading through any other path, such as
nn.Module.load_state_dict, left the graphs on the old FP8 weights.

Fp8Linear now registers a load_state_dict post-hook, which PyTorch also
runs when a parent module is loaded, so every load requantizes in place.
The loader no longer knows about FP8, the version tracking is gone, and
forward only builds the FP8 weight when it is missing or on another
device. The graph test now also loads through nn.Module.load_state_dict;
with the hook disabled that case fails.

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

* docs(hstu): bring the Transformer docs in line with FP8, FA4 and GPU runs

transformer.md still described the reference backend alone: GPU graph
replay "remain pending", the backend "was locally tested on CPU", cached
weight refresh "only for HSTU checkpoints" although FP8 layers
requantize on load, and cache onload synchronization owned by the
orchestration although each layer now waits for its layerwise onload.
The validation command listed none of the FP8, FA4 or Triton tests.

Rewrite the validation and limitations section: the full test command,
the GPUs and container the tests pass on, a table of what each variant
runs on and whether it exports, and the memory cost that FA4 keeps on
the paged path. get_inference_hstu_config now documents the arguments
this PR adds.

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

* fix(hstu): reject FP8 and FA4 in an export config when it is built

InferenceHSTUConfig documents that FP8 projections and FA4 attention
cannot be exported, and it rejects their dtype limits when it is built,
but an export config with either option only failed later, in the layer
constructor. The exporters forward both gin options, so a gin file that
enables one of them now fails at the config with the reason. The layer
constructors keep their own checks for layers built directly.

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

* refactor(hstu): unpack FA4's output, cite the FP8 amax floor, rename a dim set

flash_attn_varlen_func in the pinned FA4 4.0.0b21 always returns
(out, lse), so unpack it instead of accepting either a tuple or a
tensor. The 1e-4 amax floor of the Triton quantizers is the one
DeepGEMM's own casts use; say so. The FP8 benchmark's "pr" dimension set
named a pull request, so call it "small", next to "large".

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

* refactor(hstu): load dense checkpoints in InferenceDenseModule again

The reference backbone moved InferenceDenseModule.load_state_dict into a
free function in modules/inference_checkpoint.py. The function read the
module's private _backbone, _use_exportable and _hstu_block, so that CPU
tests could load into fake modules that mimic those attributes. The
configs package also started to import its task schemas lazily (a PEP
562 __getattr__ that writes globals()), so that the CPU config test runs
without the training embedding stack.

Move the loading back into InferenceDenseModule.load_state_dict, where
main has it, with the backbone switch. Against main, the method now only
adds the switch, no_grad around the copies, a RuntimeError instead of
asserts, and the returned result. The fake-module tests become GPU checks
on real dense modules of both backbones in test_hstu_block_inference:
each module loads another module's checkpoint (HSTU's in the training
layout, plus a sparse table to skip) and must then match its output. The
HSTU transposed weight copies are checked directly, because the forward
only reads them for large requests. Without their refresh the HSTU case
fails.

configs/__init__.py is main's again, and the config test skips without
the training stack. The comment on the backbone field now describes it.

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

* fix(hstu): pass the embedding collection configs in the Transformer export

#478 renamed get_exportable_model_for_inference's dynamic_table_configs (a
table name to is-dynamic dict) to embedding_collection_configs (one
InferenceEmbeddingCollectionConfig per collection) and changed
apply_inference_embedding_collection the same way. After the merge of main,
the Transformer branch still passed the removed name, so a no-cache export
with backbone="transformer" raised NameError before building the model.

Pass the configs by keyword, as main's apply_inference does; #478 added no
other step there. No test builds this exporter's model, so the test suite
does not cover the branch.

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

---------

Signed-off-by: Junyi Zheng <[email protected]>
Signed-off-by: Runchu Zhao <[email protected]>
Co-authored-by: Junyi Zheng <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
shijieliu added a commit that referenced this pull request Nov 17, 2026
shijieliu added a commit that referenced this pull request Nov 17, 2026
* release v26.10

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* bump dynamicemb version to 0.2.0

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* README: give the exportable embedding collections of #478 their own v26.10 entry

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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