Skip to content

vllm.model_executor.layers.fused_moe.modular_kernel

Classes:

ExpertTokensMetadata dataclass

Metadata regarding expert-token routing.

FusedMoEActivationFormat

Bases: Enum

The standard activation format (num_tokens, hidden dim).

Methods:

  • is_superset –

    Whether this (experts) format is a superset of pf_format, i.e.

Attributes:

  • BatchedExperts –

    Like 'Standard' (num_tokens, hidden dim), but the row count is an upper

  • Standard –

    The batched experts format (num experts, max tokens per expert, hidden dim)

  • is_batched (bool) –

    Whether this is the disjoint BatchedExperts format.

BatchedExperts = ('batched_experts',) class-attribute instance-attribute

Like 'Standard' (num_tokens, hidden dim), but the row count is an upper bound rather than the exact token count, so some rows are inactive padding.

Produced by all2all backends (DeepEP v2) that cannot report the received token count on the host without a device sync. Padding comes from the worst-case recv allocation (decode/cudagraph mode, where the tail rows are left uninitialized) and from per-expert block alignment (prefill mode, where the gaps are zeroed).

Inactive rows are marked by setting all of their topk_ids slots to -1; when available, ExpertTokensMetadata.psum_recv_per_rank carries the real/padding boundary on device. Consuming kernels must therefore either skip such rows or produce results for them that are safe to discard -- padding rows may hold uninitialized garbage, so an expert that derives routing by scanning every row will corrupt real tokens if it ignores the -1 markers. Only experts declaring this format are paired with such a prepare/finalize step; see is_superset.

Standard = ('standard',) class-attribute instance-attribute

The batched experts format (num experts, max tokens per expert, hidden dim)

is_batched property

Whether this is the disjoint BatchedExperts format.

is_superset(pf_format)

Whether this (experts) format is a superset of pf_format, i.e. an experts kernel declaring self can consume activations produced by a prepare/finalize step in pf_format.

The relation is directional: self is the experts format and pf_format is the prepare/finalize format. PaddedStandard is a superset of Standard (a padding-aware kernel treats unpadded input as the zero-padding case), but not vice versa. All other formats are only supersets of themselves.

FusedMoEExperts

Bases: ABC

Methods:

Attributes:

expects_unquantized_inputs property

Whether or not the PrepareFinalize should defer input quantization in the prepare step. If True, then the Experts kernel will execute the input quantization itself.

Sample subclasses that override are AITER and FlashInfer CUTLASS.

__init__(moe_config, quant_config, max_num_tokens=None, num_dispatchers=None)

moe_config: MoE layer configuration. quant_config: Quantization parameters for this experts instance.

_supports_activation(activation) abstractmethod staticmethod

Whether the kernel supports a particular act function.

_supports_batch_invariance() staticmethod

Whether the kernel supports batch invariance, i.e. the output does not depend on the order of the tokens in the input batch. This is useful for determining if the kernel can used with VLLM_BATCH_INVARIANT=1.

_supports_current_device() abstractmethod staticmethod

Whether the kernel supports the current device type (compute cability and current platform).

_supports_hash_routing() staticmethod

Whether a monolithic kernel implements hash routing itself.

Kernels that return True receive input_ids and hash_indices_table in apply() for layers with a hash-routing table.

_supports_no_act_and_mul() abstractmethod staticmethod

Whether the kernel supports act_and_mul=False, i.e. non-gated MoE models like Nemotron-Nano.

_supports_parallel_config(moe_parallel_config) abstractmethod staticmethod

Whether the kernel supports deployment in particular parallel config.

Can be overridden if a kernel does not support EP, SP or some other configuration.

_supports_router_logits_dtype(router_logits_dtype, routing_method) staticmethod

Whether a kernel supports a particular dtype for router logits input.

Can be overridden by monolithic kernels that execute the router in addition to the experts if certain dtypes are not supported.

_supports_routing_method(routing_method, weight_key, activation_key) staticmethod

Whether the kernel supports a routing method (e.g. GroupedTopK).

Can be overridden by monolithic kernels that execute the router in addition to the experts if certain routers are not supported.

_supports_shape(hidden_dim) staticmethod

Whether a kernel supports a particular shape. Can be overridden if a kernel has specific shape requirements.

activation_format() abstractmethod staticmethod

