vllm.models.muse_spark.nvidia.specialized_decode.runtime.expert_tp
¶
Expert tensor parallelism for the routed NVFP4 experts, built from the stock expert-parallel weights (pure torch and torch.distributed).
The stock layer under TP x EP with EP equal to TP holds E / tp whole experts
per rank, placed linearly (rank r owns experts [r Er, (r + 1) Er)), in
the trtllm-gen layout the stock conversion leaves. Expert tensor parallelism
gives every rank all E experts at 1 / tp of the intermediate width
I: rank r holds intermediate slice [r I', (r + 1) I'), I' = I /
tp, as the stock TP loader would cut it before that conversion.
The cut is free. A TP slice of the converted layout is, byte for byte, the converted layout of the TP slice:
- w13 weight and w13 block scales ([E, 2I, H/2] and [E, 2I, H/16]): the gated
interleave puts slice
r's2 I'rows on the contiguous rows[2 r I', 2 (r + 1) I')and the 32-row shuffle stays inside them; the scales' 128x4 interleave keeps whole 128-row tiles contiguous. - w2 weight ([E, H, I/2]): columns
[r I'/2, (r + 1) I'/2)of every row. - w2 block scales ([E, H, I/16], interleaved as [H/128, I/64, 512] bytes per
expert): the k-tiles
[r I'/64, (r + 1) I'/64)of every 128-row m-tile, which is already the slice's own interleave.
This needs I' % 64 == 0 and H % 128 == 0. The per-expert scalars
(g1_alphas, g1_scale_c, g2_alphas) do not depend on the slice: their global
input scales are one value for all experts, the same on every rank.
reshard_nvfp4 builds a rank's TP experts with one NCCL all-to-all per
tensor kind over the TP group (source s sends slice d of its experts to
rank d; the receive buffer is the final tensor, experts in global order) and
three all-gathers of the scalars. It runs once per layer at build, before
capture, and keeps the stock tensors: the stock layer still serves every step
the executor does not take. probe_rel_l2 compares one layer's TP route rows,
summed across ranks, with its EP rows.
Every check runs on every rank and is agreed across the group before any rank raises, so a refusal never leaves the other ranks waiting in a collective.
Classes:
-
StockNvfp4–One rank's stock NVFP4 experts of one layer in the converted layout,
-
TpExperts–One rank's TP experts of one layer: all
num_expertsexperts at
Functions:
-
agree–None when no rank of
grouphas a reason; else this rank's reason, or -
check_global_scales–None when the experts' input and intermediate global scales are the same
-
final_shapes–The TP tensors' shapes: (w13, w13_sf, w2, w2_sf).
-
probe_rel_l2–Rel L2 over all routes of one layer's EP route rows against its TP route
-
reshard_nvfp4–This rank's TP experts of one layer, from every rank's
stock(EP over -
route_rows–The GEMM2 row of every route (t, k), in route order (rows of routes not
-
shape_of–The shape the stock w13 implies (checked by
unsupported). -
slice_views–(w13, w13_sf, w2, w2_sf) as byte views
[tp, Er, ...]: entryd -
unsupported–Why
stockcannot be cuttpways, or None.
StockNvfp4
¶
Bases: NamedTuple
One rank's stock NVFP4 experts of one layer in the converted layout,
as the stock layer holds them (first_expert = its linear placement).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
TpExperts
¶
Bases: NamedTuple
One rank's TP experts of one layer: all num_experts experts at
intermediate slice rank of tp, in the converted layout (the block
scales as bytes; view them as e4m3 for the op).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
agree(group, reason, device)
¶
None when no rank of group has a reason; else this rank's reason, or
that another rank refused. Collective.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
check_global_scales(stock, group)
¶
None when the experts' input and intermediate global scales are the same value, bit for bit, on every rank (the TP scalars need it); collective.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
final_shapes(shape, num_experts)
¶
The TP tensors' shapes: (w13, w13_sf, w2, w2_sf).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
probe_rel_l2(ep, tp, group)
¶
Rel L2 over all routes of one layer's EP route rows against its TP route
rows summed across ranks (FP32 sum, one BF16 rounding, as the TP finalize
sums them). ep and tp are (gemm2 rows, permute map) of the two ops
on the same input and routing; the TP map must cover every route (else
every rank raises). Collective; every rank returns the same value.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
reshard_nvfp4(stock, group, num_experts)
¶
This rank's TP experts of one layer, from every rank's stock (EP over
group with linear placement). Collective over group (NCCL); run it
on every rank, before capture, outside any stream other than the current.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
route_rows(rows, permuted_idx)
¶
The GEMM2 row of every route (t, k), in route order (rows of routes not on this rank read as zero), and which routes are on this rank.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
shape_of(stock, tp)
¶
The shape the stock w13 implies (checked by unsupported).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
slice_views(stock, shape)
¶
(w13, w13_sf, w2, w2_sf) as byte views [tp, Er, ...]: entry d
is intermediate slice d of this rank's experts, in the slice's own
converted layout (no copy; not contiguous). shape is
shape_of(stock, tp) for a tp that unsupported accepts.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/expert_tp.py
unsupported(stock, tp)
¶
Why stock cannot be cut tp ways, or None.