In a standard MoE layer every token is copied to each of its experts with its full hidden state of numbers. A latent MoE projects the token down to a smaller width before dispatch, runs every expert in that latent space, and projects the combined result back up to , optionally after an RMSNorm. Implement the forward pass and the sizing rule that says what the smaller copies buy.
latent_moe_forward(x, W_down, W_router, W1, W2, W_up, top_k, norm_gain=None, eps=1e-6)
x is (T, d), W_down is (d, l), W_router is (d, N), W1 is (N, l, h), W2 is (N, h, l), W_up is (l, d).top_k most probable experts (ties go to the lower expert index), and the selected probabilities are renormalised to sum to 1; call them .norm_gain (a length-l vector) is given, apply RMSNorm before the up-projection: , the mean taken over the l features of each token. If it is None, skip the norm.(T, d) array.latent_budget(d, l, n_experts, top_k, h, bytes_per_value=2)
Take a standard layer with n_experts experts of hidden width h at top_k, each expert being two matrices ( and ). With (assume it is a whole number), its latent counterpart has experts of the same width h and selects , with expert matrices and . Return a dict with the keys, in this order:
"alpha": as an int."latent_experts", "latent_top_k": ints."dispatch_bytes_standard", "dispatch_bytes_latent": bytes one token sends at dispatch (one copy per selected expert)."expert_params_standard", "expert_params_latent": weights in all experts of the layer."active_expert_params_standard", "active_expert_params_latent": expert weights one token uses."projection_params": weights in the two latent projections."log10_combinations_standard", "log10_combinations_latent": for each layer, rounded to 2 decimals.