The activation format this experts kernel consumes. A kernel declaring PaddedStandard also accepts Standard input (see FusedMoEActivationFormat.is_superset).

executed_activation_key(weight_key, activation_key) staticmethod

The activation quantization the kernel runs for a layer requesting activation_key. Weight-only kernels return None; is_supported_config then warns about, or under VLLM_STRICT_QUANT_SCHEME forbids, the fallback.

keep_constants(layer, prefix='_experts_')

Point kept_constants at tensors kept on layer (as prefix + name.lstrip("_")), refilled in place: every post-load rerun builds a new experts object, and captured CUDA graphs read the first one's.

supports_lora() staticmethod

Return True if this expert impl natively handles LoRA.

LoRA-aware experts should mix in LoRAExpertsMixin, which flips this to True and provides the per-forward LoRA state plumbing.

supports_packed_ue8m0_act_scales()

A flag indicating whether or not this class can process packed ue8m0 activation scales.

FusedMoEExpertsModular

Bases: FusedMoEExperts

An abstract base class for the [Permute-Experts-Unpermute] step described above.

Methods:

  • adjust_N_for_activation –

    Calculate the output dimension for the activation function.

  • apply –

    This function computes the intermediate result of a Mixture of Experts

  • moe_problem_size –

    Extract the MoE problem size from the given tensor arguments:

  • output_hidden_dim –

    Hidden size of the finalized output. Experts that drop the hidden

  • workspace_dtype –

    Workspace type: The dtype to use for the workspace tensors.

  • workspace_shapes –

    Compute the shapes for the temporary and final outputs of the two gemms

adjust_N_for_activation(N, activation) staticmethod

Calculate the output dimension for the activation function.

For *_no_mul activations (e.g. relu2_no_mul), there's no gate/up split, so output size equals input size (N).

For regular gated activations (e.g., silu, gelu, swigluoai), output size is N // 2 due to gate × activation(up) multiplication.

Parameters:

  • N

    (int) –

    The intermediate size (width of w1/w3 weights).

  • activation

    (MoEActivation) –

    The activation function enum.

Returns:

  • int –

    The output dimension after activation.

apply(output, hidden_states, w1, w2, topk_weights, topk_ids, activation, global_num_experts, expert_map, a1q_scale, a2_scale, workspace13, workspace2, expert_tokens_meta, apply_router_weight_on_input) abstractmethod

This function computes the intermediate result of a Mixture of Experts (MoE) layer using two sets of weights, w1 and w2.

Writes into output and returns None, unless the implementation stopped after GEMM2 and left the top-k reduction to a fused consumer, in which case output is untouched and the unfinalized result is returned.

Parameters:

  • output

    (Tensor) –

    (torch.Tensor): The unweighted, unreduced output tensor.

  • hidden_states

    (Tensor) –

    (torch.Tensor): The (quantized) input tensor to the MoE layer.

  • w1

    (Tensor) –

    The first set of expert weights.

  • w2

    (Tensor) –

    The second set of expert weights.

  • topk_weights

    (Tensor) –

    A map of row to expert weights. Some implementations choose to do weight application.

  • topk_ids

    (Tensor) –

    A map of row to expert id.

  • activation

    (str) –

    The activation function to apply after the first MoE layer.

  • global_num_experts

    (int) –

    The total number of experts in the global expert space.

  • expert_map

    (Optional[Tensor]) –

    A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard.

  • a1q_scale

    (Optional[Tensor]) –

    Optional quantized scale to be used for a1. Result of quantization from prepare/finalize and not from the FusedMoEQuantConfig.

  • a2_scale

    (Optional[Tensor]) –

    Optional quantized scale to be used for the second gemm's activations.

  • workspace13

    (Tensor) –

    A scratch tensor used for gemm outputs must be large enough to hold output of either MoE gemm.

  • workspace2

    (Tensor) –

    A scratch tensor used for the activation function.

  • expert_tokens_meta

    (Optional[ExpertTokensMetadata]) –

    An optional ExpertTokensMetadata object containing gpu/cpu tensors as big as the number of local experts with the information about the number of tokens assigned to each local expert.

  • apply_router_weight_on_input

    (bool) –

    True if router weights are already applied on the input. This is relevant if the implementation chooses to do weight application.

moe_problem_size(a1, w1, w2, topk_ids)

