Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e604e13
[TRTLLM-17824][fix] Decline EPLB in modeling_v2 targets that do not i…
ruocheng-nv Nov 14, 2026
7386ca9
[TRTLLM-17824][feat] Static EPLB for the DeepSeek-R1 modeling_v2 target
ruocheng-nv Nov 14, 2026
47865ab
[TRTLLM-17824][feat] Online EPLB for the DeepSeek-R1 modeling_v2 target
ruocheng-nv Nov 14, 2026
283c131
[TRTLLM-17824][fix] Keep counted EPLB ids alive until close; skip onl…
ruocheng-nv Nov 14, 2026
7bdeb64
[TRTLLM-17824][test] Run online EPLB GSM8K at dep4 only on GB300
ruocheng-nv Nov 15, 2026
80111be
[TRTLLM-17824][fix] Release checkpoint keys as the DeepSeek-R1 target…
ruocheng-nv Nov 15, 2026
e7d811d
Merge remote-tracking branch 'upstream/main' into fix/mv2-eplb-guard
ruocheng-nv Nov 15, 2026
80dc800
Merge branch 'fix/mv2-eplb-guard' into feat/mv2-ds-r1-static-eplb
ruocheng-nv Nov 15, 2026
762eb29
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 15, 2026
98ee560
[TRTLLM-17824][fix] Sort the routing test's imports after the merge w…
ruocheng-nv Nov 15, 2026
a4a014f
Merge branch 'fix/mv2-eplb-guard' into feat/mv2-ds-r1-static-eplb
ruocheng-nv Nov 15, 2026
a723860
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 15, 2026
21ffddb
Merge remote-tracking branch 'upstream/main' into feat/mv2-ds-r1-stat…
ruocheng-nv Nov 17, 2026
10f2828
[TRTLLM-17824][feat] Use the tensorrt_llm._torch.modeling_v2 path for…
ruocheng-nv Nov 17, 2026
80d3d95
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 17, 2026
4bc1efb
[TRTLLM-17824][feat] Use the tensorrt_llm._torch.modeling_v2 path for…
ruocheng-nv Nov 17, 2026
9c31e42
[TRTLLM-17824][feat] Use the tensorrt_llm._torch.modeling_v2 path for…
ruocheng-nv Nov 17, 2026
5186ddb
[TRTLLM-17824][test] Move the static EPLB shard tests to their own file
ruocheng-nv Nov 17, 2026
ffb7c78
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 17, 2026
1bf6bcf
[TRTLLM-17824][doc] Show how to run EPLB on the DeepSeek-R1 modeling_…
ruocheng-nv Nov 17, 2026
e3ccbfb
[TRTLLM-17824][test] Check MTP acceptance under static EPLB, and gate…
ruocheng-nv Nov 18, 2026
856ee04
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 18, 2026
80be067
Merge remote-tracking branch 'upstream/main' into feat/mv2-ds-r1-stat…
ruocheng-nv Nov 18, 2026
8144f2f
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 18, 2026
328be78
[TRTLLM-17824][feat] Route each expert call through an EPLB context
ruocheng-nv Nov 23, 2026
0e2e652
Merge remote-tracking branch 'upstream/main' into feat/mv2-ds-r1-stat…
ruocheng-nv Nov 23, 2026
933def1
Merge branch 'feat/mv2-ds-r1-static-eplb' into feat/mv2-ds-r1-online-…
ruocheng-nv Nov 23, 2026
3c99f6b
[TRTLLM-17824][fix] Decline warmup placement in the R1 target; keep t…
ruocheng-nv Nov 24, 2026
5697b65
Merge remote-tracking branch 'origin/feat/mv2-ds-r1-static-eplb' into…
ruocheng-nv Nov 24, 2026
b169c92
Merge remote-tracking branch 'upstream/main' into feat/mv2-ds-r1-onli…
ruocheng-nv Nov 25, 2026
f80d9ce
[TRTLLM-17824][fix] Classify every nonzero update count as online EPL…
ruocheng-nv Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Climb only as far as the claim needs. Each rung says what it cannot see.
| disaggregation | feature `disagg` + `accuracy.disagg` (`config`/`context`/`generation`, or `test`) | a benchmark scored through `trtllm-serve disaggregated` | the flow's own serving of the stated deployment, or the tree's disaggregated-serving test |
| multimodal | feature `multimodal` | an image prompt answered | boot image, image benchmark |
| speculative | features `mtp`, `eagle3`, `dflash`, `dspark` | accepted tokens per iteration | acceptance gate |
| EPLB | a variant setting `llm_api_options.moe_config.load_balancer` at a `dep` member, `modeling_v2: require` | the engine builds the target (a mode missing from its `EPLB_MODES` refuses it) | variant accuracy |
| EPLB | a variant setting `llm_api_options.moe_config.load_balancer` at a `dep` member (`layer_updates_per_iter` > 0 for online), `modeling_v2: require` | the engine builds the target (a mode missing from its `EPLB_MODES` refuses it) | variant accuracy |

