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
ff22b3ac
Commit
ff22b3ac
authored
Feb 21, 2019
by
Stanislas Polu
Browse files
Few small nits in GPT-2's code examples
parent
cbb7fad3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
README.md
README.md
+4
-3
No files found.
README.md
View file @
ff22b3ac
...
...
@@ -427,7 +427,7 @@ model.to('cuda')
with
torch
.
no_grad
():
hidden_states_1
,
past
=
model
(
tokens_tensor_1
)
# past can be used to reuse precomputed hidden state in a subsequent predictions
# (see beam-search examples in the run_gpt2.py example
# (see beam-search examples in the run_gpt2.py example
).
hidden_states_2
,
past
=
model
(
tokens_tensor_2
,
past
=
past
)
```
...
...
@@ -439,14 +439,15 @@ model = GPT2LMHeadModel.from_pretrained('gpt2')
model
.
eval
()
# If you have a GPU, put everything on cuda
tokens_tensor_1
=
tokens_tensor
.
to
(
'cuda'
)
tokens_tensor_1
=
tokens_tensor_1
.
to
(
'cuda'
)
tokens_tensor_2
=
tokens_tensor_2
.
to
(
'cuda'
)
model
.
to
(
'cuda'
)
# Predict all tokens
with
torch
.
no_grad
():
predictions_1
,
past
=
model
(
tokens_tensor_1
)
# past can be used to reuse precomputed hidden state in a subsequent predictions
# (see beam-search examples in the run_gpt2.py example
# (see beam-search examples in the run_gpt2.py example
).
predictions_2
,
past
=
model
(
tokens_tensor_2
,
past
=
past
)
# get the predicted last token
...
...
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