vllm.model_executor.layers.quantization.utils.humming.moe
¶
Configure, prepare weights for, and assemble Humming MoE kernels.
Functions:
-
convert_to_humming_moe_kernel_format–Convert MoE weights from checkpoint format to Humming kernel format.
-
select_humming_moe_experts–Select the primary Humming MoE Experts class
-
stage_moe_weights_for_humming–Install canonical weights and scales for Humming's layer-based converter.
_convert_sublayer_to_humming(layer, sublayer_name, shape_n, shape_k, weight_schema, input_schema, num_experts, param_dtype)
¶
_extract_sublayer_tensors(layer, sublayer_name)
¶
Extract a sublayer's live params and persistent buffers.
_prepare_and_transform_sublayer(layer, sublayer_name, shape_n, shape_k, weight_schema, input_schema, has_bias, num_experts, param_dtype)
¶
Prepare Humming configuration and transform one sublayer's tensors.
_process_single_sublayer(layer, sublayer_name, shape_n, shape_k, weight_schema, input_schema, has_bias, num_experts, param_dtype, force_weight_schema=None, allow_input_schema_fallback=True)
¶
Process a single sublayer: convert, optionally requant, prepare, and transform.
This combines the common logic from convert_to_humming_moe_kernel_format for processing a single sublayer.
Parameters:
-
(layer¶RoutedExperts) –The RoutedExperts layer
-
(sublayer_name¶str) –Name of the sublayer (e.g., "w13", "w2")
-
(shape_n¶int) –Output dimension size
-
(shape_k¶int) –Input dimension size
-
(weight_schema¶Any) –Initial weight quantization schema
-
(input_schema¶Any) –Initial input quantization schema
-
(has_bias¶bool) –Whether the layer has bias terms
-
(num_experts¶int) –Number of experts
-
(param_dtype¶dtype) –Parameter data type
-
(force_weight_schema¶Any | None, default:None) –Optional schema to force requantization to
-
(allow_input_schema_fallback¶bool, default:True) –Whether incompatible input schemas may be replaced.
Returns:
_replace_layer_parameters(layer, sublayer_name, tensors, preserve_bias=False)
¶
Replace layer parameters for a sublayer with new tensors.
Parameters:
convert_to_humming_moe_kernel_format(layer, quant_config=None, sublayer_configs=None, weight_schema=None, input_schema=None, force_weight_schema=None, allow_input_schema_fallback=True)
¶
Convert MoE weights from checkpoint format to Humming kernel format.
This function processes weights for each sublayer (w13, w2) by: 1. Converting from checkpoint format to humming format if needed 2. Force requanting if a different quantization schema is specified 3. Preparing layer metadata for the Humming kernel 4. Transforming weights for inference
Parameters:
-
(layer¶RoutedExperts) –The RoutedExperts layer containing weights to process
-
(quant_config¶dict | None, default:None) –Optional quantization config dict. Required if weight_schema or input_schema are None. Used to build schemas via BaseWeightSchema.from_config().
-
(sublayer_configs¶dict[str, Any] | None, default:None) –Optional configuration dict for each sublayer (w13, w2). Each config must have "shape_n" and "shape_k" keys. If None, configs are built from layer.moe_config properties.
-
(weight_schema¶Any | None, default:None) –Optional initial weight quantization schema. If None, built from quant_config.
-
(input_schema¶Any | None, default:None) –Optional initial input quantization schema. If None, built from quant_config or env vars.
-
(force_weight_schema¶Any | None, default:None) –Optional schema to force requantization to
-
(allow_input_schema_fallback¶bool, default:True) –Whether incompatible input schemas may be replaced.
Side effects
- Modifies layer parameters in place
- Sets layer.weight_schemas and layer.input_schemas
- Sets layer.humming_configs for quant config construction
select_humming_moe_experts(config, weight_key, activation_key)
¶
Select the primary Humming MoE Experts class Note: Shape-specific fallbacks may still occur at runtime.
stage_moe_weights_for_humming(layer, w13, w2, w13_scale, w2_scale, w13_input_scale=None, w2_input_scale=None)
¶
Install canonical weights and scales for Humming's layer-based converter.
Returns the scale parameter name used, weight_scale or
weight_scale_inv.