## Rules that save hours

Expand Down

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.

[Nice to have] (R6: Required documentation) agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/skills/trtllm-modeling-v2-features/references/features.md:609: - agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/skills/trtllm-modeling-v2-features/references/features.md:609 says "only the padding rows a target names with eplb_call(..., rows=...) are left out". But rows names the token rows (tensorrt_llm/_torch/modeling_v2/catalog/moe/eplb.py:362-367), so an agent following this would pass the padding ranges, and the statistic would count only padding. Padding rows are also still routed and computed; only the statistic leaves them out.

  • examples/wide_ep/ep_load_balancer/README.md:468 says "Per-layer dynamic EPLB runs the built-in model." The section's configs set modeling_v2: require, where the resolver raises instead (tests/unittest/_torch/modeling_v2/test_modeling_v2_routing.py:1732-1736). Say "auto runs the built-in model and require fails", as the bullet above does.
  • examples/wide_ep/ep_load_balancer/README.md:376: "(36 slots a rank, 32 of them replicas)" reads as 32 replicas per rank. Each rank holds 32 experts and 4 replicas.
  • agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/skills/trtllm-modeling-v2-features/references/features.md:547: the plan is None for online EPLB too, not only for static.

Original file line number Diff line number Diff line change
Expand Up @@ -552,25 +552,43 @@ an EPLB deployment only if its class lists the mode in `EPLB_MODES`.
- A target that gathers tokens before routing routes on every rank and must
get the same slots on every rank: `eplb_call` does
(`offset_by_ep_rank=False`).
- Online EPLB adds three duties, all through `EplbLayer`:
- While loading, `share_experts` hands the balancer host copies of this
rank's share of every routed layer's experts (`host_experts`), each slot
weight in the slot layout.
- After loading, `bind_slots` moves the slot weights to memory the balancer
writes, before any view of them is taken. Every per-slot scalar the
expert kernel reads is a bound slot weight, not a value recomputed in the
forward.
- Per forward, `eplb_call(eplb, ids, rows=..., last=...)` records the router's
expert ids without the padding rows, and `close()` hands each layer back
once, after its last expert kernel and before the next layer routes. A draft
layer is closed after the worker's last draft step, also when the worker
drafts nothing.

**Grep.** `EPLB_MODES`, `moe_eplb_mode`, `eplb_slots`, `EplbLayer`,
`eplb_call`, `eplb_route`, `moe_load_balancer_mode`, `maybe_create_moe_load_balancer`,
`MoeLoadBalancerConfig`, `initial_global_assignments`, `num_slots`.
`eplb_call`, `eplb_route`, `share_experts`, `bind_slots`, `close_draft_eplb`,
`moe_load_balancer_mode`, `maybe_create_moe_load_balancer`,
`MoeLoadBalancerConfig`, `initial_global_assignments`, `num_slots`,
`layer_updates_per_iter`.

**Tests to imitate.**
- `tests/unittest/_torch/modeling_v2/moe/ops/test_modeling_v2_eplb.py`: the slots,
registration and each expert call's routing (`eplb_call`) on the CPU; the
route op's cells, where every EP rank must
route the same ids to the same slots; and a slot-routed layer whose windows
sum to the layer without EPLB.
- `tests/unittest/_torch/modeling_v2/models/deepseek_v3/r1_0528_nvfp4__sm_10x__default/test_modeling_v2_deepseek_default_shards.py`
(`test_eplb_*`): slots and `load` under a placement drawn per layer, with
copies of an expert across ranks and twice on one rank, against the
world-size-1 table without EPLB.
registration and each expert call's routing (`eplb_call`) on the CPU; the online protocol a layer follows with the
balancer, its host copies and its binding, on the CPU; the route op's
cells, where every EP rank must route the same ids to the same slots; a
slot-routed layer whose windows sum to the layer without EPLB; and a real
online balancer moving experts into bound slots.
- `tests/unittest/_torch/modeling_v2/models/deepseek_v3/r1_0528_nvfp4__sm_10x__default/test_modeling_v2_deepseek_eplb_shards.py`
(`test_eplb_*`, `test_online_eplb_*`): slots and `load` under a placement
drawn per layer, with copies of an expert across ranks and twice on one
rank, and the host copies online EPLB hands over, against the world-size-1
table without EPLB.
- `tests/unittest/_torch/modeling_v2/test_modeling_v2_routing.py`
(`test_eplb_*`, `test_r1_*eplb*`): the resolver's decisions per mode and
layout.
- `accuracy/modeling_v2/deepseek_v3/r1_0528_nvfp4__sm_10x__default/test_accuracy.py::TestModelingV2DeepseekR10528Nvfp4Sm10xDefault::test_gsm8k_static_eplb`.
- `accuracy/modeling_v2/deepseek_v3/r1_0528_nvfp4__sm_10x__default/test_accuracy.py::TestModelingV2DeepseekR10528Nvfp4Sm10xDefault::test_gsm8k_static_eplb`
and `::test_gsm8k_online_eplb`.

