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
chenpangpang
transformers
Commits
9dc8fb2f
Unverified
Commit
9dc8fb2f
authored
Jan 11, 2022
by
Sylvain Gugger
Committed by
GitHub
Jan 11, 2022
Browse files
Add test to check reported training loss (#15096)
* Add test * Add tests for the reported train loss
parent
b67fd797
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
tests/test_trainer.py
tests/test_trainer.py
+21
-0
No files found.
tests/test_trainer.py
View file @
9dc8fb2f
...
@@ -444,6 +444,27 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
...
@@ -444,6 +444,27 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
trainer
.
train
()
trainer
.
train
()
self
.
check_trained_model
(
trainer
.
model
)
self
.
check_trained_model
(
trainer
.
model
)
def
test_training_loss
(
self
):
n_gpus
=
max
(
1
,
get_gpu_count
())
# With even logs
trainer
=
get_regression_trainer
(
logging_steps
=
64
/
(
8
*
n_gpus
))
trainer
.
train
()
log_history
=
trainer
.
state
.
log_history
losses
=
[
log
[
"loss"
]
for
log
in
log_history
if
"loss"
in
log
]
train_loss
=
log_history
[
-
1
][
"train_loss"
]
self
.
assertAlmostEqual
(
sum
(
losses
)
/
len
(
losses
),
train_loss
,
places
=
4
)
# With uneven logs
trainer
=
get_regression_trainer
(
logging_steps
=
5
)
trainer
.
train
()
log_history
=
trainer
.
state
.
log_history
# Training loss should be the same as before
new_train_loss
=
log_history
[
-
1
][
"train_loss"
]
self
.
assertAlmostEqual
(
train_loss
,
new_train_loss
,
places
=
4
)
def
test_custom_optimizer
(
self
):
def
test_custom_optimizer
(
self
):
train_dataset
=
RegressionDataset
()
train_dataset
=
RegressionDataset
()
args
=
TrainingArguments
(
"./regression"
)
args
=
TrainingArguments
(
"./regression"
)
...
...
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