Skip to content

Support subslice shapes in maxtext when using Pathways #1854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion MaxText/configs/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,8 @@ projector_output_dim_for_vit: 4096
rope_theta_for_vit: 10000
vision_output_dim_for_vit: 4096
pixel_shuffle_ratio_for_vit: 0.5
projector_dropout_for_vit: 0.0
projector_dropout_for_vit: 0.0

# Subslice shape in the form of "x,y,z" when using pathways (single controller).
# Example: "8,8" to use a 8x8 subgrid (64 chips) of a full pod (16x16) of trillium.
subslice_shape: ""
25 changes: 25 additions & 0 deletions MaxText/maxtext_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,31 @@ def create_device_mesh(config, devices=None):
"""Creates a device mesh with each slice in its own data parallel group. If there is only one slice, uses two replicas"""
if devices is None:
devices = jax.devices()
if (
config.subslice_shape is not None
and config.enable_single_controller
and config.num_slices == 1
):
max_logging.log(
f"Trying to create a subslice with shape: {config.subslice_shape}"
)
subslice_shape = tuple(int(x) for x in config.subslice_shape.split(","))
device_coords = [device.coords for device in devices]
device_coords_np = np.array(device_coords)

# Find the minimum coordinates to start the subslice
min_coords = device_coords_np.min(axis=0)

subslice_devices = []
for device in devices:
coords = device.coords
if all(
min_coords[i] <= coords[i] < min_coords[i] + subslice_shape[i]
for i in range(len(subslice_shape))
):
subslice_devices.append(device)
devices = subslice_devices

num_devices = len(devices)
num_slices = 1 if config.inference_benchmark_test else config.num_slices
num_devices_per_slice = num_devices // num_slices
Expand Down
4 changes: 4 additions & 0 deletions MaxText/pyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# pylint: disable=missing-module-docstring, bare-except, consider-using-generator, missing-function-docstring
from collections import OrderedDict
from typing import Any, Union
from math import prod
import math
import os
import sys
Expand Down Expand Up @@ -1014,6 +1015,9 @@ def get_num_target_devices(raw_keys):
compile_topology = accelerator_to_spec_map.get_system_characteristics(raw_keys["compile_topology"])
devices_per_slice = compile_topology.devices_per_slice
return int(devices_per_slice * raw_keys["compile_topology_num_slices"])
elif raw_keys.get("subslice_shape") and raw_keys.get("enable_single_controller"):
subslice_shape = tuple(int(x) for x in raw_keys["subslice_shape"].split(","))
return prod(subslice_shape)
else:
return len(jax.devices())

Expand Down
Loading