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
f1a6df32
Unverified
Commit
f1a6df32
authored
Sep 09, 2022
by
Ekagra Ranjan
Committed by
GitHub
Sep 09, 2022
Browse files
Generate: Simplify is_pad_token_not_equal_to_eos_token_id (#18933)
parent
85125fcf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
6 deletions
+3
-6
src/transformers/generation_tf_utils.py
src/transformers/generation_tf_utils.py
+1
-3
src/transformers/generation_utils.py
src/transformers/generation_utils.py
+2
-3
No files found.
src/transformers/generation_tf_utils.py
View file @
f1a6df32
...
@@ -1739,9 +1739,7 @@ class TFGenerationMixin:
...
@@ -1739,9 +1739,7 @@ class TFGenerationMixin:
)
->
tf
.
Tensor
:
)
->
tf
.
Tensor
:
is_input_ids
=
len
(
inputs
.
shape
)
==
2
and
inputs
.
dtype
in
(
tf
.
int32
,
tf
.
int64
)
is_input_ids
=
len
(
inputs
.
shape
)
==
2
and
inputs
.
dtype
in
(
tf
.
int32
,
tf
.
int64
)
is_pad_token_in_inputs
=
(
pad_token_id
is
not
None
)
and
tf
.
math
.
reduce_any
(
inputs
==
pad_token_id
)
is_pad_token_in_inputs
=
(
pad_token_id
is
not
None
)
and
tf
.
math
.
reduce_any
(
inputs
==
pad_token_id
)
is_pad_token_not_equal_to_eos_token_id
=
(
eos_token_id
is
None
)
or
(
is_pad_token_not_equal_to_eos_token_id
=
(
eos_token_id
is
None
)
or
(
pad_token_id
!=
eos_token_id
)
(
eos_token_id
is
not
None
)
and
(
pad_token_id
!=
eos_token_id
)
)
# Check if input is input_ids and padded -> only then is attention_mask defined
# Check if input is input_ids and padded -> only then is attention_mask defined
if
is_input_ids
and
is_pad_token_in_inputs
and
is_pad_token_not_equal_to_eos_token_id
:
if
is_input_ids
and
is_pad_token_in_inputs
and
is_pad_token_not_equal_to_eos_token_id
:
...
...
src/transformers/generation_utils.py
View file @
f1a6df32
...
@@ -495,9 +495,8 @@ class GenerationMixin:
...
@@ -495,9 +495,8 @@ class GenerationMixin:
)
->
torch
.
LongTensor
:
)
->
torch
.
LongTensor
:
is_input_ids
=
len
(
inputs
.
shape
)
==
2
and
inputs
.
dtype
in
[
torch
.
int
,
torch
.
long
]
is_input_ids
=
len
(
inputs
.
shape
)
==
2
and
inputs
.
dtype
in
[
torch
.
int
,
torch
.
long
]
is_pad_token_in_inputs
=
(
pad_token_id
is
not
None
)
and
(
pad_token_id
in
inputs
)
is_pad_token_in_inputs
=
(
pad_token_id
is
not
None
)
and
(
pad_token_id
in
inputs
)
is_pad_token_not_equal_to_eos_token_id
=
(
eos_token_id
is
None
)
or
(
is_pad_token_not_equal_to_eos_token_id
=
(
eos_token_id
is
None
)
or
(
pad_token_id
!=
eos_token_id
)
(
eos_token_id
is
not
None
)
and
(
pad_token_id
!=
eos_token_id
)
)
# Check if input is input_ids and padded -> only then is attention_mask defined
# Check if input is input_ids and padded -> only then is attention_mask defined
if
is_input_ids
and
is_pad_token_in_inputs
and
is_pad_token_not_equal_to_eos_token_id
:
if
is_input_ids
and
is_pad_token_in_inputs
and
is_pad_token_not_equal_to_eos_token_id
:
return
inputs
.
ne
(
pad_token_id
).
long
()
return
inputs
.
ne
(
pad_token_id
).
long
()
...
...
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