**Fast check.** quickstart or `trtllm-serve` at a dep layout with
`moe_config.load_balancer` set and `modeling_v2: require`: the engine must
Expand All @@ -587,8 +605,16 @@ not report the registered layers, so the target's own tests carry that.
- A slot loaded with the wrong expert, or an id routed to a slot that holds
another expert, still produces fluent text. Use a placement that differs
from the default in every layer, with an expert held twice on one rank.
- Padding rows and attention-DP dummy requests count in the routing like
real tokens.
- Attention-DP dummy requests count in the statistic like real tokens;
only the padding rows a target names with `eplb_call(..., rows=...)` are left out.
- A layer that is registered but never runs, for example after the loader
builds the model twice, changes nothing under static EPLB. Under online
EPLB the balancer waits for it.
EPLB the balancer waits for it, and so does every later forward: a missed
`close` hangs the engine rather than failing it.
- Under online EPLB, a view of a slot weight taken before `bind_slots`, or a
per-slot scalar recomputed in the forward, reads stale values after the
first move -- the score drops only once the balancer has moved experts, so
the run has to be long enough for that.
- Online EPLB needs host-accessible device memory: Grace's, or GDRCopy on x86
with a library that matches the node's `gdrdrv` driver. Without it the
balancer fails at creation.
147 changes: 145 additions & 2 deletions examples/wide_ep/ep_load_balancer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,149 @@ A [Modeling V2](../../../tensorrt_llm/_torch/modeling_v2/README.md) target runs

| Target | EPLB modes | Layouts |
|---|---|---|
| DeepSeek-R1-0528 NVFP4 (`deepseek_v3/r1_0528_nvfp4__sm_10x__default`, SM100 and SM103) | static | attention DP with pure expert parallelism over 4 or 8 GPUs (dep4, dep8) |
| DeepSeek-R1-0528 NVFP4 (`deepseek_v3/r1_0528_nvfp4__sm_10x__default`, SM100 and SM103) | static, online | attention DP with pure expert parallelism over 4 or 8 GPUs (dep4, dep8) |

Every other target declines EPLB, so those deployments run the built-in model. To collect the expert statistics for `generate_eplb_config.py`, run the statistics pass with `modeling_v2: off`. The built-in model uses the same router, so its statistics describe the same load.
Every other target declines EPLB, so those deployments run the built-in model.

### Run EPLB on the Modeling V2 target

The steps below run the DeepSeek-R1-0528 NVFP4 target with EPLB at dep8: attention DP with 8-way expert parallelism, on two GB200 or GB300 trays. They follow the steps above at the scale the target runs EPLB. `modeling_v2: require` builds the target or fails with the reason it does not fit; with `auto`, a deployment the target does not fit runs the built-in model instead.

Set up the environment:

```bash
export MODEL_NAME=nvidia/DeepSeek-R1-0528-FP4
export MODEL_PATH=<YOUR_MODEL_PATH>
```

