Skip to content

Commit cff6edc

Browse files
Merge pull request #2516 from hx89:hx/zero1_ga_fix
PiperOrigin-RevId: 821792784
2 parents f486fa9 + beac7ed commit cff6edc

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/MaxText/train.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ def train_loop(config, recorder, state=None):
413413

414414
with mesh, nn_partitioning.axis_rules(config.logical_axis_rules):
415415
shaped_batch = maxtext_utils.get_shaped_batch(config)
416-
state = jax.lax.with_sharding_constraint(state, state_mesh_shardings)
416+
if config.shard_optimizer_over_data:
417+
state = jax.lax.with_sharding_constraint(state, state_mesh_shardings)
417418
compiled = p_train_step.lower(state, shaped_batch, init_rng).compile()
418419
compiled_stats = compiled.memory_analysis()
419420
max_utils.print_compiled_memory_stats(compiled_stats)
@@ -437,7 +438,8 @@ def train_loop(config, recorder, state=None):
437438
nextrng = jax.jit(jax.random.fold_in)(init_rng, step)
438439
with maybe_record_goodput(recorder, GoodputEvent.STEP, step):
439440
with mesh, nn_partitioning.axis_rules(config.logical_axis_rules):
440-
state = jax.lax.with_sharding_constraint(state, state_mesh_shardings)
441+
if config.shard_optimizer_over_data:
442+
state = jax.lax.with_sharding_constraint(state, state_mesh_shardings)
441443
state, metrics = p_train_step(state, example_batch, nextrng)
442444

443445
step_time_delta = datetime.datetime.now() - last_step_completion

0 commit comments

Comments
 (0)