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

Expts #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Expts #583

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
41 changes: 41 additions & 0 deletions init2winit/training_metrics_grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
'enable_semip_grad_normsq': False,
'enable_ema': False,
'optstate_sumsq_fields': [],
'optstate_sumsq_param_wise_fields': [],
'optstate_sum_fields': [],
'optstate_sum_param_wise_fields': [],
'enable_grafting_norms': False,
})

Expand Down Expand Up @@ -183,11 +185,21 @@ def init_fn(params, batch_stats):
field_name: jnp.zeros(num_train_steps)
for field_name in config['optstate_sumsq_fields']
}
if config['optstate_sumsq_param_wise_fields']:
metrics_state['optstate_sumsq_param_wise'] = {
field_name: jax.tree_map(lambda x: jnp.zeros(num_train_steps), params)
for field_name in config['optstate_sumsq_param_wise_fields']
}
if config['optstate_sum_fields']:
metrics_state['optstate_sum'] = {
field_name: jnp.zeros(num_train_steps)
for field_name in config['optstate_sum_fields']
}
if config['optstate_sum_param_wise_fields']:
metrics_state['optstate_sum_param_wise'] = {
field_name: jax.tree_map(lambda x: jnp.zeros(num_train_steps), params)
for field_name in config['optstate_sum_param_wise_fields']
}
if config['enable_preconditioner_normsq']:
metrics_state['preconditioner_normsq'] = jnp.zeros(num_train_steps)
if config['enable_semip_grad_normsq']:
Expand Down Expand Up @@ -275,6 +287,21 @@ def update_fn(metrics_state, step, train_cost, grad, old_params, new_params,
field_normsq = total_tree_norm_sql2(field)
next_metrics_state['optstate_sumsq'][field_name] = metrics_state[
'optstate_sumsq'][field_name].at[step].set(field_normsq)
if config['optstate_sumsq_param_wise_fields']:
next_metrics_state['optstate_sumsq_param_wise'] = {}
for field_name in config['optstate_sumsq_param_wise_fields']:
field = optimizer_utils.extract_field(optimizer_state, field_name)
if field is None:
raise ValueError('optimizer state has no field {}'.format(field_name))
field_normsq = jax.tree_map(_compute_leaf_norms, field)
field_normsqs = jax.tree_map(jnp.square, field_normsq)
next_metrics_state['optstate_sumsq_param_wise'][field_name] = (
_set_pytree_idx(
metrics_state['optstate_sumsq_param_wise'][field_name],
field_normsqs,
step,
)
)
if config['optstate_sum_fields']:
next_metrics_state['optstate_sum'] = {}
for field_name in config['optstate_sum_fields']:
Expand All @@ -284,6 +311,20 @@ def update_fn(metrics_state, step, train_cost, grad, old_params, new_params,
field_normsq = total_tree_sum(field)
next_metrics_state['optstate_sum'][field_name] = metrics_state[
'optstate_sum'][field_name].at[step].set(field_normsq)
if config['optstate_sum_param_wise_fields']:
next_metrics_state['optstate_sum_param_wise'] = {}
for field_name in config['optstate_sum_param_wise_fields']:
field = optimizer_utils.extract_field(optimizer_state, field_name)
if field is None:
raise ValueError('optimizer state has no field {}'.format(field_name))
field_sums = jax.tree_map(jnp.sum, field)
next_metrics_state['optstate_sum_param_wise'][field_name] = (
_set_pytree_idx(
metrics_state['optstate_sum_param_wise'][field_name],
field_sums,
step,
)
)
if (config['enable_preconditioner_normsq'] or
config['enable_semip_grad_normsq']):
preconditioner = freeze(
Expand Down