Prepare a dataset following the [benchmarking documentation](https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/developer-guide/perf-benchmarking.md#preparing-a-dataset), for example:

```bash
trtllm-bench --model ${MODEL_PATH} prepare-dataset \
--output ./dataset.json \
token-norm-dist \
--num-requests 4096 \
--input-mean 1024 --output-mean 1024 \
--input-stdev 0 --output-stdev 0
```

#### Static EPLB

1. Collect the expert statistics on the built-in model. The Modeling V2 target does not record them, and the built-in model routes with the same router, so its statistics describe the same load. Quote `"off"`: YAML reads a bare `off` as `false`.

```bash
export EXPERT_STATISTIC_PATH=./expert_statistic
export EXPERT_STATISTIC_ITER_RANGE=100-200

cat > ./config_stats.yaml <<EOF
modeling_v2: "off"
enable_attention_dp: true
EOF

trtllm-llmapi-launch \
trtllm-bench --model ${MODEL_NAME} \
--model_path ${MODEL_PATH} \
throughput \
--tp 8 \
--ep 8 \
--config ./config_stats.yaml \
--kv_cache_free_gpu_mem_fraction 0.75 \
--dataset ./dataset.json \
--warmup 0 \
--eos_id -1
```

2. Generate the placement for 8 ranks and 288 slots (36 slots a rank, 32 of them replicas), then stop counting:

```bash
python report_load_statistics.py --expert_statistic_path $EXPERT_STATISTIC_PATH
python generate_eplb_config.py \
--ep_size 8 \
--num_slots 288 \
--expert_statistic_path $EXPERT_STATISTIC_PATH \
--output_path ./moe_load_balancer.yaml
unset EXPERT_STATISTIC_PATH EXPERT_STATISTIC_ITER_RANGE
```

3. Run the Modeling V2 target with the placement. The target runs an FP8 KV cache only.

```bash
cat > ./config_v2_static.yaml <<EOF
modeling_v2: require
enable_attention_dp: true
kv_cache_config:
dtype: fp8
moe_config:
load_balancer: ./moe_load_balancer.yaml
EOF

trtllm-llmapi-launch \
trtllm-bench --model ${MODEL_NAME} \
--model_path ${MODEL_PATH} \
throughput \
--tp 8 \
--ep 8 \
--config ./config_v2_static.yaml \
--kv_cache_free_gpu_mem_fraction 0.75 \
--dataset ./dataset.json \
--warmup 0 \
--eos_id -1
```

The log names the target on every rank: `modeling_v2: building tensorrt_llm._torch.modeling_v2.models.deepseek_v3.r1_0528_nvfp4__sm_10x__default.modeling.ModelingV2DeepseekR10528Nvfp4Sm10xDefault on all 8 rank(s)`.

To serve the same deployment:

```bash
trtllm-llmapi-launch \
trtllm-serve ${MODEL_PATH} \
--tp_size 8 \
--ep_size 8 \
--config ./config_v2_static.yaml \
--host 0.0.0.0 \
--port 8000
```

#### Online EPLB

Online EPLB starts from the default placement and moves experts while serving, two layers an iteration here:

```bash
cat > ./moe_load_balancer_online.yaml <<EOF
num_slots: 288
layer_updates_per_iter: 2
EOF

cat > ./config_v2_online.yaml <<EOF
modeling_v2: require
enable_attention_dp: true
kv_cache_config:
dtype: fp8
moe_config:
load_balancer: ./moe_load_balancer_online.yaml
EOF

trtllm-llmapi-launch \
trtllm-bench --model ${MODEL_NAME} \
--model_path ${MODEL_PATH} \
throughput \
--tp 8 \
--ep 8 \
--config ./config_v2_online.yaml \
--kv_cache_free_gpu_mem_fraction 0.75 \
--dataset ./dataset.json \
--warmup 0 \
--eos_id -1
```

The balancer writes expert weights into GPU memory from the host. Grace systems (GB200, GB300) have that built in; x86 systems need GDRCopy, with a `gdrdrv` kernel module that matches the GDRCopy library.

#### dep4

On one GB200 or GB300 tray, generate the placement with `--ep_size 4` and run with `--tp 4 --ep 4` (`--tp_size 4 --ep_size 4` for `trtllm-serve`). 288 slots give 72 slots a rank.

#### Limits

- The target runs EPLB at dep4 and dep8 only: attention DP with pure expert parallelism over 4 or 8 GPUs. With EPLB at any other layout, including the 32- and 36-way expert parallelism of the steps above, `auto` runs the built-in model and `require` fails, naming the layout.
- Static and online EPLB only. Per-layer dynamic EPLB runs the built-in model.
- The statistics in step 1 come from the built-in model.
58 changes: 53 additions & 5 deletions tensorrt_llm/_torch/modeling_v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ modeling_v2: require
```

To opt out and always use Modeling V1, set `modeling_v2="off"` in the Python
API or `modeling_v2: off` in the configuration file.
API or `modeling_v2: "off"` in the configuration file. Quote it there: YAML
reads a bare `off` as `false`, which the configuration rejects.

Use `require` when you validate or benchmark a target, so the run cannot fall
back to Modeling V1 without you noticing. A target can also read the mode with
Expand Down Expand Up @@ -391,7 +392,7 @@ MoE layers into it:
| Model loader | Creates the balancer around the model when the deployment runs EPLB (`moe_load_balancer_mode`), and registers weight slots and finalizes it after the weights load. |
| Executor | Wraps every forward in a balancer iteration, turns statistics and updates off during warmup, and shuts the balancer down. |
| Resolver | Builds a target for an EPLB deployment only if the target class lists the deployment's mode in `EPLB_MODES` (see [Routing](#routing)). |
| Target | Registers its MoE layers, loads its experts by slot, routes expert ids to slot ids, and declines in `route` the layouts it has not measured EPLB at. |
| Target | Registers its MoE layers, loads its experts by slot, routes expert ids to slot ids, and declines in `route` the layouts it has not measured EPLB at. Under online EPLB it also hands the balancer host copies of its experts, binds its slot weights to it, and hands every layer back once per forward. |

A target reaches the balancer only through
[`catalog/moe/eplb.py`](catalog/moe/eplb.py). The balancer
Expand Down Expand Up @@ -434,19 +435,66 @@ the example.
Then list the mode in the target class, `EPLB_MODES = frozenset({"static"})`,
and gate the layouts in `route` on `moe_eplb_mode(model_config)`.

### Online EPLB in a target

Online EPLB (`layer_updates_per_iter > 0`) moves experts between slots while
the engine serves. Each forward, every routed layer's statistic records which
experts the tokens chose. Between forwards the balancer recomputes the
placement of a few layers, copies the moved experts' weights from host memory
into their new slots and reroutes to them. On top of the four static steps a
target does three more, and lists `"online"` in `EPLB_MODES`:

5. **Host copies.** While loading, call
`EplbLayer.share_experts(slot_weights, expert_weight)` once per routed
layer. `slot_weights` names every per-slot weight -- the operands, their
block scales and any per-slot scalar the expert kernel takes -- and
`expert_weight(name, expert)` reads one expert's weight in the slot layout,
through the same cut and transform as a slot. It is called for the experts
in `EplbLayer.host_experts`, this rank's share of its node, so the node
holds every expert once. Those experts' checkpoint tensors are then read,
which the target's coverage accounting has to expect.
6. **Binding.** After loading, call `EplbLayer.bind_slots(slot_weights)`
before taking any view of those weights. Binding moves them to memory the
balancer can write and registers every slot, and a view taken earlier
keeps reading the old storage. Binding the same weights again does
nothing, as when the model loader runs a post-load hook twice. Every
per-slot value the expert kernel reads has to be a bound slot weight: a
value derived once from the slot's expert, such as an output scale
computed while taking the views, keeps the old expert's value after a
move. The balancer needs host-accessible device memory, which Grace
systems have and x86 systems get from GDRCopy.
7. **The forward.** `eplb_call(eplb, ids, rows=..., last=...)` takes the layer
from the balancer on its first call of a forward and records the router's
expert ids; its plan stays None, since the slots change only between
forwards. `rows` names the rows that are tokens when the rest are padding,
such as the rows an attention-DP gather pads, and `last` marks the last
call of a pass over the layer: the forward's last call of a layer that
runs once. Without `last`, `close` completes the statistic.
`EplbLayer.close()` hands the layer back after its last expert kernel of
the forward. The balancer takes the layers in their registration order
every forward and waits for each to come back, so call `close` once per
forward per layer, before the next layer routes. A layer the forward did
not run is closed as well, such as a draft layer when the worker drafts
nothing. A layer that runs once per draft step is closed after the last
draft step.

### Testing EPLB

A target that implements EPLB adds:

* **CPU:** its slots and weight manifest under a placement unlike the default
one, with copies of an expert on several ranks and twice on one rank, and
its routing decisions for each EPLB mode and layout.
its routing decisions for each EPLB mode and layout. Under online EPLB,
also the host copies its load hands over, against what a slot holding the
same expert loads.
* **GPU:** the cells of the catalog EPLB entry and of its expert kernel at
the shapes and slot windows the target calls them with (`TARGET_CELLS`).
the shapes and slot windows the target calls them with (`TARGET_CELLS`),
and its registrations against a real balancer in each mode it implements.
* **Accuracy:** its benchmark with EPLB at every layout it admits, with
`modeling_v2="require"`. A slot loaded with the wrong expert still produces
fluent text, so use a placement that differs from the default one in every
layer.
layer. Under online EPLB, a run long enough for the balancer to move
experts in every layer, the draft layer included.

## Writing operations

Expand Down
Loading
Loading