Class MiniMaxMoE
Routing: scores = sigmoid(x Wg^T); experts are chosen by the top-k of
scores + e_score_correction_bias, but the combine weights are the unbiased
scores, renormalized over the chosen experts and multiplied by
routed_scaling_factor. The router runs in float32.
Routed experts are stored stacked, one tensor per projection (experts_w1,
experts_w3: [local, I, D]; experts_w2: [local, D, I]), so a rank
allocates only the experts it owns and no per-expert modules exist. Under expert parallelism
every rank routes all tokens identically, computes only the tokens assigned to its own
experts, and the partial outputs are summed with an all-reduce; the shared expert is replicated
and added afterwards.
This is the reference (eager) implementation: routing decisions are read back to the host and each active expert runs on its own gathered rows, so it is not CUDA-graph capturable.
-
Field Summary
Fields inherited from class LayerBlock
device, dtype, module -
Constructor Summary
ConstructorsConstructorDescriptionMiniMaxMoE(MiniMaxModelArgs args) Constructor for the unsharded layout.MiniMaxMoE(MiniMaxModelArgs args, MiniMaxShard shard, TensorParallelGroup group) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the first global expert index owned by this rank.expertWeights(int projection) Returns the stacked weight tensor of a projection.Forward propagation (or forward pass) through the layer.intReturns the number of experts owned by this rank.voidsetRouterFp32(Tensor weight, Tensor bias) Installs float32 router parameters so routing is not rounded to the model's compute dtype.Returns the shared expert.Methods inherited from class LayerBlock
add, add, device, dtype, eval, isTraining, load, loadStateDict, module, save, setRequiresGrad, to, to, toString, train
-
Constructor Details
-
MiniMaxMoE
Constructor for the unsharded layout.- Parameters:
args- model hyperparameters.
-
MiniMaxMoE
Constructor.- Parameters:
args- model hyperparameters.shard- this rank's slice of the routed experts; their weights are allocated on its device.group- all-reduce group forshard.size() > 1, otherwisenull.
-
-
Method Details
-
setRouterFp32
-
expertStart
public int expertStart()Returns the first global expert index owned by this rank.- Returns:
- first local expert.
-
localExperts
public int localExperts()Returns the number of experts owned by this rank.- Returns:
- local expert count.
-
expertWeights
Returns the stacked weight tensor of a projection.- Parameters:
projection-1(gate),2(down) or3(up).- Returns:
- the stacked tensor
[localExperts, ...].
-
forward
-