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
365ccd0a
Commit
365ccd0a
authored
Dec 23, 2019
by
patrickvonplaten
Browse files
make if statements cleaner for prepare_inputs_for_generation
parent
d039c679
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
src/transformers/modeling_ctrl.py
src/transformers/modeling_ctrl.py
+3
-2
src/transformers/modeling_gpt2.py
src/transformers/modeling_gpt2.py
+3
-2
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+2
-2
No files found.
src/transformers/modeling_ctrl.py
View file @
365ccd0a
...
...
@@ -491,8 +491,9 @@ class CTRLLMHeadModel(CTRLPreTrainedModel):
return
self
.
lm_head
def
prepare_inputs_for_generation
(
self
,
input_ids
,
**
kwargs
):
# inputs_ids should only be composed of last token if past is in kwargs and defined
input_ids
=
input_ids
[:,
-
1
].
unsqueeze
(
-
1
)
if
'past'
in
kwargs
and
kwargs
[
'past'
]
else
input_ids
# only last token for inputs_ids if past is defined in kwargs
if
'past'
in
kwargs
and
kwargs
[
'past'
]:
input_ids
=
input_ids
[:,
-
1
].
unsqueeze
(
-
1
)
inputs
=
{
"input_ids"
:
input_ids
}
inputs
.
update
(
kwargs
)
...
...
src/transformers/modeling_gpt2.py
View file @
365ccd0a
...
...
@@ -560,8 +560,9 @@ class GPT2LMHeadModel(GPT2PreTrainedModel):
return
self
.
lm_head
def
prepare_inputs_for_generation
(
self
,
input_ids
,
**
kwargs
):
# inputs_ids should only be composed of last token if past is in kwargs and defined
input_ids
=
input_ids
[:,
-
1
].
unsqueeze
(
-
1
)
if
'past'
in
kwargs
and
kwargs
[
'past'
]
else
input_ids
# only last token for inputs_ids if past is defined in kwargs
if
'past'
in
kwargs
and
kwargs
[
'past'
]:
input_ids
=
input_ids
[:,
-
1
].
unsqueeze
(
-
1
)
inputs
=
{
"input_ids"
:
input_ids
}
inputs
.
update
(
kwargs
)
...
...
src/transformers/modeling_utils.py
View file @
365ccd0a
...
...
@@ -540,8 +540,8 @@ class PreTrainedModel(nn.Module):
return
{
"input_ids"
:
input_ids
}
def
_do_output_past
(
self
,
outputs
):
# TODO: might be better to write a self.do_output_past method for each
individual class as is done for
# prepare_inputs_for_generation
# TODO: might be better to write a self.do_output_past method for each
#
individual class as is done for
prepare_inputs_for_generation
has_output_past
=
hasattr
(
self
.
config
,
'output_past'
)
and
self
.
config
.
output_past
has_multiple_outputs
=
len
(
outputs
)
>
1
has_mem_len
=
hasattr
(
self
,
'mem_len'
)
...
...
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