IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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)

source

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)

Parameters:

  • layer (_LinearLayer) – The linear layer to shard.
  • tp_axis (str | None) – The name of the mesh axis to shard along. Defaults to TP.

Returns:

The same layer, with its parameters resharded.

Return type:

_LinearLayer