[MoE Refactor] Standardize Humming MoE experts + utilities (#43373)
Signed-off-by: Bill Nell <bnell@redhat.com> Co-authored-by: Robert Shaw <114415538+robertgshaw2-redhat@users.noreply.github.com>
This commit is contained in:
@@ -36,28 +36,42 @@ from vllm.model_executor.layers.fused_moe.utils import (
|
||||
_resize_cache,
|
||||
swiglu_limit_func,
|
||||
)
|
||||
from vllm.model_executor.layers.quantization.utils.quant_utils import QuantKey
|
||||
from vllm.model_executor.layers.quantization.utils.quant_utils import (
|
||||
QuantKey,
|
||||
kFp8DynamicTokenSym,
|
||||
kFp8Static128BlockSym,
|
||||
kFp8StaticChannelSym,
|
||||
kInt4Static,
|
||||
kInt8Static,
|
||||
kMxfp4Dynamic,
|
||||
kMxfp4Static,
|
||||
kMxfp8Dynamic,
|
||||
kMxfp8Static,
|
||||
kNvfp4Static,
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
from vllm.utils.humming import HummingLayerMeta, HummingMethod, dtypes
|
||||
from vllm.utils.import_utils import has_humming
|
||||
from vllm.v1.worker.workspace import current_workspace_manager
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.model_executor.layers.fused_moe import RoutedExperts
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def get_humming_moe_gemm_type() -> str:
|
||||
env_gemm_type: str = envs.VLLM_HUMMING_MOE_GEMM_TYPE or ""
|
||||
env_gemm_type = env_gemm_type.lower()
|
||||
if env_gemm_type == "indexed":
|
||||
gemm_type = env_gemm_type
|
||||
elif env_gemm_type in ["grouped_contiguous", "grouped"]:
|
||||
gemm_type = "grouped_contiguous"
|
||||
else:
|
||||
gemm_type = "indexed"
|
||||
def get_humming_moe_gemm_type() -> str | None:
|
||||
env_gemm_type: str | None = envs.VLLM_HUMMING_MOE_GEMM_TYPE
|
||||
gemm_type = None
|
||||
if env_gemm_type is not None:
|
||||
env_gemm_type = env_gemm_type.lower()
|
||||
if env_gemm_type == "indexed":
|
||||
gemm_type = env_gemm_type
|
||||
elif env_gemm_type in ["grouped_contiguous", "grouped"]:
|
||||
gemm_type = "grouped_contiguous"
|
||||
else:
|
||||
gemm_type = "indexed"
|
||||
|
||||
logger.info_once(f"Using {gemm_type} gemm for humming moe") # noqa
|
||||
return gemm_type
|
||||
@@ -89,6 +103,8 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
self._permute_scratch: MoEPermuteScratch | None = None
|
||||
|
||||
def init_humming_moe(self):
|
||||
from vllm.utils.humming import HummingMethod
|
||||
|
||||
self.compute_config = {
|
||||
"use_batch_invariant": envs.VLLM_BATCH_INVARIANT,
|
||||
"use_f16_accum": envs.VLLM_HUMMING_USE_F16_ACCUM,
|
||||
@@ -141,7 +157,7 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
return math.ceil(global_valid_shape_m * num_experts / global_num_experts)
|
||||
|
||||
@staticmethod
|
||||
def humming_gemm_type() -> HummingGemmType:
|
||||
def humming_gemm_type() -> "HummingGemmType":
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
@@ -153,12 +169,51 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
weight_key: QuantKey | None,
|
||||
activation_key: QuantKey | None,
|
||||
) -> bool:
|
||||
SUPPORTED_W_A = [
|
||||
(kMxfp4Static, None),
|
||||
(kMxfp4Static, kMxfp4Dynamic),
|
||||
(kMxfp4Static, kMxfp8Dynamic),
|
||||
(kMxfp4Static, kFp8DynamicTokenSym),
|
||||
(kNvfp4Static, None),
|
||||
(kNvfp4Static, kFp8DynamicTokenSym),
|
||||
(kMxfp8Static, None),
|
||||
(kMxfp8Static, kFp8DynamicTokenSym),
|
||||
(kFp8StaticChannelSym, None),
|
||||
(kFp8StaticChannelSym, kFp8DynamicTokenSym),
|
||||
(kFp8Static128BlockSym, None),
|
||||
(kFp8Static128BlockSym, kFp8DynamicTokenSym),
|
||||
(kInt4Static, None),
|
||||
(kInt4Static, kFp8DynamicTokenSym),
|
||||
(kInt8Static, None),
|
||||
(kInt8Static, kFp8DynamicTokenSym),
|
||||
]
|
||||
return (weight_key, activation_key) in SUPPORTED_W_A
|
||||
|
||||
@property
|
||||
def expects_unquantized_inputs(self) -> bool:
|
||||
"""
|
||||
Humming kernels handle input quantization internally via
|
||||
HummingMethod.may_quant_input() in the apply() method.
|
||||
|
||||
This property tells the prepare/finalize step to skip input
|
||||
quantization (by setting defer_input_quant=True) and pass
|
||||
unquantized inputs to the experts. This prevents double
|
||||
quantization: once in prepare and once in Humming's apply().
|
||||
|
||||
Returns:
|
||||
True to indicate that this expert expects unquantized inputs
|
||||
and will handle quantization internally.
|
||||
"""
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _supports_current_device() -> bool:
|
||||
platform = current_platform
|
||||
return platform.is_cuda() and platform.has_device_capability((7, 5))
|
||||
return (
|
||||
has_humming()
|
||||
and platform.is_cuda()
|
||||
and platform.has_device_capability((7, 5))
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _supports_no_act_and_mul() -> bool:
|
||||
@@ -182,10 +237,7 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
|
||||
@staticmethod
|
||||
def _supports_parallel_config(moe_parallel_config: FusedMoEParallelConfig) -> bool:
|
||||
return not (
|
||||
moe_parallel_config.use_fi_nvl_two_sided_kernels
|
||||
or moe_parallel_config.use_fi_nvl_one_sided_kernels
|
||||
)
|
||||
return True
|
||||
|
||||
def moe_problem_size(
|
||||
self,
|
||||
@@ -194,6 +246,8 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
w2: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
) -> tuple[int, int, int, int, int]:
|
||||
from vllm.utils.humming import HummingLayerMeta
|
||||
|
||||
meta1: HummingLayerMeta = self.layer.humming_metas["w13"]
|
||||
meta2: HummingLayerMeta = self.layer.humming_metas["w2"]
|
||||
|
||||
@@ -215,6 +269,9 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
return meta1.num_experts, num_tokens, meta1.shape_n // 2, meta1.shape_k, top_k
|
||||
|
||||
def get_buffer_metas(self, M: int, topk: int, activation: MoEActivation):
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
from vllm.utils.humming import dtypes
|
||||
|
||||
num_experts = self.num_experts
|
||||
N = self.layer.intermediate_size_per_partition
|
||||
K = self.layer.hidden_size
|
||||
@@ -254,7 +311,9 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
torch_dtype_map = {
|
||||
dtypes.float16: torch.float16,
|
||||
dtypes.bfloat16: torch.bfloat16,
|
||||
dtypes.float32: torch.float32,
|
||||
dtypes.float8e4m3: torch.float8_e4m3fn,
|
||||
dtypes.float8e5m2: torch.float8_e5m2,
|
||||
dtypes.int8: torch.int8,
|
||||
dtypes.int4: torch.uint8,
|
||||
}
|
||||
@@ -289,7 +348,13 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
for key in buffer_metas:
|
||||
meta = buffer_metas[key]
|
||||
if "quanted" in key and a_dtype.num_bits == 4:
|
||||
meta["shape"] = meta["shape"][:-1] + (meta["shape"][-1] // 2,)
|
||||
last_dim = meta["shape"][-1]
|
||||
if last_dim % 2 != 0:
|
||||
raise ValueError(
|
||||
f"Int4 packing requires last dimension to be even, "
|
||||
f"got {last_dim} for buffer '{key}'"
|
||||
)
|
||||
meta["shape"] = meta["shape"][:-1] + (last_dim // 2,)
|
||||
|
||||
if num_bits == 16:
|
||||
required_buffers = ["gate_up_output", "activation_output", "down_output"]
|
||||
@@ -325,8 +390,13 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
|
||||
output_key = "down_output" if self.is_batched() else "output"
|
||||
output_shape = buffer_metas[output_key]["shape"]
|
||||
elem_size = self.layer.params_dtype.itemsize
|
||||
|
||||
return (workspace1_nbytes // 2,), (workspace2_nbytes // 2,), output_shape
|
||||
return (
|
||||
(workspace1_nbytes // elem_size,),
|
||||
(workspace2_nbytes // elem_size,),
|
||||
output_shape,
|
||||
)
|
||||
|
||||
def workspace_shapes(
|
||||
self,
|
||||
@@ -344,7 +414,7 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
def make_workspaces(self, M: int, topk: int, activation: MoEActivation):
|
||||
shapes = self._workspace_shapes(M, topk, activation)
|
||||
workspace1_shape, workspace2_shape, output_shape = shapes
|
||||
torch_dtype = self.layer.param_dtype
|
||||
torch_dtype = self.layer.params_dtype
|
||||
workspace1, workspace2 = current_workspace_manager().get_simultaneous(
|
||||
(workspace1_shape, torch_dtype),
|
||||
(workspace2_shape, torch_dtype),
|
||||
@@ -370,45 +440,8 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
|
||||
return buffers
|
||||
|
||||
def apply(
|
||||
self,
|
||||
output: torch.Tensor,
|
||||
hidden_states: torch.Tensor,
|
||||
w1: torch.Tensor,
|
||||
w2: torch.Tensor,
|
||||
topk_weights: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
activation: MoEActivation,
|
||||
global_num_experts: int,
|
||||
expert_map: torch.Tensor | None,
|
||||
a1q_scale: torch.Tensor | None,
|
||||
a2_scale: torch.Tensor | None,
|
||||
workspace13: torch.Tensor,
|
||||
workspace2: torch.Tensor,
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
apply_router_weight_on_input: bool,
|
||||
):
|
||||
assert not apply_router_weight_on_input
|
||||
|
||||
self.main_apply(
|
||||
hidden_states=hidden_states,
|
||||
topk_weights=topk_weights,
|
||||
topk_ids=topk_ids,
|
||||
workspace1=workspace13,
|
||||
workspace2=workspace2,
|
||||
expert_tokens_meta=expert_tokens_meta,
|
||||
)
|
||||
|
||||
def main_apply(
|
||||
self,
|
||||
hidden_states: torch.Tensor,
|
||||
topk_weights: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
workspace1: torch.Tensor,
|
||||
workspace2: torch.Tensor,
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
):
|
||||
raise NotImplementedError
|
||||
# Note: apply method is implemented by subclasses following the
|
||||
# standard FusedMoEExpertsModular.apply signature
|
||||
|
||||
@staticmethod
|
||||
def is_supported_config(
|
||||
@@ -418,24 +451,27 @@ class HummingExpertsBase(mk.FusedMoEExpertsModular):
|
||||
activation_key: QuantKey | None,
|
||||
activation_format: mk.FusedMoEActivationFormat,
|
||||
) -> tuple[bool, str | None]:
|
||||
if activation_format == mk.FusedMoEActivationFormat.BatchedExperts:
|
||||
supported = cls.activation_format() == activation_format
|
||||
reason = "activation_format mismatched"
|
||||
elif activation_format == mk.FusedMoEActivationFormat.Standard:
|
||||
if cls.activation_format() != mk.FusedMoEActivationFormat.Standard:
|
||||
supported = False
|
||||
reason = "activation_format mismatched"
|
||||
else:
|
||||
assert hasattr(cls, "humming_gemm_type")
|
||||
gemm_type = cls.humming_gemm_type().value.lower()
|
||||
preferred_gemm_type = get_humming_moe_gemm_type().lower()
|
||||
supported = preferred_gemm_type == gemm_type
|
||||
reason = "preferred gemm type mismatched"
|
||||
else:
|
||||
supported = False
|
||||
reason = "unsupported activation_format"
|
||||
supported, reason = mk.FusedMoEExpertsModular.is_supported_config(
|
||||
cls,
|
||||
moe_config,
|
||||
weight_key,
|
||||
activation_key,
|
||||
activation_format,
|
||||
)
|
||||
|
||||
return supported, None if supported else reason
|
||||
if supported:
|
||||
assert hasattr(cls, "humming_gemm_type")
|
||||
gemm_type = cls.humming_gemm_type().value.lower()
|
||||
preferred_gemm_type = get_humming_moe_gemm_type()
|
||||
if preferred_gemm_type is not None:
|
||||
supported = preferred_gemm_type.lower() == gemm_type
|
||||
if not supported:
|
||||
reason = (
|
||||
f"preferred gemm type {preferred_gemm_type} != "
|
||||
f"supported gemm type {gemm_type}"
|
||||
)
|
||||
|
||||
return supported, reason
|
||||
|
||||
def apply_activation(
|
||||
self,
|
||||
@@ -459,7 +495,9 @@ class HummingIndexedExperts(HummingExpertsBase):
|
||||
return mk.FusedMoEActivationFormat.Standard
|
||||
|
||||
@staticmethod
|
||||
def humming_gemm_type() -> HummingGemmType:
|
||||
def humming_gemm_type() -> "HummingGemmType":
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
|
||||
return HummingGemmType.INDEXED
|
||||
|
||||
def prepare_humming_moe_kwargs(
|
||||
@@ -470,12 +508,18 @@ class HummingIndexedExperts(HummingExpertsBase):
|
||||
) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
valid_shape_m = self.estimate_local_valid_shape_m(topk_ids)
|
||||
|
||||
moe_block_size = None
|
||||
for min_shape_m, max_shape_m, config in self.w13_tuning_config:
|
||||
if valid_shape_m > min_shape_m and valid_shape_m <= max_shape_m:
|
||||
moe_block_size = config["block_shape"][0]
|
||||
break
|
||||
else:
|
||||
raise ValueError(f"cannot found moe_block_size for shape {valid_shape_m}")
|
||||
|
||||
if moe_block_size is None:
|
||||
logger.warning_once(
|
||||
"No tuning config found for shape %s, using default block_size=64",
|
||||
valid_shape_m,
|
||||
)
|
||||
moe_block_size = 64
|
||||
|
||||
sorted_ids, expert_ids, num_tokens_padded = moe_align_block_size(
|
||||
topk_ids=topk_ids,
|
||||
@@ -501,27 +545,47 @@ class HummingIndexedExperts(HummingExpertsBase):
|
||||
|
||||
return moe_kwargs1, moe_kwargs2
|
||||
|
||||
def main_apply(
|
||||
def apply(
|
||||
self,
|
||||
output: torch.Tensor,
|
||||
hidden_states: torch.Tensor,
|
||||
w1: torch.Tensor,
|
||||
w2: torch.Tensor,
|
||||
topk_weights: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
workspace1: torch.Tensor,
|
||||
activation: MoEActivation,
|
||||
global_num_experts: int,
|
||||
expert_map: torch.Tensor | None,
|
||||
a1q_scale: torch.Tensor | None,
|
||||
a2_scale: torch.Tensor | None,
|
||||
workspace13: torch.Tensor,
|
||||
workspace2: torch.Tensor,
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
):
|
||||
apply_router_weight_on_input: bool,
|
||||
) -> None:
|
||||
"""
|
||||
Standard apply implementation for Humming indexed experts.
|
||||
|
||||
Note: Humming kernels handle weights and quantization internally through
|
||||
the layer object, so w1, w2, a1q_scale, a2_scale parameters are not used.
|
||||
The output is written into workspace13 via the buffer management.
|
||||
"""
|
||||
from vllm.utils.humming import HummingMethod
|
||||
|
||||
assert not apply_router_weight_on_input
|
||||
|
||||
hidden_states = hidden_states.view(-1, hidden_states.size(-1))
|
||||
buffers = self.prepare_buffers(
|
||||
workspace1,
|
||||
workspace13,
|
||||
workspace2,
|
||||
topk_ids.size(0),
|
||||
topk_ids.size(1),
|
||||
self.layer.activation,
|
||||
activation,
|
||||
)
|
||||
|
||||
moe_kwargs1, moe_kwargs2 = self.prepare_humming_moe_kwargs(
|
||||
topk_ids=topk_ids,
|
||||
expert_map=self.layer.expert_map,
|
||||
expert_map=expert_map,
|
||||
expert_tokens_meta=expert_tokens_meta,
|
||||
)
|
||||
|
||||
@@ -542,7 +606,7 @@ class HummingIndexedExperts(HummingExpertsBase):
|
||||
)
|
||||
|
||||
self.apply_activation(
|
||||
activation=self.layer.activation,
|
||||
activation=activation,
|
||||
input=buffers["gate_up_output"],
|
||||
output=buffers["activation_output"],
|
||||
)
|
||||
@@ -567,10 +631,13 @@ class HummingIndexedExperts(HummingExpertsBase):
|
||||
inputs=buffers["down_output"].view(*topk_ids.shape, -1),
|
||||
topk_weights=topk_weights,
|
||||
topk_ids=topk_ids,
|
||||
expert_map=self.layer.expert_map,
|
||||
expert_map=expert_map,
|
||||
outputs=buffers["output"],
|
||||
)
|
||||
|
||||
# Note: output is already written to buffers["output"]
|
||||
# which aliases workspace13/output
|
||||
|
||||
|
||||
class HummingGroupedExperts(HummingExpertsBase):
|
||||
def finalize_weight_and_reduce_impl(self) -> mk.TopKWeightAndReduce:
|
||||
@@ -581,35 +648,57 @@ class HummingGroupedExperts(HummingExpertsBase):
|
||||
return mk.FusedMoEActivationFormat.Standard
|
||||
|
||||
@staticmethod
|
||||
def humming_gemm_type() -> HummingGemmType:
|
||||
def humming_gemm_type() -> "HummingGemmType":
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
|
||||
return HummingGemmType.GROUPED_CONTIGUOUS
|
||||
|
||||
def main_apply(
|
||||
def apply(
|
||||
self,
|
||||
output: torch.Tensor,
|
||||
hidden_states: torch.Tensor,
|
||||
w1: torch.Tensor,
|
||||
w2: torch.Tensor,
|
||||
topk_weights: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
workspace1: torch.Tensor,
|
||||
activation: MoEActivation,
|
||||
global_num_experts: int,
|
||||
expert_map: torch.Tensor | None,
|
||||
a1q_scale: torch.Tensor | None,
|
||||
a2_scale: torch.Tensor | None,
|
||||
workspace13: torch.Tensor,
|
||||
workspace2: torch.Tensor,
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
):
|
||||
apply_router_weight_on_input: bool,
|
||||
) -> None:
|
||||
"""
|
||||
Standard apply implementation for Humming grouped experts.
|
||||
|
||||
Note: Humming kernels handle weights and quantization internally through
|
||||
the layer object, so w1, w2, a1q_scale, a2_scale parameters are not used.
|
||||
The output is written into workspace13 via the buffer management.
|
||||
"""
|
||||
from vllm.utils.humming import HummingMethod
|
||||
|
||||
assert not apply_router_weight_on_input
|
||||
|
||||
valid_shape_m = self.estimate_local_valid_shape_m(topk_ids)
|
||||
|
||||
buffers = self.prepare_buffers(
|
||||
workspace1,
|
||||
workspace13,
|
||||
workspace2,
|
||||
topk_ids.size(0),
|
||||
topk_ids.size(1),
|
||||
self.layer.activation,
|
||||
activation,
|
||||
)
|
||||
|
||||
hidden_states, _, expert_first_token_offset, inv_perm, _ = moe_permute(
|
||||
hidden_states=hidden_states,
|
||||
a1q_scale=None,
|
||||
topk_ids=topk_ids,
|
||||
n_expert=self.global_num_experts,
|
||||
n_expert=global_num_experts,
|
||||
n_local_expert=self.num_experts,
|
||||
expert_map=self.layer.expert_map,
|
||||
expert_map=expert_map,
|
||||
scratch=self._get_permute_scratch(),
|
||||
)
|
||||
|
||||
@@ -633,7 +722,7 @@ class HummingGroupedExperts(HummingExpertsBase):
|
||||
)
|
||||
|
||||
self.apply_activation(
|
||||
activation=self.layer.activation,
|
||||
activation=activation,
|
||||
input=buffers["gate_up_output"],
|
||||
output=buffers["activation_output"],
|
||||
)
|
||||
@@ -665,6 +754,9 @@ class HummingGroupedExperts(HummingExpertsBase):
|
||||
expert_first_token_offset=expert_first_token_offset,
|
||||
)
|
||||
|
||||
# Note: output is already written to buffers["output"]
|
||||
# which aliases workspace13/output
|
||||
|
||||
|
||||
class BatchedHummingGroupedExperts(HummingExpertsBase):
|
||||
def finalize_weight_and_reduce_impl(self) -> mk.TopKWeightAndReduce:
|
||||
@@ -675,29 +767,51 @@ class BatchedHummingGroupedExperts(HummingExpertsBase):
|
||||
return mk.FusedMoEActivationFormat.BatchedExperts
|
||||
|
||||
@staticmethod
|
||||
def humming_gemm_type() -> HummingGemmType:
|
||||
def humming_gemm_type() -> "HummingGemmType":
|
||||
from vllm.utils.humming import GemmType as HummingGemmType
|
||||
|
||||
return HummingGemmType.GROUPED_MASKED
|
||||
|
||||
def main_apply(
|
||||
def apply(
|
||||
self,
|
||||
output: torch.Tensor,
|
||||
hidden_states: torch.Tensor,
|
||||
w1: torch.Tensor,
|
||||
w2: torch.Tensor,
|
||||
topk_weights: torch.Tensor,
|
||||
topk_ids: torch.Tensor,
|
||||
workspace1: torch.Tensor,
|
||||
activation: MoEActivation,
|
||||
global_num_experts: int,
|
||||
expert_map: torch.Tensor | None,
|
||||
a1q_scale: torch.Tensor | None,
|
||||
a2_scale: torch.Tensor | None,
|
||||
workspace13: torch.Tensor,
|
||||
workspace2: torch.Tensor,
|
||||
expert_tokens_meta: mk.ExpertTokensMetadata | None,
|
||||
):
|
||||
apply_router_weight_on_input: bool,
|
||||
) -> None:
|
||||
"""
|
||||
Standard apply implementation for Humming batched grouped experts.
|
||||
|
||||
Note: Humming kernels handle weights and quantization internally through
|
||||
the layer object, so w1, w2, a1q_scale, a2_scale parameters are not used.
|
||||
The output is written into workspace13 via the buffer management.
|
||||
"""
|
||||
from vllm.utils.humming import HummingMethod
|
||||
|
||||
assert not apply_router_weight_on_input
|
||||
assert expert_tokens_meta is not None
|
||||
|
||||
hidden_states = hidden_states.view(-1, hidden_states.size(-1))
|
||||
valid_shape_m = self.estimate_local_valid_shape_m(topk_ids)
|
||||
expert_num_tokens = expert_tokens_meta.expert_num_tokens
|
||||
|
||||
buffers = self.prepare_buffers(
|
||||
workspace1,
|
||||
workspace13,
|
||||
workspace2,
|
||||
topk_ids.size(0),
|
||||
topk_ids.size(1),
|
||||
self.layer.activation,
|
||||
activation,
|
||||
)
|
||||
|
||||
inputs, input_scale = HummingMethod.may_quant_input(
|
||||
@@ -720,7 +834,7 @@ class BatchedHummingGroupedExperts(HummingExpertsBase):
|
||||
)
|
||||
|
||||
self.apply_activation(
|
||||
activation=self.layer.activation,
|
||||
activation=activation,
|
||||
input=buffers["gate_up_output"],
|
||||
output=buffers["activation_output"],
|
||||
)
|
||||
@@ -743,3 +857,6 @@ class BatchedHummingGroupedExperts(HummingExpertsBase):
|
||||
tuning_config=self.w2_tuning_config_str,
|
||||
sublayer_name="w2",
|
||||
)
|
||||
|
||||
# Note: output is already written to buffers["down_output"]
|
||||
# which aliases workspace13/output
|
||||
|
||||
@@ -711,10 +711,12 @@ def convert_gpt_oss_weight_to_mxfp4_moe_kernel_format(
|
||||
|
||||
if mxfp4_backend == Mxfp4MoeBackend.HUMMING:
|
||||
from vllm.model_executor.layers.quantization.utils.humming_utils import (
|
||||
prepare_humming_moe_layer,
|
||||
convert_to_humming_moe_kernel_format,
|
||||
)
|
||||
|
||||
prepare_humming_moe_layer(layer, {"quant_method": "gpt_oss_mxfp4"})
|
||||
convert_to_humming_moe_kernel_format(
|
||||
layer, quant_config={"quant_method": "gpt_oss_mxfp4"}
|
||||
)
|
||||
return (
|
||||
layer.w13_weight,
|
||||
layer.w2_weight,
|
||||
@@ -1277,10 +1279,12 @@ def convert_weight_to_mxfp4_moe_kernel_format(
|
||||
|
||||
if mxfp4_backend == Mxfp4MoeBackend.HUMMING:
|
||||
from vllm.model_executor.layers.quantization.utils.humming_utils import (
|
||||
prepare_humming_moe_layer,
|
||||
convert_to_humming_moe_kernel_format,
|
||||
)
|
||||
|
||||
prepare_humming_moe_layer(layer, {"quant_method": "mxfp4"})
|
||||
convert_to_humming_moe_kernel_format(
|
||||
layer, quant_config={"quant_method": "mxfp4"}
|
||||
)
|
||||
return (
|
||||
layer.w13_weight,
|
||||
layer.w2_weight,
|
||||
@@ -1569,7 +1573,7 @@ def make_mxfp4_moe_quant_config(
|
||||
w2_bias: torch.Tensor | None = None,
|
||||
a1_scale: torch.Tensor | None = None,
|
||||
a2_scale: torch.Tensor | None = None,
|
||||
layer: torch.nn.Module | None = None,
|
||||
layer: "RoutedExperts | None" = None,
|
||||
) -> FusedMoEQuantConfig | None:
|
||||
"""Create a FusedMoEQuantConfig for the given MXFP4 backend."""
|
||||
if mxfp4_backend == Mxfp4MoeBackend.DEEPGEMM_MXFP4:
|
||||
@@ -1662,7 +1666,7 @@ def make_mxfp4_moe_quant_config(
|
||||
get_humming_moe_quant_config,
|
||||
)
|
||||
|
||||
assert isinstance(layer, RoutedExperts)
|
||||
assert layer is not None
|
||||
return get_humming_moe_quant_config(
|
||||
layer,
|
||||
gemm1_alpha=gemm1_alpha,
|
||||
@@ -1703,6 +1707,7 @@ def make_mxfp4_moe_kernel(
|
||||
assert prepare_finalize is not None
|
||||
|
||||
logger.info_once("Using %s", prepare_finalize.__class__.__name__)
|
||||
logger.info_once("Using %s", experts_cls.__name__)
|
||||
|
||||
extra_kwargs = {}
|
||||
if mxfp4_backend == Mxfp4MoeBackend.HUMMING:
|
||||
|
||||
Reference in New Issue
Block a user