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
col_parallel
col_parallel()
max.nn.common_layers.linear.col_parallel(layer, tp_axis=None)
Shards a linear layer’s weight across its output features.
Each device along tp_axis holds the weight rows for the output
features it computes, so the weight’s first dimension is sharded and
its second is replicated. The layer’s bias is sharded the same way
when the layer has one. On a mesh with no tp_axis axis, the
parameters stay replicated.
Shard a linear layer’s weight on a (dp, tp) mesh:
from max.driver import CPU
from max.nn.common_layers.linear import col_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=True)
col_parallel(layer)