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
008672e6
Unverified
Commit
008672e6
authored
Mar 18, 2021
by
Sylvain Gugger
Committed by
GitHub
Mar 18, 2021
Browse files
Fix distributed evaluation (#10795)
* Fix distributed evaluation * Use logger
parent
9352b515
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
src/transformers/trainer.py
src/transformers/trainer.py
+8
-3
tests/test_trainer_distributed.py
tests/test_trainer_distributed.py
+5
-0
No files found.
src/transformers/trainer.py
View file @
008672e6
...
...
@@ -690,7 +690,7 @@ class Trainer:
"""
Helper to get number of samples in a :class:`~torch.utils.data.DataLoader` by accessing its dataset.
Will raise an exception if the underlying dataset des
e
not implement method :obj:`__len__`
Will raise an exception if the underlying dataset d
o
es not implement method :obj:`__len__`
"""
return
len
(
dataloader
.
dataset
)
...
...
@@ -1812,8 +1812,13 @@ class Trainer:
eval_losses_gatherer
=
DistributedTensorGatherer
(
world_size
,
num_examples
,
make_multiple_of
=
batch_size
)
if
not
prediction_loss_only
:
preds_gatherer
=
DistributedTensorGatherer
(
world_size
,
num_examples
,
make_multiple_of
=
batch_size
)
labels_gatherer
=
DistributedTensorGatherer
(
world_size
,
num_examples
,
make_multiple_of
=
batch_size
)
# The actual number of eval_sample can be greater than num_examples in distributed settings (when we pass
# a batch size to the sampler)
make_multiple_of
=
None
if
hasattr
(
dataloader
,
"sampler"
)
and
isinstance
(
dataloader
.
sampler
,
SequentialDistributedSampler
):
make_multiple_of
=
dataloader
.
sampler
.
batch_size
preds_gatherer
=
DistributedTensorGatherer
(
world_size
,
num_examples
,
make_multiple_of
=
make_multiple_of
)
labels_gatherer
=
DistributedTensorGatherer
(
world_size
,
num_examples
,
make_multiple_of
=
make_multiple_of
)
model
.
eval
()
...
...
tests/test_trainer_distributed.py
View file @
008672e6
...
...
@@ -97,6 +97,11 @@ if __name__ == "__main__":
def
compute_metrics
(
p
:
EvalPrediction
)
->
Dict
:
sequential
=
list
(
range
(
len
(
dataset
)))
success
=
p
.
predictions
.
tolist
()
==
sequential
and
p
.
label_ids
.
tolist
()
==
sequential
if
not
success
and
training_args
.
local_rank
==
0
:
logger
.
warning
(
"Predictions and/or labels do not match expected results:
\n
- predictions: "
f
"
{
p
.
predictions
.
tolist
()
}
\n
- labels:
{
p
.
label_ids
.
tolist
()
}
\n
- expected:
{
sequential
}
"
)
return
{
"success"
:
success
}
trainer
=
Trainer
(
...
...
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