Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
2e07180c
Unverified
Commit
2e07180c
authored
Dec 16, 2021
by
Matt
Committed by
GitHub
Dec 16, 2021
Browse files
Train step fix (#14796)
* Fix for TF train step when no "labels" key in input * make style
parent
465a8b8d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
0 deletions
+3
-0
src/transformers/modeling_tf_utils.py
src/transformers/modeling_tf_utils.py
+3
-0
No files found.
src/transformers/modeling_tf_utils.py
View file @
2e07180c
...
@@ -870,6 +870,9 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu
...
@@ -870,6 +870,9 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin, Pu
# the input dict (and loss is computed internally)
# the input dict (and loss is computed internally)
if
y
is
None
and
"labels"
in
x
:
if
y
is
None
and
"labels"
in
x
:
y
=
x
[
"labels"
]
# Stops confusion with metric computations
y
=
x
[
"labels"
]
# Stops confusion with metric computations
elif
y
is
None
and
"input_ids"
in
x
:
# Just make any kind of dummy array to make loss work
y
=
tf
.
zeros
(
tf
.
shape
(
x
[
"input_ids"
])[
0
],
dtype
=
tf
.
int64
)
# Run forward pass.
# Run forward pass.
with
tf
.
GradientTape
()
as
tape
:
with
tf
.
GradientTape
()
as
tape
:
y_pred
=
self
(
x
,
training
=
True
)
y_pred
=
self
(
x
,
training
=
True
)
...
...
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