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
70710529
Unverified
Commit
70710529
authored
Sep 08, 2021
by
Matt
Committed by
GitHub
Sep 08, 2021
Browse files
Fix Tensorflow T5 with int64 input (#13479)
* Fix Tensorflow T5 with int64 input * Style pass
parent
361b6df3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
src/transformers/models/t5/modeling_tf_t5.py
src/transformers/models/t5/modeling_tf_t5.py
+7
-2
No files found.
src/transformers/models/t5/modeling_tf_t5.py
View file @
70710529
...
...
@@ -874,16 +874,21 @@ class TFT5PreTrainedModel(TFPreTrainedModel):
),
"self.model.config.decoder_start_token_id has to be defined. In TF T5 it is usually set to the pad_token_id. See T5 docs for more information"
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
cast
(
start_tokens
,
input_ids
.
dtype
)
# Ensure compatible dtypes for concatenation
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
assert
pad_token_id
is
not
None
,
"self.model.config.pad_token_id has to be defined."
# replace possible -100 values in labels by `pad_token_id`
shifted_input_ids
=
tf
.
where
(
shifted_input_ids
==
-
100
,
tf
.
fill
(
shape_list
(
shifted_input_ids
),
pad_token_id
),
shifted_input_ids
shifted_input_ids
==
-
100
,
tf
.
cast
(
tf
.
fill
(
shape_list
(
shifted_input_ids
),
pad_token_id
),
shifted_input_ids
.
dtype
),
shifted_input_ids
,
)
# "Verify that `labels` has only positive values and -100"
assert_gte0
=
tf
.
debugging
.
assert_greater_equal
(
shifted_input_ids
,
tf
.
constant
(
0
))
assert_gte0
=
tf
.
debugging
.
assert_greater_equal
(
shifted_input_ids
,
tf
.
constant
(
0
,
dtype
=
shifted_input_ids
.
dtype
)
)
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
...
...
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