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
12f0d7e8
Unverified
Commit
12f0d7e8
authored
Jan 20, 2021
by
Julien Plu
Committed by
GitHub
Jan 20, 2021
Browse files
Fix label datatype in TF Trainer (#9616)
* Fix label datatype * Apply style
parent
76f36e18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
src/transformers/trainer_tf.py
src/transformers/trainer_tf.py
+23
-4
No files found.
src/transformers/trainer_tf.py
View file @
12f0d7e8
...
@@ -638,7 +638,15 @@ class TFTrainer:
...
@@ -638,7 +638,15 @@ class TFTrainer:
reduced_features
=
{
reduced_features
=
{
k
:
ft
[:
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
]
for
k
,
ft
in
features
.
items
()
k
:
ft
[:
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
]
for
k
,
ft
in
features
.
items
()
}
}
reduced_labels
=
labels
[:
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
]
if
tf
.
is_tensor
(
labels
):
reduced_labels
=
labels
[:
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
]
elif
isinstance
(
labels
,
dict
):
reduced_labels
=
{
k
:
lbl
[:
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
]
for
k
,
lbl
in
labels
.
items
()
}
else
:
raise
ValueError
(
"The labels must be either a tf.Tensor or a dict."
)
self
.
training_step
(
reduced_features
,
reduced_labels
,
nb_instances_in_global_batch
)
self
.
training_step
(
reduced_features
,
reduced_labels
,
nb_instances_in_global_batch
)
...
@@ -650,9 +658,20 @@ class TFTrainer:
...
@@ -650,9 +658,20 @@ class TFTrainer:
for
k
,
ft
in
features
.
items
()
for
k
,
ft
in
features
.
items
()
}
}
labels
=
tf
.
concat
(
if
tf
.
is_tensor
(
labels
):
[
labels
[
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
:],
reduced_labels
],
axis
=
0
labels
=
tf
.
concat
(
)
[
labels
[
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
:],
reduced_labels
],
axis
=
0
)
elif
isinstance
(
labels
,
dict
):
labels
=
{
k
:
tf
.
concat
(
[
lbl
[
self
.
args
.
train_batch_size
//
self
.
args
.
n_replicas
:],
reduced_labels
[
k
]],
axis
=
0
,
)
for
k
,
lbl
in
labels
.
items
()
}
else
:
raise
ValueError
(
"The labels must be either a tf.Tensor or a dict."
)
gradients
=
self
.
gradient_accumulator
.
gradients
gradients
=
self
.
gradient_accumulator
.
gradients
gradients
=
[
gradients
=
[
...
...
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