This document is relevant for: Inf2, Trn1, Trn2, Trn3

NCC_EVRF009#

Error message: The combined memory needed for the model’s activation tensors exceeds the high-bandwidth memory limit.

To fix this issue, do one or more of these steps:

  1. Decrease the batch size or the sequence length, if possible.

  2. Shard the activations across more NeuronCores with tensor parallelism. With TorchNeuron, use DTensor and the tensor-parallel styles of torch.distributed on the neuron backend.

  3. For training at scale, use TorchTitan Neuron. For inference, use the tensor parallelism of vLLM Neuron.

This example shards two linear layers with tensor parallelism on the neuron backend:

from torch.distributed.device_mesh import init_device_mesh
from torch.distributed.tensor.parallel import (
    ColwiseParallel, RowwiseParallel, parallelize_module,
)

tp_mesh = init_device_mesh("neuron", (world_size,), mesh_dim_names=("tp",))
model = torch.nn.Sequential(
    torch.nn.Linear(16, 32), torch.nn.ReLU(), torch.nn.Linear(32, 16),
).to("neuron")
model = parallelize_module(
    model, tp_mesh, {"0": ColwiseParallel(), "2": RowwiseParallel()},
)

For more information:

This document is relevant for: Inf2, Trn1, Trn2, Trn3