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
7132d55c
Unverified
Commit
7132d55c
authored
Sep 27, 2022
by
Ekagra Ranjan
Committed by
GitHub
Sep 27, 2022
Browse files
Remove unused `cur_len` in generation_utils.py (#18874)
* remove unused cur_len in generation_utils.py * linting
parent
a32f97c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
14 deletions
+0
-14
src/transformers/generation_utils.py
src/transformers/generation_utils.py
+0
-14
No files found.
src/transformers/generation_utils.py
View file @
7132d55c
...
@@ -534,7 +534,6 @@ class GenerationMixin:
...
@@ -534,7 +534,6 @@ class GenerationMixin:
model_kwargs
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
model_kwargs
:
Optional
[
Dict
[
str
,
torch
.
Tensor
]]
=
None
,
device
:
torch
.
device
=
None
,
device
:
torch
.
device
=
None
,
)
->
torch
.
LongTensor
:
)
->
torch
.
LongTensor
:
if
model_kwargs
is
not
None
and
"decoder_input_ids"
in
model_kwargs
:
if
model_kwargs
is
not
None
and
"decoder_input_ids"
in
model_kwargs
:
return
model_kwargs
.
pop
(
"decoder_input_ids"
)
return
model_kwargs
.
pop
(
"decoder_input_ids"
)
else
:
else
:
...
@@ -1720,11 +1719,9 @@ class GenerationMixin:
...
@@ -1720,11 +1719,9 @@ class GenerationMixin:
# keep track of which sequences are already finished
# keep track of which sequences are already finished
unfinished_sequences
=
input_ids
.
new
(
input_ids
.
shape
[
0
]).
fill_
(
1
)
unfinished_sequences
=
input_ids
.
new
(
input_ids
.
shape
[
0
]).
fill_
(
1
)
cur_len
=
input_ids
.
shape
[
-
1
]
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
@@ -1747,7 +1744,6 @@ class GenerationMixin:
...
@@ -1747,7 +1744,6 @@ class GenerationMixin:
)
)
if
synced_gpus
and
this_peer_finished
:
if
synced_gpus
and
this_peer_finished
:
cur_len
=
cur_len
+
1
continue
# don't waste resources running the code we don't need
continue
# don't waste resources running the code we don't need
next_token_logits
=
outputs
.
logits
[:,
-
1
,
:]
next_token_logits
=
outputs
.
logits
[:,
-
1
,
:]
...
@@ -1787,7 +1783,6 @@ class GenerationMixin:
...
@@ -1787,7 +1783,6 @@ class GenerationMixin:
model_kwargs
=
self
.
_update_model_kwargs_for_generation
(
model_kwargs
=
self
.
_update_model_kwargs_for_generation
(
outputs
,
model_kwargs
,
is_encoder_decoder
=
self
.
config
.
is_encoder_decoder
outputs
,
model_kwargs
,
is_encoder_decoder
=
self
.
config
.
is_encoder_decoder
)
)
cur_len
=
cur_len
+
1
# if eos_token was found in one sentence, set sentence to finished
# if eos_token was found in one sentence, set sentence to finished
if
eos_token_id
is
not
None
:
if
eos_token_id
is
not
None
:
...
@@ -1973,12 +1968,10 @@ class GenerationMixin:
...
@@ -1973,12 +1968,10 @@ class GenerationMixin:
# keep track of which sequences are already finished
# keep track of which sequences are already finished
unfinished_sequences
=
input_ids
.
new
(
input_ids
.
shape
[
0
]).
fill_
(
1
)
unfinished_sequences
=
input_ids
.
new
(
input_ids
.
shape
[
0
]).
fill_
(
1
)
cur_len
=
input_ids
.
shape
[
-
1
]
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
# auto-regressive generation
# auto-regressive generation
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
@@ -2001,7 +1994,6 @@ class GenerationMixin:
...
@@ -2001,7 +1994,6 @@ class GenerationMixin:
)
)
if
synced_gpus
and
this_peer_finished
:
if
synced_gpus
and
this_peer_finished
:
cur_len
=
cur_len
+
1
continue
# don't waste resources running the code we don't need
continue
# don't waste resources running the code we don't need
next_token_logits
=
outputs
.
logits
[:,
-
1
,
:]
next_token_logits
=
outputs
.
logits
[:,
-
1
,
:]
...
@@ -2043,7 +2035,6 @@ class GenerationMixin:
...
@@ -2043,7 +2035,6 @@ class GenerationMixin:
model_kwargs
=
self
.
_update_model_kwargs_for_generation
(
model_kwargs
=
self
.
_update_model_kwargs_for_generation
(
outputs
,
model_kwargs
,
is_encoder_decoder
=
self
.
config
.
is_encoder_decoder
outputs
,
model_kwargs
,
is_encoder_decoder
=
self
.
config
.
is_encoder_decoder
)
)
cur_len
=
cur_len
+
1
# if eos_token was found in one sentence, set sentence to finished
# if eos_token was found in one sentence, set sentence to finished
if
eos_token_id
is
not
None
:
if
eos_token_id
is
not
None
:
...
@@ -2248,7 +2239,6 @@ class GenerationMixin:
...
@@ -2248,7 +2239,6 @@ class GenerationMixin:
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
@@ -2561,7 +2551,6 @@ class GenerationMixin:
...
@@ -2561,7 +2551,6 @@ class GenerationMixin:
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
@@ -2884,7 +2873,6 @@ class GenerationMixin:
...
@@ -2884,7 +2873,6 @@ class GenerationMixin:
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
@@ -3083,7 +3071,6 @@ class GenerationMixin:
...
@@ -3083,7 +3071,6 @@ class GenerationMixin:
synced_gpus
:
Optional
[
bool
]
=
None
,
synced_gpus
:
Optional
[
bool
]
=
None
,
**
model_kwargs
,
**
model_kwargs
,
)
->
Union
[
BeamSearchOutput
,
torch
.
LongTensor
]:
)
->
Union
[
BeamSearchOutput
,
torch
.
LongTensor
]:
r
"""
r
"""
Generates sequences of token ids for models with a language modeling head using **constrained beam search
Generates sequences of token ids for models with a language modeling head using **constrained beam search
decoding** and can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.
decoding** and can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.
...
@@ -3247,7 +3234,6 @@ class GenerationMixin:
...
@@ -3247,7 +3234,6 @@ class GenerationMixin:
this_peer_finished
=
False
# used by synced_gpus only
this_peer_finished
=
False
# used by synced_gpus only
while
True
:
while
True
:
if
synced_gpus
:
if
synced_gpus
:
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# Under synced_gpus the `forward` call must continue until all gpus complete their sequence.
# The following logic allows an early break if all peers finished generating their sequence
# The following logic allows an early break if all peers finished generating their sequence
...
...
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