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
267587c2
Commit
267587c2
authored
Dec 23, 2019
by
patrickvonplaten
Browse files
add and improve comments
parent
d891fd0a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
2 deletions
+4
-2
src/transformers/modeling_ctrl.py
src/transformers/modeling_ctrl.py
+1
-1
src/transformers/modeling_gpt2.py
src/transformers/modeling_gpt2.py
+1
-1
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+2
-0
No files found.
src/transformers/modeling_ctrl.py
View file @
267587c2
...
...
@@ -491,7 +491,7 @@ class CTRLLMHeadModel(CTRLPreTrainedModel):
return
self
.
lm_head
def
prepare_inputs_for_generation
(
self
,
input_ids
,
**
kwargs
):
# inputs_ids
contain only
last token if past is in kwargs and defined
# 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
inputs
=
{
"input_ids"
:
input_ids
}
...
...
src/transformers/modeling_gpt2.py
View file @
267587c2
...
...
@@ -560,7 +560,7 @@ class GPT2LMHeadModel(GPT2PreTrainedModel):
return
self
.
lm_head
def
prepare_inputs_for_generation
(
self
,
input_ids
,
**
kwargs
):
# inputs_ids
contain only
last token if past is in kwargs and defined
# 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
inputs
=
{
"input_ids"
:
input_ids
}
...
...
src/transformers/modeling_utils.py
View file @
267587c2
...
...
@@ -732,6 +732,7 @@ class PreTrainedModel(nn.Module):
outputs
=
self
(
**
model_inputs
)
next_token_logits
=
outputs
[
0
][:,
-
1
,
:]
# if model has past, then set the past parameter to speed up decoding
if
self
.
_has_past
(
outputs
):
past
=
outputs
[
1
]
...
...
@@ -819,6 +820,7 @@ class PreTrainedModel(nn.Module):
outputs
=
self
(
**
model_inputs
)
# (batch_size * num_beams, cur_len, vocab_size)
scores
=
outputs
[
0
][:,
-
1
,
:]
# (batch_size * num_beams, vocab_size)
# if model has past, then set the past parameter to speed up decoding
if
self
.
_has_past
(
outputs
):
past
=
outputs
[
1
]
...
...
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