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 class

RowParallelLinear

RowParallelLinear​

class max.nn.common_layers.linear.RowParallelLinear(*args, tp_axis=None, **kwargs)

source

Bases: Linear

A linear layer whose weight is sharded across its input features.

The constructor shards the layer’s weight the way row_parallel() does, along tp_axis (by default TP). On a mesh with no such axis, the weight stays replicated.

Build a sharded layer on a (dp, tp) mesh:

from max.driver import CPU
from max.nn.common_layers.linear import RowParallelLinear
from max.nn.common_layers.mesh_axis import DP, TP
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):
    sharded = RowParallelLinear(8, 8, bias=False)

Constructs a linear layer and shards its weight.

Parameters:

  • *args – Positional arguments passed to Linear.
  • tp_axis (str | None) – The name of the mesh axis to shard along. Defaults to TP.
  • **kwargs – Keyword arguments passed to Linear.