Extract the MoE problem size from the given tensor arguments: - a: The hidden states, input to the MoE layer. - w1: The first set of expert weights. - w2: The second set of expert weights. - topk_ids: The topk ids.

Note: extracting the problem shape from the weight and activation tensors is not obvious. It needs to be done this way specifically due to subtle issues with particular kernels, e.g. the int4 kernels divide the trailing dimension by two, so it's not "correct" to extract N or K from the trailing dimension of w1 or w2. Similarly, some kernels transpose the weights, so this needs to be kept in mind.

Note: This implementation covers most cases. However, if experts require a specialized implementation, like MarlinExperts, they are free to override this function.

output_hidden_dim(hidden_dim)

Hidden size of the finalized output. Experts that drop the hidden padding return the unpadded size.

workspace_dtype(act_dtype)

Workspace type: The dtype to use for the workspace tensors.

workspace_shapes(M, N, K, topk, global_num_experts, local_num_experts, expert_tokens_meta, activation) abstractmethod

Compute the shapes for the temporary and final outputs of the two gemms and activation in the fused expert function. Since the gemms are independent, the workspace for the first gemm can be shared with the workspace for the last gemm.

Inputs: - M: number of tokens. - N: Row (or column) dimension of expert weights. - K: hidden dimension - topk: The number of top-k experts to select. - global_num_experts: global number of experts. - local_num_experts: local number of experts due to DP/EP. - expert_tokens_meta: number of tokens per expert metadata for batched format.

Returns a tuple of: - workspace13 shape tuple: must be large enough to hold the result of either expert gemm. - workspace2 shape tuple: must be large enough to hold the result of the activation function. - output shape tuple: must be exact size of the final gemm output. - Note: workspace shapes can be 0 if the workspace is not needed. But in order for activation chunking to work, the first dimension of each tuple must be the number of tokens when the shape is not 0.

FusedMoEExpertsMonolithic

Bases: FusedMoEExperts

An abstract base class for the [Permute-Experts-Unpermute] step described above, but with the monolithic interface (accepts router logits rather than topk ids and weights).

Methods:

_supports_router_logits_dtype(router_logits_dtype, routing_method) staticmethod

Whether the kernel supports a dtype for router logits.

Modular kernels should opt-in to support.

_supports_routing_method(routing_method, weight_key, activation_key) staticmethod

Whether the kernel supports a routing method (e.g. GroupedTopK).

Monolithic kernels should explicitly opt-in to support.

apply(hidden_states, w1, w2, router_logits, activation, global_num_experts, expert_map, a1q_scale, apply_router_weight_on_input, num_expert_group=None, e_score_correction_bias=None, routed_scaling_factor=None, topk_group=None, routing_replay_out=None)

Same as FusedMoEExperts.apply, except uses router_logits as opposed to the topk_ids and topk_weights. This is useful for kernels with fused router and fused_experts (e.g. FLASHINFER_TRTLLM).

Kernels that supports_routing_replay_capture write each token's routed expert ids into the leading rows of routing_replay_out.

apply_precomputed_routing(hidden_states, w1, w2, topk_weights, topk_ids, activation, global_num_experts, a1q_scale)

Same as apply, but with routing computed by vLLM's router.

Tokens whose topk_ids are -1 (padding) must not reach any expert.

supports_precomputed_routing()

Whether apply_precomputed_routing is implemented.

supports_routing_replay_capture()

Whether this expert supports routing replay capture.

