Skip to content

[None][feat] modeling_v2 qwen4_exp: PLE host table per rank, per server or per node - #22077

Closed
Wanli-Jiang wants to merge 10 commits into
NVIDIA:mainfrom
Wanli-Jiang:user/williamj/q38-ple-host-table
Closed

Wanli-Jiang wants to merge 10 commits into
NVIDIA:mainfrom
Wanli-Jiang:user/williamj/q38-ple-host-table

Conversation

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

Stacked on #21621 (the Qwen3.8-Flash-Next FP8 modeling_v2 target). Until that merges, the diff here also shows its commits; this PR is the last two:

  • [None][chore] modeling_v2 qwen4_exp fp8: drop the shared host PLE table removes the FP8 target's PLE_SHARED_HOST sharing (flock, a JSON descriptor in a shared directory, pidfd_getfd).
  • [None][feat] modeling_v2 qwen4_exp: PLE host table per rank, per server or per node replaces it with one implementation for both Qwen3.8-Flash-Next targets.

The PLE n-gram table is 47.7 GiB of FP8 rows (320,001,536 x 160) and lives in host memory, one private copy per rank. qwen4_exp/ple_host_table.py cuts its rows into 8 fixed chunks (each a multiple of 2 MiB) and stores them as TRTLLM_MODELING_V2_PLE_HOST_TABLE says:

Mode Storage Lookup Copies, ctx tep2 + gen tep2 on one node Extra work per step
rank (default) private, whole table local 4 none
server private, only this rank's chunks (tp 2: 4, tp 4: 2) the gather reads this rank's rows and writes zeros for the others; the target sums over the attention-TP group 1 per server one TP sum of the PLE n-gram rows
node each chunk one CUDA VMM allocation on host NUMA memory, shared by every process of the host local: every rank maps all 8 chunks back to back 1 per node none
  • server is exact: every element has one nonzero term. ple_ngram_embed gains row_window=(lo, hi, base); the default reads the whole table, so rank and other callers are unchanged. It needs attention TP over a size that divides 8; under attention DP it runs as rank and says so in the log. The FP8 target keeps its PLE front on the main stream when the rows are summed.
  • node (qwen4_exp/chunk_broker.py): the first process to bind a chunk's abstract Unix socket creates and fills the chunk's allocation, then passes its POSIX fd with SCM_RIGHTS to the processes that connect. Peers of another uid are refused through SO_PEERCRED. When the owner exits or aborts before publishing, the kernel closes its socket and a waiter takes the chunk over. Nothing is written to the filesystem, and no ptrace permission is needed. Each rank fills the chunks of its own share first, so the ranks of a server load the table in parallel, and servers on one node (disaggregated context and generation) share one copy.
  • The shared table is keyed by the checkpoint directory's safetensors files (names, sizes, modification times) plus the table's shape and dtype; attached chunks are checked against the checkpoint's rows.
  • When a rank cannot take part in node (no VMM host NUMA allocation, no checkpoint identity, no owner within the timeout), every rank of the server agrees and runs server instead, or rank.

Compared with the removed FP8 sharing: no ptrace requirement (it fell back to one copy per rank without it), no lock held across weight loading, no files to own or clean up, an identity that does not rest on sampled rows, both targets instead of FP8 only, and a fallback of one copy per server instead of per rank.

Evidence (GB300, 4 GPUs a node, GSM8K with real acceptance):

Deployment rank server node
FP8 tep4 MTP3, fp8 KV, breakable prefill (three modes on one node) 95.11, AL 3.266 95.91, AL 3.272 95.38, AL 3.270
NVFP4 tep4 MTP3, GSM8K and long context 96.17, AL 3.689 / 4.000 96.17, AL 3.689 / 4.000 96.17, AL 3.689 / 4.000
FP8 disaggregated dep2 + dep2 95.30 runs as rank (attention DP) 95.07
  • Every rank logs how it stores the table. tep4 node: each process created 2 chunks and attached 6. Disaggregated node: the two context ranks created 4 and attached 4, the two generation ranks attached all 8.
  • Host memory, FP8 tep4, one node, after weight load and before KV cache creation: rank about 293 GiB, server 143 GiB, node about 143 GiB (theory: 3 x 47.7 GiB less).
  • KV cache manager v2 sizes its automatic host tier from the host memory available at KV creation, so the freed memory goes there: the largest per-rank host quota is 24.5 GiB with rank and 62.6 / 69.1 GiB with server / node.
  • Load time: FP8 tep4 test 599 s -> 416 / 418 s, NVFP4 tep4 624 s -> 333 / 326 s.
  • Not measured yet: the step-time cost of the server TP sum.

