flashinfer.fused_moe.split_fp4_moe_weights_by_locality_domain

flashinfer.fused_moe.split_fp4_moe_weights_by_locality_domain(gemm1_weights: Tensor, gemm1_weights_scale: Tensor, gemm2_weights: Tensor, gemm2_weights_scale: Tensor, num_domains: int = 2) → List[Dict[str, Tensor]]

Cut NVFP4 MoE weights into per-locality-domain shards for uGPU localization.

Takes the full weights before the trtllm-gen shuffle, in the layout trtllm_fp4_block_scale_moe() documents with linear (unswizzled) block scales, and returns one dictionary per domain for its localized_weights argument. Domain d gets rows [d * I/n, (d + 1) * I/n) of each of the two FC1 halves (so every gate row stays with its up row) and rows [d * H/n, (d + 1) * H/n) of FC2, which keeps the full reduction dimension. Shuffle each returned shard exactly like the full weights, and copy it into its domain’s memory, before passing it to the MoE call.

Parameters:
  • gemm1_weights (torch.Tensor) – [E, 2 * I, H // 2] packed FP4 FC1 weights (uint8), two halves of I rows each.

  • gemm1_weights_scale (torch.Tensor) – [E, 2 * I, H // 16] linear FC1 block scales.

  • gemm2_weights (torch.Tensor) – [E, H, I // 2] packed FP4 FC2 weights (uint8).

  • gemm2_weights_scale (torch.Tensor) – [E, H, I // 16] linear FC2 block scales.

  • num_domains (int) – Number of locality domains (default 2, the only count the MoE call supports).

Returns:

Contiguous, unshuffled shards with the keys gemm1_weights, gemm1_weights_scale, gemm2_weights and gemm2_weights_scale.

Return type:

List[Dict[str, torch.Tensor]]