@@ -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