Test Coverage

  • qwen3_8_flash_next_fp8__sm_103__unified/test_weights.py:
    • test_host_table_chunks_cover_the_rows: chunk alignment, coverage, and the shares of every TP size (CPU).
    • test_chunk_broker_hands_over: across processes, a waiter attaches to what the owner publishes and so does a late process, or the waiter binds the socket and creates the chunk itself when the first process exits before publishing; no files are left (CPU).
    • test_host_table_modes[rank|server|node|node-fallback]: mode, window, host residency, and bytes equal to the checkpoint's (GPU; node needs VMM host NUMA).
  • ops/ple/test_modeling_v2_ple_ngram_embed.py::test_row_windows_sum_to_the_whole_table: both gather kernels, 2 and 4 ranks, from a slice and from the whole table; each share equals the reference and the shares sum bitwise to the whole table's output.
  • On GB300 at this head: the FP8 and NVFP4 PLE and weight unit tests plus ops/ple, 205 passed; the accuracy runs in the table above.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

…kpoint's shapes

Family operations of qwen4_exp gain what the Qwen3.8-Flash-Next-FP8 target needs, without
changing what the NVFP4 target launches:

- hc_lowrank_act, renorm_moe_routing_op, fp8_quantize_1x128: certified cells under CUDA-graph
  capture at the FP8 target's decode batches.
