Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
d022a749
Commit
d022a749
authored
Nov 11, 2021
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Nov 11, 2021
Browse files
Improve test coverage. Add tests for Recovery module.
PiperOrigin-RevId: 409277297
parent
4b5560cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
official/core/base_trainer.py
official/core/base_trainer.py
+2
-2
official/core/base_trainer_test.py
official/core/base_trainer_test.py
+24
-0
No files found.
official/core/base_trainer.py
View file @
d022a749
...
...
@@ -75,8 +75,8 @@ class Recovery:
self
.
recover_counter
+=
1
if
self
.
recover_counter
>
self
.
recovery_max_trials
:
raise
RuntimeError
(
"The loss value is NaN after training loop and
it happens %d times."
%
self
.
recover_counter
)
"The loss value is NaN
or out of range
after training loop and
"
f
"this happens
{
self
.
recover_counter
}
times."
)
# Loads the previous good checkpoint.
checkpoint_path
=
self
.
checkpoint_manager
.
restore_or_initialize
()
logging
.
warning
(
...
...
official/core/base_trainer_test.py
View file @
d022a749
...
...
@@ -150,6 +150,30 @@ class MockAsyncTrainer(trainer_lib._AsyncTrainer):
return
self
.
eval_global_step
.
numpy
()
class
RecoveryTest
(
tf
.
test
.
TestCase
):
def
test_recovery_module
(
self
):
ckpt
=
tf
.
train
.
Checkpoint
(
v
=
tf
.
Variable
(
1
,
dtype
=
tf
.
int32
))
model_dir
=
self
.
get_temp_dir
()
manager
=
tf
.
train
.
CheckpointManager
(
ckpt
,
model_dir
,
max_to_keep
=
1
)
recovery_module
=
trainer_lib
.
Recovery
(
loss_upper_bound
=
1.0
,
checkpoint_manager
=
manager
,
recovery_begin_steps
=
1
,
recovery_max_trials
=
1
)
self
.
assertFalse
(
recovery_module
.
should_recover
(
1.1
,
0
))
self
.
assertFalse
(
recovery_module
.
should_recover
(
0.1
,
1
))
self
.
assertTrue
(
recovery_module
.
should_recover
(
1.1
,
2
))
# First triggers the recovery once.
recovery_module
.
maybe_recover
(
1.1
,
10
)
# Second time, it raises.
with
self
.
assertRaisesRegex
(
RuntimeError
,
'The loss value is NaN .*'
):
recovery_module
.
maybe_recover
(
1.1
,
10
)
class
TrainerTest
(
tf
.
test
.
TestCase
,
parameterized
.
TestCase
):
def
setUp
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment