Read the equation
Each chosen expert evaluates the same input representation h. Its output vector is multiplied by the associated routing weight, and the selected vectors are added. The implementation groups tokens by expert for efficient evaluation and restores their original order before summing; those data-movement steps preserve this intended mixture formula.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| h | Token representation |
| w_i | Routing weight for selected expert i |
| y | Routed output vector |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.
Original context
Read the surrounding source passage
new_x = torch.empty_like(outs)
new_x[idxs] = outs
final_out = (new_x.view(
*topk_ids.shape, -1).type(topk_weight.dtype).mul_(
topk_weight.unsqueeze(dim=-1)).sum(dim=1).type(new_x.dtype))
return final_outExact original notation
final_out = (new_x.view(
*topk_ids.shape, -1).type(topk_weight.dtype).mul_(
topk_weight.unsqueeze(dim=-1)).sum(dim=1).type(new_x.dtype))Related builds
Sources & provenance
final_out = (new_x.view( *topk_ids.shape, -1).type(topk_weight.dtype).mul_( topk_weight.unsqueeze(dim=-1)).sum(dim=1).type(new_x.dtype))
final_out = ( new_x.view(*topk_ids.shape, -1) .type(topk_weight.dtype) .mul_(topk_weight.unsqueeze(dim=-1)) .sum(dim=1) .type(new_x.dtype) )
final_out = (new_x.view( *topk_ids.shape, -1).type(topk_weight.dtype).mul_( topk_weight.unsqueeze(dim=-1)).sum(dim=1).type(new_x.dtype))
final_out = ( new_x.view(*topk_ids.shape, -1) .type(topk_weight.dtype) .mul_(topk_weight.unsqueeze(dim=-1)) .sum(dim=1) .type(new_x.dtype) )