- qsa_paged_index_scores: opt-in prefill query-tile path and wide split (prefill_query_tile=,
  wide_split=; both default off, so the NVFP4 target's launches are unchanged), one-row-tile
  variant, no batch specialization of the group kernel, memory-clobbering PDL wait.
- qsa_topk_expand_decode: opt-in ordered wide launch (ordered_wide=, default off).
- ple_gate_conv_inject_norm, qwen4_exp_hc_up_gate_mean, qwen4_exp_hc_inject_norm,
  spec_rollback_commit: new parameters, defaulted to the current behavior.
- jit_variants: warms the Triton variants a family op launches, so no variant compiles in a
  served step.
- fused_sigmoid_mul_inplace, rms_norm_gated_token_major: direct_launch= (default off), the op's own
  launch without the custom-op dispatch, same results.
- The family operations the FP8 target calls as they are (causal_conv1d_update,
  gdn_decode_rows_gated_norm, gdn_prefill_conv_post, bf16_to_fp32) list the FP8 target's shapes in
  their tests.

Signed-off-by: Wanli Jiang <[email protected]>
… TP1/TP2/TEP2/DEP2/TP4/TEP4/DEP4 on GB300

One modeling_v2 target, qwen4_exp/qwen3_8_flash_next_fp8__sm_103__unified, serves
Qwen3.8-Flash-Next-FP8 (routed experts FP8 with 128x128 block scales, bf16 elsewhere) on GB300 at
every single-node layout routing admits for it: tp1, tp2/tp4, tep2/tep4 and dep2/dep4, with CUDA
graphs, the overlap scheduler, one-model MTP-Eagle (1-7 drafts) and IndexShare, KV cache
auto/FP8/NVFP4, a bf16 recurrent-state cache, chunked prefill, block reuse with recurrent-state
snapshots, the breakable prefill CUDA graph under attention TP, disaggregated serving and image and
video input.

routing.py sends a checkpoint the engine resolves as FP8_BLOCK_SCALES to this target at the NVFP4
target's layouts plus tp2 and tep2; the target's check_deployment declines the checkpoints and engine
choices it does not run. Every other checkpoint routes as before.

The target's own CUDA kernels build into the family library (models/qwen4_exp/csrc): the
TP-block decode MoE (8-CTA clusters, one launch per layer for <= 8 rows at tp4/tep4, opt-in through
TRTLLM_MODELING_V2_DECODE_MOE_TPB=rr), the hyper-connection TP sum fused with the injection and
grouped norm (one IPC Lamport launch on the stock all-reduce workspace), and the one-launch decode
routing + 1x128 quantization in front of the trtllm-gen FP8 block-scale MoE runner. The prefill
experts use a target copy of the CuTe blockwise GEMM with a contiguous grouped mode.

The target calls the catalog's cublas_mm, thop_attention and fused_qk_norm_rope and the family's
operations directly, with its shapes as TARGET_CELLS in those operations' tests; its own ops/ holds
only the operations it runs differently.

The TP sum and the attention-DP gather and scatter are the shared catalog/comm entries. Under
attention DP the MoE round trip is the all-gather / reduce-scatter; with
TRTLLM_MODELING_V2_MOE_ALLTOALL=1 it is instead an all-to-all dispatch / combine on the stock
NVLink one-sided MoE all-to-all (ops/comm/moe_a2a__dp_dispatch_combine), a reference of that path.

Unit tests (tests/unittest/_torch/modeling_v2/models/qwen4_exp/<target>/) cover routing, the core
and pool layout per rank, rank-local weight shards, speculative rollback, the in-forward snapshot,
the vision tower against Hugging Face, every target operation's certified cells and the 2- and
4-rank collectives, the all-to-all round trip included. The accuracy class TestModelingV2Qwen38FlashNextFp8Sm103Unified
(tests/integration/defs/accuracy/modeling_v2/qwen4_exp/<target>/test_accuracy.py) runs GSM8K with
three drafts, block reuse and chunked prefill at tep4 (FP8 KV, breakable prefill graph) and at dep4
(also with the all-to-all round trip), and disaggregated dep2, against the FP8_BLOCK_SCALES
references.

Signed-off-by: Wanli Jiang <[email protected]>
…mat to the FP8 target's native code

Signed-off-by: Wanli Jiang <[email protected]>
…vous files without following symlinks

The rendezvous directory (default /dev/shm) is writable by every user of the host. The lock, descriptor and temporary descriptor files are now opened with O_NOFOLLOW, created 0600 (the temporary one with O_EXCL), and read only when the calling uid owns them. Resolves bandit B108 on the default directory.

Signed-off-by: Wanli Jiang <[email protected]>
…eference, check gdn_in_proj_conv's bf16 conv operands

Signed-off-by: Wanli Jiang <[email protected]>
…ize support and precompiles

Signed-off-by: Wanli Jiang <[email protected]>
…ot run, honor PDL and all-reduce settings

Signed-off-by: Wanli Jiang <[email protected]>
TRTLLM_MODELING_V2_PLE_SHARED_HOST mapped one host copy of the PLE n-gram
table per node through a rendezvous in /dev/shm and pidfd_getfd. It needs
ptrace rights over the owner, holds a lock for the whole weight load and
keys the table by sampled rows. Remove it: the FP8 target keeps one
host-resident copy per rank, as the NVFP4 target does. A family-level
replacement that works for both targets follows separately.

Signed-off-by: Wanli Jiang <[email protected]>
…er or per node

The PLE n-gram table (47.7 GiB of FP8 rows on Qwen3.8-Flash-Next) is
host-resident with one copy per rank. qwen4_exp/ple_host_table.py stores
it as TRTLLM_MODELING_V2_PLE_HOST_TABLE says, for both targets:

* rank (default): one private copy per rank, as before.
* server: the rows are cut into 8 fixed chunks; under attention TP each
  rank stores only its chunks (tp 2: 4, tp 4: 2), the n-gram gather
  reads those rows and writes zeros for the others (ple_ngram_embed's
  new row_window), and the target sums the gathered rows over the TP
  group. Every element has one nonzero term, so the sum is exact. One
  copy per server; no inter-process state.
* node: each chunk is one CUDA VMM allocation on host NUMA memory. The
  first process of the host to bind the chunk's abstract Unix socket
  creates and fills it and passes its POSIX fd to the others with
  SCM_RIGHTS (qwen4_exp/chunk_broker.py: peers of another uid are
  refused through SO_PEERCRED, an owner that exits or aborts hands the
  chunk to its waiters, nothing is written to the filesystem). Every
  rank maps all chunks back to back and gathers locally. A rank fills
  the chunks of its share first, so the ranks of a server load the
  table in parallel; servers on one node (disaggregated context and
  generation) share it. The table is keyed by the checkpoint
  directory's safetensors files (names, sizes, modification times), and
  attached chunks are checked against the checkpoint's rows.

server needs attention TP over a size dividing 8, else it runs as rank.
When a rank cannot take part in node (no VMM host NUMA allocation, no
checkpoint identity, no owner within the timeout), every rank of the
server runs server instead, or rank. The FP8 target keeps its PLE front
on the main stream when the rows are summed.

Tests: the chunk layout, the broker across processes (publish, late
attach, owner exit), the four storage outcomes against the checkpoint's
bytes, and row-window shares that sum bitwise to the whole table's
output on both gather kernels.

Signed-off-by: Wanli Jiang <[email protected]>
@hanjingtian

Copy link
Copy Markdown
Collaborator

Could you please rebase this branch onto the latest upstream main to include the CI hang fix in #22101 (6edbe383497a)? The current branch still contains the regression that can cause pipelines to hang for an extended period and worsen CI queueing

@ruocheng-nv

Copy link
Copy Markdown
Collaborator

Hi, heads-up: #22286 has merged, so ModelingV2 now lives at tensorrt_llm/_torch/modeling_v2 (module tensorrt_llm._torch.modeling_v2), and the old _torch/_experimental/modeling_v2 path no longer exists.

Since this PR touches modeling_v2, please rebase it onto the latest main. You can use these migration commands to move any files you added under the old directory and update any remaining references to the old path.

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