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
row_parallel
row_parallel()
max.nn.common_layers.linear.row_parallel(layer, tp_axis=None)
Shards a linear layer’s weight across its input features.
Each device along tp_axis holds the weight columns for the input
features it multiplies, so the weight’s second dimension is sharded
and its first is replicated. On a mesh with no tp_axis axis, the
weight stays replicated.
Shard a linear layer’s weight on a (dp, tp) mesh:
from max.driver import CPU
from max.nn.common_layers.linear import row_parallel
from max.nn.common_layers.mesh_axis import DP, TP
from max.nn import Linear
from max.tensor import default_device
from max.tensor.sharding import DeviceMesh, Replicated, Sharded
cpu = CPU()
mesh = DeviceMesh(
devices=(cpu, cpu, cpu, cpu),
mesh_shape=(2, 2),
axis_names=(DP, TP),
)
with default_device(mesh):
layer = Linear(8, 8, bias=False)
row_parallel(layer)