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
699541c4
Unverified
Commit
699541c4
authored
Jun 10, 2020
by
Setu Shah
Committed by
GitHub
Jun 11, 2020
Browse files
TFTrainer: Add dataloader_drop_last (#4925)
parent
e80d6c68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
src/transformers/trainer.py
src/transformers/trainer.py
+1
-0
src/transformers/trainer_tf.py
src/transformers/trainer_tf.py
+7
-3
No files found.
src/transformers/trainer.py
View file @
699541c4
...
...
@@ -286,6 +286,7 @@ class Trainer:
sampler
=
sampler
,
batch_size
=
self
.
args
.
eval_batch_size
,
collate_fn
=
self
.
data_collator
.
collate_batch
,
drop_last
=
self
.
args
.
dataloader_drop_last
,
)
return
data_loader
...
...
src/transformers/trainer_tf.py
View file @
699541c4
...
...
@@ -68,7 +68,7 @@ class TFTrainer:
ds
=
(
self
.
train_dataset
.
cache
()
.
shuffle
(
self
.
num_train_examples
)
.
batch
(
self
.
args
.
train_batch_size
)
.
batch
(
self
.
args
.
train_batch_size
,
drop_remainder
=
self
.
args
.
dataloader_drop_last
)
.
prefetch
(
tf
.
data
.
experimental
.
AUTOTUNE
)
)
...
...
@@ -82,12 +82,16 @@ class TFTrainer:
raise
ValueError
(
"Trainer: evaluation requires an eval_dataset."
)
eval_dataset
=
eval_dataset
if
eval_dataset
is
not
None
else
self
.
eval_dataset
ds
=
eval_dataset
.
cache
().
batch
(
self
.
args
.
eval_batch_size
).
prefetch
(
tf
.
data
.
experimental
.
AUTOTUNE
)
ds
=
(
eval_dataset
.
cache
()
.
batch
(
self
.
args
.
eval_batch_size
,
drop_remainder
=
self
.
args
.
dataloader_drop_last
)
.
prefetch
(
tf
.
data
.
experimental
.
AUTOTUNE
)
)
return
self
.
args
.
strategy
.
experimental_distribute_dataset
(
ds
)
def
get_test_tfdataset
(
self
,
test_dataset
:
tf
.
data
.
Dataset
)
->
tf
.
data
.
Dataset
:
ds
=
test_dataset
.
batch
(
self
.
args
.
eval_batch_size
)
ds
=
test_dataset
.
batch
(
self
.
args
.
eval_batch_size
,
drop_remainder
=
self
.
args
.
dataloader_drop_last
)
return
self
.
args
.
strategy
.
experimental_distribute_dataset
(
ds
)
...
...
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