Expand description
2026-09-25: Tensor-parallel weight sharding helpers.
Each weight tensor is sliced along one of two axes:
-
Column-parallel (Q/K/V proj, gate_proj, up_proj): weight shape
[out, in]becomes[out / tp, in]. Rankrkeeps rows[r * out / tp, (r + 1) * out / tp), one contiguous slice in row-major layout, so onecopy_d2d. -
Row-parallel (O proj, down_proj): weight
[out, in]becomes[out, in / tp]. Rankrkeeps cols[r * in / tp, (r + 1) * in / tp), one strided copy per row.
1D per-output vectors shard along the output axis of their column-parallel
GEMM (shard_dense_1d_bf16).
The BF16 primitives are here; quant_shard.rs slices weights that are
already NVFP4 or FP8 block-scaled, and gdn.rs the segmented Gated-DeltaNet
projections.
Owner: model-arch (tensor parallelism). Invariants:
- With
tp_size <= 1every shard function returns its source unchanged and allocates nothing.
Structs§
- TpAttention
Dims - 2026-09-25: Pre-TP-shard attention dimensions reconstructed from
config. - TpGdn
Dims - 2026-09-25: Pre-TP-shard GDN (linear-attention / SSM) dimensions
reconstructed from
config. - TpMoe
Dims - 2026-09-25: Pre-TP-shard dimensions for MoE expert projections. Unlike the
head counts,
serve_phases/topology.rsdoes not dividemoe_intermediate_size, sofull_inter == config.moe_intermediate_sizeand the local size is computed here.
Enums§
- TpShard
Kind - 2026-09-25: TP shard kind for a 2D weight
[out_dim, in_dim].
Functions§
- load_
qk_ norms_ tp - 2026-09-25: Q/K-norm 1D shard pair. The closure receives
(name, full_dim)and returns the loader’s sharded norm — typically aDenseWeight.q_normis sharded againstfull_q_n;k_normagainstfull_kv_n. Returns(q_norm, k_norm). - load_
qkvo_ tp - 2026-09-25: Sequence the four Q/K/V/O loads via a loader-supplied closure. The
closure receives
(name, full_out, full_in, kind)and returns the loader’s representation of that projection (BF16 dense, NVFP4 quantized, FP8 block-scaled — varies by format). - shard_
dense_ 1d_ bf16 - 2026-09-25: Shard a 1D BF16 vector
[dim]on dim 0, for per-output vectors of column-parallel GEMMs. Same ownership rule asshard_dense_bf16. - shard_
dense_ bf16 - 2026-09-25: Shard a BF16 dense weight
[out_dim, in_dim]according tokind. - shard_
dense_ weight - 2026-09-25:
shard_dense_bf16on aDenseWeight, with the same ownership rule: a new buffer only when a shard happened, and then the caller frees the source. - shard_
fp8_ block_ scaled - 2026-09-25: Shard an FP8 block-scaled weight.
weightis[N, K]FP8 bytes;row_scaleis[N/block_size, K/block_size]FP32. Both slice on the same axis at block granularity. Same ownership rule asshard_quantized_nvfp4. - shard_
gdn_ ba_ rows - 2026-09-25: Shard the BA gate BF16 weight
[2*full_nv, h]to[2*local_nv, h]. - shard_
gdn_ conv_ rows - 2026-09-25: Shard the depthwise
conv1dBF16 weight[full_conv_dim, d_conv]to[local_conv_dim, d_conv]. Its channels are the QKV channels (one filter per channel), so it uses the same[Q|K|V]segments as the QKV in-projection. - shard_
gdn_ out_ proj_ row_ parallel - 2026-09-25: Shard the
out_projBF16 weight[h, full_value_dim]row-parallel on its input dim (value_dim). Rankrkeeps columns[r*local_value_dim, (r+1)*local_value_dim)of every output row; the layer sums the partial products with an all-reduce after the GEMM. Returns(ptr, h, local_value_dim). - shard_
gdn_ qkv_ rows - 2026-09-25: Shard the
[Q|K|V](in_proj_qkv) BF16 weight[full_conv_dim, h]to the local rank’s[local_conv_dim, h], slicing Q, K and V independently by the local head range. Returns(ptr, local_rows, h). - shard_
gdn_ qkvz_ rows - 2026-09-25: Shard the concatenated
[Q|K|V|Z](in_proj_qkvz) BF16 weight[full_qkvz_out, h]to the local rank’s[local_qkvz_out, h], slicing all four segments independently. Returns(ptr, local_rows, h). - shard_
gdn_ value_ vector - 2026-09-25: Shard a per-value-head 1D vector on the value-head axis:
[full_nv * unit]→[local_nv * unit], whereunitis the number of elements per value head andelem_bytestheir size. The loaders call it fora_log/dt_bias(unit = 1,elem_bytes = 4). Returns(ptr, local_len_elems). - shard_
quantized_ nvfp4 - 2026-09-25: Shard an NVFP4-quantized weight. The packed weight is
[N, K/2]u8; the per-group scale is[N, K/group_size]u8 (FP8);weight_scale_2is a per-tensor f32 (replicated across all ranks).