Skip to content

vllm.model_executor.layers.quantization.utils.marlin_utils

Functions:

check_moe_marlin_supports_config(config, group_size, allow_tile_padding=False)

Whether the fused MoE Marlin kernel supports config.

With allow_tile_padding=True, a tile-misaligned intermediate size is zero-padded to a valid thread tile at weight prep (see marlin_moe_padded_intermediate), so only a group straddling the padded boundary stays unsupported. hidden_size is the MoE I/O extent and is never padded.

get_marlin_workspace(device)

Get zero-initialized locks for the current stream, ubatch, and lane.

Marlin resets its locks after each call, so ordered calls can reuse them.

marlin_moe_intermediate_size(w1_packed, w2_packed)

Given Marlin packed weight matrices w1_packed, and w2_packed, return the MoE intermediate size N

marlin_moe_padded_intermediate(intermediate_size, group_size=-1)

Smallest MoE intermediate size satisfying the Marlin MoE thread tiles.

The kernel needs gate-up 2 * intermediate % 128 == 0 and down intermediate % 64 == 0, i.e. intermediate % 64 == 0. A misaligned size is zero-padded to the next valid tile at weight prep, kept a multiple of group_size so the group count stays integral. The padded region never reaches the MoE output: w13's padded output channels are zeroed by the zero-padded scales, so the padded inputs to w2 are zero.

marlin_pad_dim(x, size, padded)

Zero-pad the last dim from size to padded (activations K, bias N).

marlin_pad_qweight(qweight, size_n, size_k, padded_n, padded_k)

Zero-pad a GPTQ-layout packed weight (size_k / pack, size_n) for gptq_marlin_repack.

marlin_pad_scales(scales, size_n, size_k, padded_n, padded_k, group_size)

Zero-pad weight scales (num_groups, size_n); call before marlin_permute_scales and pass the padded extents to it.

marlin_padded_nk(size_n, size_k, group_size=-1)

Minimal (padded_n, padded_k) satisfying a Marlin thread-tile family.

Marlin GEMM and repack require (n % 64, k % 128) or (n % 128, k % 64); shapes satisfying neither are zero-padded up to the cheaper family. K stays divisible by group_size so padded scales keep an integral group count. Padded weight regions contribute nothing to the GEMM output: quantized value 0 decodes to 0.0 (FP4/FP8) or is cancelled by the zero-padded scales/zero-points (INT).

marlin_repacked_nk(qweight, num_bits)

Recover the (size_n, size_k) a Marlin weight was repacked with (including any tile padding) from its packed shape.

marlin_unpad_output(output, size_n, padded_n)

Strip padded output columns back to the logical N.

TODO: marlin_gemm could instead write the un-padded columns directly into a caller-provided c buffer so this slice copy disappears.

moe_packed_to_marlin_zero_points(q_zp_packed, size_k, size_n, num_bits)

Convert compressed-tensors packed zero points to Marlin format.

Unlike AWQ, compressed-tensors uses standard bit packing without interleaving, so we just unpack and apply Marlin permutation directly.