Skip to content

Commit 804ff4e

Browse files
Merge pull request #2534 from AI-Hypercomputer:chengnuojin-zero1-fix
PiperOrigin-RevId: 823060372
2 parents 5b01873 + 23147c9 commit 804ff4e

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/MaxText/configs/base.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ ici_autoregressive_parallelism: 1
466466
ici_pipeline_parallelism: 1
467467
ici_expert_parallelism: 1
468468

469+
# Enable ZeRO-1 optimizer sharding over data axis
470+
shard_optimizer_over_data: False
471+
469472
# The number of TPU slices is automatically determined, you should not set this explicitly. For ahead of time compilation,
470473
# you should set compile_toplogy_num_slices, which will in turn set this value. For non-TPU environments this is set to 1.
471474
num_slices: -1
@@ -859,7 +862,6 @@ subslice_shape: ""
859862

860863
# NNX
861864
enable_nnx: false
862-
shard_optimizer_over_data: False
863865

864866
################################## Qwen3-Next Specific Configs ##################################
865867
# Kernel size for the 1D convolution in the Gated Delta Net

src/MaxText/pyconfig.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ def validate_keys(keys):
261261
"For Qwen3-Next, sparse_matmul must be False for now. The dense path has been verified against reference."
262262
)
263263

264+
if keys["shard_optimizer_over_data"]:
265+
validate_optimizer_sharding_over_data(keys)
266+
264267

265268
def validate_tokenizer(keys):
266269
assert keys[
@@ -1119,6 +1122,15 @@ def validate_ragged_dot(raw_keys):
11191122
max_logging.log(f"JAX config {config_flag} not found, possibly due to old JAX version.")
11201123

11211124

1125+
def validate_optimizer_sharding_over_data(raw_keys):
1126+
zero1_supported_opt_types = ("adamw", "adam_pax")
1127+
if raw_keys["opt_type"] not in zero1_supported_opt_types:
1128+
raise ValueError(
1129+
f"Optimizer type {raw_keys["opt_type"]} is not supported for optimizer sharding.\n"
1130+
f"Please use an optimizer from this list: {zero1_supported_opt_types}."
1131+
)
1132+
1133+
11221134
def create_new_logical_axis_rules(old_logical_axis_rules, new_logical_axis_rules):
11231135
new_logical_axis = set()
11241136
replacements = []

0 commit comments

Comments
 (0)