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

Add matrix epsilon diagonal instead of truncating numerical noise. #555

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions init2winit/trainer_lib/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ def train(self):
self._time_at_prev_eval_end = start_time
self._prev_eval_step = self._global_step

if self._global_step in self._checkpoint_steps and jax.process_index() == 0:
self._save(self._checkpoint_dir, max_to_keep=None)

for _ in range(start_step, self._num_train_steps):
with jax.profiler.StepTraceAnnotation('train',
step_num=self._global_step):
Expand All @@ -210,9 +213,6 @@ def train(self):
# directly in the top-level for loop).
batch = next(train_iter)

if (self._global_step in self._checkpoint_steps
and jax.process_index() == 0):
self._save(self._checkpoint_dir, max_to_keep=None)
lr = self._lr_fn(self._global_step)
# It looks like we are reusing an rng key, but we aren't.
# TODO(gdahl): Make it more obvious that passing rng is safe.
Expand All @@ -225,13 +225,26 @@ def train(self):
self._metrics_state, batch, self._global_step, lr, rng,
self._local_device_indices, self._sum_train_cost)
self._global_step += 1

if (
self._global_step in self._checkpoint_steps
and jax.process_index() == 0
):
self._save(self._checkpoint_dir, max_to_keep=None)
lr = self._optimizer_state.hyperparams['learning_rate'][0]
# TODO(gdahl, gilmer): consider moving this test up.
# NB: Since this test is after we increment self._global_step, having 0
# in eval_steps does nothing.
if trainer_utils.should_eval(
self._global_step, self._eval_frequency, self._eval_steps):
report = self._eval(lr, start_step, start_time)
try:
report = self._eval(lr, start_step, start_time)
except utils.TrainingDivergedError as e:
# In case of NaN durin evals, make sure to save the last checkpoint.
checkpoint.wait_for_checkpoint_save()
raise utils.TrainingDivergedError(
f'divergence at step {self._global_step}'
) from e
yield report
if self._check_early_stopping(report):
return
Expand Down