Skip to content

vllm.model_executor.layers.quantization.utils.marlin_utils_fp8

Functions:

_moe_pad_last(x, n, padded_n)

Zero-pad the last dim of a (E, ..., n) tensor to padded_n.

_moe_pad_shard_rows(x, n, padded_n)

Zero-pad each gate/up shard of a (E, 2 * n, ...) tensor to padded_n rows. FP8 zero decodes to 0.0, so the padded rows contribute nothing.

mxfp8_marlin_process_scales(marlin_scales)

Reorder scales for e8m0 kernel layout and convert to float8_e8m0fnu.

pack_fp8_to_int32(fp8_tensor, size_k_first=True)

Repack FP8 weights to gptq format (packed int32 elements).

prepare_fp8_moe_layer_for_marlin(layer, w13_weight, w2_weight, w13_weight_scale, w2_weight_scale)

Shuffle weights and scales into marlin format.

prepare_mxfp8_layer_for_marlin(layer)

Repack MXFP8 weights and scales into Marlin kernel format.

Expects the layer to have
  • weight: [N, K] float8_e4m3fn
  • weight_scale: [N, K//32] uint8 (e8m0 encoded)
  • input_size_per_partition / output_size_per_partition

prepare_mxfp8_moe_layer_for_marlin(layer, w13, w2, w13_scale, w2_scale)

Repack MXFP8 MoE weights and scales into Marlin kernel format.

Parameters:

  • layer

    (Module) –

    MoE layer.

  • w13

    (Tensor) –

    [E, 2*N, K] float8_e4m3fn weights.

  • w2

    (Tensor) –

    [E, K, N] float8_e4m3fn weights.

  • w13_scale

    (Tensor) –

    [E, 2*N, K//32] uint8 e8m0 scales.

  • w2_scale

    (Tensor) –

    [E, K, N//32] uint8 e8m0 scales.

Returns: