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

Maintain fp32 for optimizer state when offloading is enabled #1223

Merged
merged 1 commit into from
Feb 6, 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
4 changes: 0 additions & 4 deletions MaxText/max_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def cast_dtype_from_to(nest, src, dst):
return jax.tree_util.tree_map(lambda t: t.astype(dst) if t.dtype == src else t, nest)


def cast_to_bf16(params):
return cast_dtype_from_to(params, np.float32, jnp.bfloat16)


def find_nans_and_infs(pytree):
def finder(x):
return jnp.any(jnp.isinf(x) | jnp.isnan(x))
Expand Down
2 changes: 0 additions & 2 deletions MaxText/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,9 @@ def reshape_to_microbatch_accumulations(batch_arr):
else:
if config.optimizer_memory_host_offload:
cast_params = jax.device_put(state.params, max_utils.with_memory_kind(state_mesh_shardings.params, "device"))
cast_params = max_utils.cast_to_bf16(cast_params)
state = state.replace(params=cast_params)
if config.use_dpo:
reference_params = jax.device_put(reference_params, max_utils.with_memory_kind(reference_params_sharding, "device"))
reference_params = max_utils.cast_to_bf16(reference_params)
extra_dpo_args = [reference_params]
grad_func = jax.value_and_grad(_loss_fn, argnums=4, has_aux=True)
(loss, aux), raw_grads = grad_func(model, config, data, dropout_rng, state.params, *extra_dpo_args, is_train=True)
Expand Down
Loading