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
b8385d8a
Unverified
Commit
b8385d8a
authored
Sep 09, 2021
by
Matt
Committed by
GitHub
Sep 09, 2021
Browse files
TF Seq2Seq int dtype fix (#13496)
Fixes problems with passing int64 input to TF Seq2Seq models.
parent
008c2d0b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
6 deletions
+16
-6
src/transformers/models/bart/modeling_tf_bart.py
src/transformers/models/bart/modeling_tf_bart.py
+3
-1
src/transformers/models/blenderbot/modeling_tf_blenderbot.py
src/transformers/models/blenderbot/modeling_tf_blenderbot.py
+3
-1
src/transformers/models/blenderbot_small/modeling_tf_blenderbot_small.py
...s/models/blenderbot_small/modeling_tf_blenderbot_small.py
+3
-1
src/transformers/models/marian/modeling_tf_marian.py
src/transformers/models/marian/modeling_tf_marian.py
+4
-2
src/transformers/models/pegasus/modeling_tf_pegasus.py
src/transformers/models/pegasus/modeling_tf_pegasus.py
+3
-1
No files found.
src/transformers/models/bart/modeling_tf_bart.py
View file @
b8385d8a
...
@@ -61,6 +61,8 @@ LARGE_NEGATIVE = -1e8
...
@@ -61,6 +61,8 @@ LARGE_NEGATIVE = -1e8
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
pad_token_id
=
tf
.
cast
(
pad_token_id
,
input_ids
.
dtype
)
decoder_start_token_id
=
tf
.
cast
(
decoder_start_token_id
,
input_ids
.
dtype
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
# replace possible -100 values in labels by `pad_token_id`
# replace possible -100 values in labels by `pad_token_id`
...
@@ -70,7 +72,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
...
@@ -70,7 +72,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
if
tf
.
executing_eagerly
():
if
tf
.
executing_eagerly
():
# "Verify that `labels` has only positive values and -100"
# "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
=
input_ids
.
dtype
))
# Make sure the assertion op is called by wrapping the result in an identity no-op
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
with
tf
.
control_dependencies
([
assert_gte0
]):
...
...
src/transformers/models/blenderbot/modeling_tf_blenderbot.py
View file @
b8385d8a
...
@@ -64,6 +64,8 @@ LARGE_NEGATIVE = -1e8
...
@@ -64,6 +64,8 @@ LARGE_NEGATIVE = -1e8
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
pad_token_id
=
tf
.
cast
(
pad_token_id
,
input_ids
.
dtype
)
decoder_start_token_id
=
tf
.
cast
(
decoder_start_token_id
,
input_ids
.
dtype
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
# replace possible -100 values in labels by `pad_token_id`
# replace possible -100 values in labels by `pad_token_id`
...
@@ -73,7 +75,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
...
@@ -73,7 +75,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
if
tf
.
executing_eagerly
():
if
tf
.
executing_eagerly
():
# "Verify that `labels` has only positive values and -100"
# "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
=
input_ids
.
dtype
))
# Make sure the assertion op is called by wrapping the result in an identity no-op
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
with
tf
.
control_dependencies
([
assert_gte0
]):
...
...
src/transformers/models/blenderbot_small/modeling_tf_blenderbot_small.py
View file @
b8385d8a
...
@@ -62,6 +62,8 @@ LARGE_NEGATIVE = -1e8
...
@@ -62,6 +62,8 @@ LARGE_NEGATIVE = -1e8
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
pad_token_id
=
tf
.
cast
(
pad_token_id
,
input_ids
.
dtype
)
decoder_start_token_id
=
tf
.
cast
(
decoder_start_token_id
,
input_ids
.
dtype
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
# replace possible -100 values in labels by `pad_token_id`
# replace possible -100 values in labels by `pad_token_id`
...
@@ -71,7 +73,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
...
@@ -71,7 +73,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
if
tf
.
executing_eagerly
():
if
tf
.
executing_eagerly
():
# "Verify that `labels` has only positive values and -100"
# "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
=
input_ids
.
dtype
))
# Make sure the assertion op is called by wrapping the result in an identity no-op
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
with
tf
.
control_dependencies
([
assert_gte0
]):
...
...
src/transformers/models/marian/modeling_tf_marian.py
View file @
b8385d8a
...
@@ -63,6 +63,8 @@ LARGE_NEGATIVE = -1e8
...
@@ -63,6 +63,8 @@ LARGE_NEGATIVE = -1e8
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
pad_token_id
=
tf
.
cast
(
pad_token_id
,
input_ids
.
dtype
)
decoder_start_token_id
=
tf
.
cast
(
decoder_start_token_id
,
input_ids
.
dtype
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
# replace possible -100 values in labels by `pad_token_id`
# replace possible -100 values in labels by `pad_token_id`
...
@@ -72,7 +74,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
...
@@ -72,7 +74,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
if
tf
.
executing_eagerly
():
if
tf
.
executing_eagerly
():
# "Verify that `labels` has only positive values and -100"
# "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
=
input_ids
.
dtype
))
# Make sure the assertion op is called by wrapping the result in an identity no-op
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
with
tf
.
control_dependencies
([
assert_gte0
]):
...
@@ -1407,7 +1409,7 @@ class TFMarianMTModel(TFMarianPreTrainedModel, TFCausalLanguageModelingLoss):
...
@@ -1407,7 +1409,7 @@ class TFMarianMTModel(TFMarianPreTrainedModel, TFCausalLanguageModelingLoss):
if
inputs
[
"labels"
]
is
not
None
:
if
inputs
[
"labels"
]
is
not
None
:
inputs
[
"labels"
]
=
tf
.
where
(
inputs
[
"labels"
]
=
tf
.
where
(
inputs
[
"labels"
]
==
self
.
config
.
pad_token_id
,
inputs
[
"labels"
]
==
self
.
config
.
pad_token_id
,
tf
.
fill
(
shape_list
(
inputs
[
"labels"
]),
-
100
),
tf
.
fill
(
shape_list
(
inputs
[
"labels"
]),
tf
.
cast
(
-
100
,
inputs
[
"labels"
].
dtype
)
),
inputs
[
"labels"
],
inputs
[
"labels"
],
)
)
inputs
[
"use_cache"
]
=
False
inputs
[
"use_cache"
]
=
False
...
...
src/transformers/models/pegasus/modeling_tf_pegasus.py
View file @
b8385d8a
...
@@ -63,6 +63,8 @@ LARGE_NEGATIVE = -1e8
...
@@ -63,6 +63,8 @@ LARGE_NEGATIVE = -1e8
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
# Copied from transformers.models.bart.modeling_tf_bart.shift_tokens_right
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
def
shift_tokens_right
(
input_ids
:
tf
.
Tensor
,
pad_token_id
:
int
,
decoder_start_token_id
:
int
):
pad_token_id
=
tf
.
cast
(
pad_token_id
,
input_ids
.
dtype
)
decoder_start_token_id
=
tf
.
cast
(
decoder_start_token_id
,
input_ids
.
dtype
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
start_tokens
=
tf
.
fill
((
shape_list
(
input_ids
)[
0
],
1
),
decoder_start_token_id
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
shifted_input_ids
=
tf
.
concat
([
start_tokens
,
input_ids
[:,
:
-
1
]],
-
1
)
# replace possible -100 values in labels by `pad_token_id`
# replace possible -100 values in labels by `pad_token_id`
...
@@ -72,7 +74,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
...
@@ -72,7 +74,7 @@ def shift_tokens_right(input_ids: tf.Tensor, pad_token_id: int, decoder_start_to
if
tf
.
executing_eagerly
():
if
tf
.
executing_eagerly
():
# "Verify that `labels` has only positive values and -100"
# "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
=
input_ids
.
dtype
))
# Make sure the assertion op is called by wrapping the result in an identity no-op
# Make sure the assertion op is called by wrapping the result in an identity no-op
with
tf
.
control_dependencies
([
assert_gte0
]):
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