Subclasses backed by a kernel that exposes routed expert IDs (e.g. FlashInfer's routing_replay_out) should override.

FusedMoEKernel

Methods:

_post_init_setup()

Resolve any leftover setup dependencies between self.prepare_finalize and self.fused_experts here.

output_is_reduced()

Indicates whether or not the output of fused MoE kernel is reduced across all ranks.

supports_precomputed_routing()

Whether apply_monolithic_routed can replace apply_monolithic.

FusedMoEKernelModularImpl

Methods:

  • apply –

    This function computes a Mixture of Experts (MoE) layer using two sets

_allocate_buffers(out_dtype, device, M_chunk, M_full, N, K, top_k, global_num_experts, local_num_experts, expert_tokens_meta, activation)

Allocate temporary and output buffers for the fused experts op. Inputs: - out_dtype: output type of workspace and output tensors. - device: the device of the workspace and output tensors. See workspace_shapes for a description of the remainder of arguments. Returns the workspace tensors, output tensor, and whether the output uses a prepare/finalize-provided allocation.

_finalize(output, fused_out, hidden_states, topk_weights, topk_ids, apply_router_weight_on_input, shared_experts, shared_experts_input)

The _finalize method is a wrapper around self.prepare_finalize.finalize that handles DBO, async and shared expert overlap.

Parameters:

  • output

    (Tensor) –

    Tensor the finalized result is written into.

  • fused_out

    (Tensor) –

    The unweighted, unreduced output of the fused experts.

  • hidden_states

    (Tensor) –

    The input tensor to the MoE layer.

  • topk_weights

    (Tensor) –

    A map of row to expert weights.

  • topk_ids

    (Tensor) –

    A map of row to expert id.

  • apply_router_weight_on_input

    (bool) –

    True if the router weights were already applied on the input.

  • shared_experts

    (SharedExperts | None) –

    SharedExperts | None. The shared experts if any.

  • shared_experts_input

    (Tensor | None) –

    Optional separate input for shared experts. When latent MoE is used, hidden_states is the latent-projected tensor (smaller dimension) used by routed experts, while shared_experts_input is the original hidden_states (full dimension) needed by the shared expert MLP.

_prepare(hidden_states, topk_weights, topk_ids, global_num_experts, expert_map, apply_router_weight_on_input)

The _prepare method is a wrapper around self.prepare_finalize.prepare that handles DBO and async.

apply(hidden_states, w1, w2, topk_ids, topk_weights, activation=MoEActivation.SILU, global_num_experts=-1, expert_map=None, apply_router_weight_on_input=False, shared_experts=None, shared_experts_input=None)

This function computes a Mixture of Experts (MoE) layer using two sets of weights, w1 and w2, and top-k gating mechanism.

Parameters:

  • hidden_states

    (Tensor) –

    (torch.Tensor): The input tensor to the MoE layer.

  • w1

    (Tensor) –

    The first set of expert weights.

  • w2

    (Tensor) –

    The second set of expert weights.

  • topk_ids

    (Tensor) –

    A map of row to expert id.

  • topk_weights

    (Tensor) –

    The topk weights applied at the end of the layer.

  • activation

    (MoEActivation, default: SILU ) –

    The activation function to apply after the first MoE layer.

  • global_num_experts

    (int, default: -1 ) –

    The total number of experts in the global expert space.

  • expert_map

    (Optional[Tensor], default: None ) –

    A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard.

  • apply_router_weight_on_input

    (bool, default: False ) –

    Apply router weights before activation. The expert selects whether prepare or GEMM1 applies them; GEMM2 and finalize must not apply them again.

  • shared_experts

    (SharedExperts | None, default: None ) –

    SharedExperts | None. The shared experts if any.

  • shared_experts_input

    (Optional[Tensor], default: None ) –

    Optional separate input for shared experts. For latent MoE, this is the original hidden_states before latent projection.

Returns:

FusedMoEKernelMonolithicImpl

Methods:

  • apply –

    Same as forward(), except uses router_logits as opposed

  • apply_routed –

    Like apply, but with routing from vLLM's top-k.

apply(hidden_states, w1, w2, router_logits, activation, global_num_experts, expert_map, apply_router_weight_on_input, num_expert_group=None, e_score_correction_bias=None, routed_scaling_factor=None, topk_group=None, *, routing_sink, input_ids=None, hash_indices_table=None, a1q_scale=None)

Same as forward(), except uses router_logits as opposed to the topk_ids and topk_weights. This is used for kernels that have fused router + experts (e.g. FLASHINFER_TRTLLM). a1q_scale is given when the caller already quantized hidden_states.

apply_routed(hidden_states, w1, w2, topk_weights, topk_ids, activation, global_num_experts, *, routing_sink)

Like apply, but with routing from vLLM's top-k.

FusedMoEPrepareAndFinalize

Bases: ABC

An abstract base class for the [Quantize-Prepare] and [Finalize] steps described above.

There are two variants of this class: * FusedMoEPrepareAndFinalizeModular - this operates on topk ids and weights * FusedMoEPrepareAndFinalizeMonolithic - the operates on router_logits

Methods:

Attributes:

activation_format abstractmethod property

A property indicating the output format of the activations for the 'prepare' method.

allocate_fused_expert_output(shape, dtype, device, weight_and_reduce_impl)

Optionally provide the exact output buffer for the expert kernel.

Implementations returning a tensor must preserve its identity through finalize; replacing it may silently reintroduce a write-back copy.

max_num_tokens_per_rank() abstractmethod

Some PrepareFinalize All2All implementations are batched. Meaning, they can process only as set of tokens at a time. This function returns the batch size i.e the maximum number of tokens the implementation can process at a time. Return None if there are no such restrictions.

output_is_reduced() abstractmethod

Indicates whether or not the output of finalize is reduced across all ranks.

post_init_setup(fused_experts)

Initialize FusedMoEPrepareAndFinalizeModular settings that depend on FusedMoEExpertsModular experts object. The FusedMoEPrepareAndFinalizeModular implementations that have such dependencies may choose to override this function.

supports_async()

Indicates whether or not this class implements prepare_async and finalize_async.

supports_dbo()

Indicates whether or not this class can run under the dispatch-combine-overlap DBO schedule.

Defaults to supports_async(). A class whose synchronous prepare and finalize do their own DBO compute/comm handoff can return True here while keeping supports_async() False.

supports_deferred_moe_finalize()

Whether finalize can be skipped for a deferring consumer.

An implementation opts in only if everything it does in finalize -- the top-k reduction, and any combine or reduce-scatter -- is work the consumer takes over.

topk_indices_dtype() abstractmethod

The PrepareFinalize All2All implementations generally constrain the dtype of the topk_ids they support. This function returns the required topk indices dtype so it can be respected. Return None if there are no such restrictions.

FusedMoEPrepareAndFinalizeModular

Bases: FusedMoEPrepareAndFinalize

An abstract base class for the [Quantize-Prepare] and [Finalize] steps described above for the Modular case.

Methods:

  • finalize –

    Perform any combine plus apply weights and perform a reduction on the

  • finalize_async –

    Perform any combine plus apply weights and perform a reduction on the

  • prepare –

    Perform any quantization (and/or) dispatching needed for this kernel.

  • prepare_async –

    Perform any quantization (and/or) dispatching needed for this kernel

finalize(output, fused_expert_output, topk_weights, topk_ids, apply_router_weight_on_input, weight_and_reduce_impl) abstractmethod

Perform any combine plus apply weights and perform a reduction on the fused experts output. - output: The output tensor, written in place. Must be (M, K) shape. - fused_expert_output: The unweighted, unreduced output of the fused experts, it will have (M, topk, K) shape. - topk_weights: The weights to be applied to the fused_experts_output. - topk_ids: The topk_ids. - apply_router_weight_on_input: When False, apply the weights to fused_expert_output. - weight_and_reduce_impl: An optional TopKWeightAndReduce implementation.

finalize_async(output, fused_expert_output, topk_weights, topk_ids, apply_router_weight_on_input, weight_and_reduce_impl)

Perform any combine plus apply weights and perform a reduction on the fused experts output but do not wait for results from other workers. - output: The output tensor, written in place. Must be (M, K) shape. - fused_expert_output: The unweighted, unreduced output of the fused experts, it will have (M, topk, K) shape. - topk_weights: The weights to be applied to the fused_experts_output. - topk_ids: The topk_ids. - apply_router_weight_on_input: When False, apply the weights to fused_expert_output. - weight_and_reduce_impl: An optional TopKWeightAndReduce implementation.

Returns a callback or a hook callback pair that when invoked waits for results from other workers and has the same return signature as finalize, if a hook is returned this is more lightweight check that the recv is complete without doing extra work (used by DBO, will be refactored in the very near future)

ret = obj.finalize_async(output, ...) ... output not valid yet ... if isinstance(ret, tuple): hook, receiver = ret hook() receiver() ... output valid here ...

is equivalent to:

obj.finalize(output, ...)

prepare(a1, topk_weights, topk_ids, num_experts, expert_map, apply_router_weight_on_input, quant_config, defer_input_quant) abstractmethod

Perform any quantization (and/or) dispatching needed for this kernel. - a1: The (unquantized) input to the MoE layer. - topk_ids: The topk ids. - topk_weights: The topk weights. - num_experts: The total number of experts in the global expert space. - expert_map: A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard. - apply_router_weight_on_input: When True, apply the weights to the activations, before quantization + dispatching. - quant_config: Quantization info provided by the fused experts. - defer_input_quant: Runtime parameter indicating whether or not to defer input quantization to the FusedMoEExpertsModular in cases where the compute kernel expects unquantized inputs

Returns a tuple of: - quantized + dispatched a. - Optional quantized + dispatched a1_scales. - Optional ExpertTokensMetadata containing gpu/cpu tensors as big as the number of local experts with the information about the number of tokens assigned to each local expert. - Optional dispatched expert topk IDs - Optional dispatched expert topk weight

prepare_async(a1, topk_weights, topk_ids, num_experts, expert_map, apply_router_weight_on_input, quant_config, defer_input_quant)

Perform any quantization (and/or) dispatching needed for this kernel but do not wait for results from other workers. - a1: The (unquantized) input to the MoE layer. - a1_scale: Optional scales for a1 - a2_scale: Optional scales for the second MoE gemm. Required to make sure the quantization is consistent for both gemms. - topk_ids: The topk ids. - topk_weights: The topk weights. - num_experts: The total number of experts in the global expert space. - expert_map: A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard. - apply_router_weight_on_input: When True, apply the weights to the activations, before quantization + dispatching. - defer_input_quant: Runtime parameter indicating whether or not to defer input quantization to the FusedMoEExpertsModular in cases where the compute kernel expects unquantized inputs

Returns a callback or a hook callback pair that when invoked waits for results from other workers and has the same return signature as prepare, if a hook is returned this is more lightweight check that the recv is complete without doing extra work (used by DBO, will be refactored in the very near future)

e.g.

ret = obj.prepare_async(...)

if isinstance(ret, tuple): hook, receiver = ret hook()

if hook is not None: a, a_scales, expert_meta, topk_ids, topk_weights = receiver()

is equivalent to:

a, a_scales, expert_meta, topk_ids, topk_weights = obj.prepare(...)

FusedMoEPrepareAndFinalizeMonolithic

Bases: FusedMoEPrepareAndFinalize

An abstract base class for the [Quantize-Prepare] and [Finalize] steps described above for the monolithic case.

Methods:

  • finalize –

    Optional method for subclasses compatible with monolithic

  • prepare –

    Optional method for subclasses compatible with monolithic

  • prepare_routed –

    Like prepare, but dispatch vLLM's routing instead of logits.

  • supports_precomputed_routing –

    Whether prepare_routed is implemented.

finalize(fused_expert_output) abstractmethod

Optional method for subclasses compatible with monolithic FusedMoEExpertsModular kernels.

Perform any combine plus apply weights and perform a reduction on the fused experts output. - fused_expert_output: The unweighted, unreduced output of the fused experts, it will have (M, topk, K) shape.

prepare(a1, router_logits, quant_config, defer_input_quant=False, a1_scale=None) abstractmethod

Optional method for subclasses compatible with monolithic FusedMoEExpertsModular kernels.

Perform any quantization (and/or) dispatching needed for this kernel. - a1: The (unquantized) input to the MoE layer. - quant_config: Quantization info provided by the fused experts. - defer_input_quant: Runtime parameter indicating whether or not to defer input quantization to the FusedMoEExpertsModular - a1_scale: The scales of a1 when the caller already quantized it.

Returns a tuple of: - quantized + dispatched a. - Optional quantized + dispatched a1_scales.

prepare_routed(a1, topk_weights, topk_ids, quant_config, defer_input_quant=False)

Like prepare, but dispatch vLLM's routing instead of logits.

Returns the quantized and dispatched (a1q, a1q_scale, topk_weights, topk_ids).

supports_precomputed_routing()

Whether prepare_routed is implemented.

RouterWeightApplication

Bases: Enum

Stage applying per-token topk weights for input-side router weighting.

RoutedScaleMode separately controls the layer's routed_scaling_factor.

TopKWeightAndReduce

Bases: ABC

An abstract base class for weight application and reduction implementations.

Methods:

  • apply –

    Apply topk_weights to the fused_experts_outputs and/or reduce.

apply(output, fused_expert_output, topk_weights, topk_ids, apply_router_weight_on_input) abstractmethod

Apply topk_weights to the fused_experts_outputs and/or reduce. If an output tensor is not passed, it will be created in the function.