Skip to content
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

Neuron support in Axlearn #566

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 axlearn/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ def create_device_mesh(
# Check if the devices are part of a multi-granule configuration.
# <https://github.com/google/jax/blob/b81b79c1b0d2ec/jax/experimental/mesh_utils.py#L313>
device_platform = devices[0].platform
attr = "process_index" if device_platform != "tpu" else "slice_index"
attr = "process_index" if device_platform == "gpu" else "slice_index"
is_multi_granule_env = hasattr(devices[0], attr)
if not all(el.platform == device_platform for el in devices):
raise NotImplementedError(f"Not all devices had platform: {device_platform}.")
Expand All @@ -1193,6 +1193,10 @@ def create_device_mesh(
logging.warning("Falling back to ICI-only mesh on GPU, performance may be reduced.")
return build_standard_mesh(mesh_shape, devices=devices)

# Neuron also only uses standard mesh
if device_platform == "neuron":
return build_standard_mesh(mesh_shape, devices=devices)

# We only break the first device axis (the least communication intensive) across granules.
assert (
ici_mesh_shape[0] % num_granules == 0
Expand Down
9 changes: 8 additions & 1 deletion axlearn/experiments/text/gpt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import math
from typing import Dict, List, Optional, Sequence, Tuple, Union

import jax
import jax.numpy as jnp
import numpy as np
import tensorflow as tf
from jax.sharding import PartitionSpec

Expand Down Expand Up @@ -267,12 +269,17 @@ def model_config(
batch_axis_names=batch_axis_names,
seq_axis_names="seq",
)

device_platform = np.asarray(jax.devices())[0].platform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jax.devices() during config building may be an unexpected dependency on global state -- should we take a platform arg or similar?

Copy link
Author

@apoorvtintin apoorvtintin Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change it, but I followed the pattern already used here

devices = jax.devices()

Please let me know if the platform flag is necessary, I can add it. Thanks!

# Trainium will have FSDP support soon, for now use Zero 3.
fsdp_axis_names = ("expert", "fsdp", "seq") if device_platform != "neuron" else ("data")

cfg.dtype = jnp.float32
# Shard some FFN and attention weights over multiple axes.
set_double_shard_weights_config(
cfg.decoder.transformer.layer,
batch_axis_names=batch_axis_names,
fsdp_axis_names=("expert", "fsdp", "seq"),
fsdp_axis_names=fsdp_axis_names,
tp_axis_names="model",
seq_axis_names=("seq",),
)
Expand Down
5 changes: 4 additions & 1 deletion axlearn/experiments/text/gpt/fuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def get_trainer_kwargs(
num_kv_heads = 8

rope_theta = ROPE_THETA[version]

# dict() is more readable here.
# pylint: disable=use-dict-literal
if model_size == "test":
Expand Down Expand Up @@ -167,6 +166,10 @@ def get_trainer_kwargs(
"gpu-(p5.48xlarge|p4de.24xlarge)-(256|512|1024)",
mesh_shape_from_axes(data=-1, fsdp=8),
),
(
"neuron-(trn1.32xlarge|trn1n.32xlarge)-(32|64|256|512|1024|2048)",
mesh_shape_from_axes(data=-1, model=8),
),
),
)
elif model_size == "70B":
Expand Down