For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python function
moe_forward
moe_forward()
max.nn.common_layers.moe_exchange.moe_forward(mlp, h, *args, **kwargs)
Runs a feed-forward block on h and returns its output placed as h.
The movement follows from how h lies on its mesh and from whether the
block SumsOverDevices:
- Rows held per replica, a per-row block: the block runs on them as they are.
- Rows held per replica, a summing block: the rows are all-gathered, the block runs on the whole batch, and each replica keeps its own rows of the completed output.
- Replicated rows, a per-row block: each device runs an even share of the rows, and the outputs are gathered.
- Replicated rows, a summing block: the block runs and completes its output.
-
Parameters:
-
Returns:
-
The block’s output, with the mapping and shard shapes of
h. -
Raises:
-
- NotImplementedError – If the block sums over devices, or the rows have to move, on a mesh of more than one axis.
- TypeError – If a block that runs per row returns partial sums.
-
Return type: