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
5ab87cd4
Unverified
Commit
5ab87cd4
authored
Jan 06, 2022
by
Matt Churgin
Committed by
GitHub
Jan 06, 2022
Browse files
wrapped forward passes in torch.no_grad() (#15037)
parent
5a06118b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
tests/test_modeling_roberta.py
tests/test_modeling_roberta.py
+6
-3
No files found.
tests/test_modeling_roberta.py
View file @
5ab87cd4
...
...
@@ -485,6 +485,7 @@ class RobertaModelIntegrationTest(TestCasePlus):
model
=
RobertaForMaskedLM
.
from_pretrained
(
"roberta-base"
)
input_ids
=
torch
.
tensor
([[
0
,
31414
,
232
,
328
,
740
,
1140
,
12695
,
69
,
46078
,
1588
,
2
]])
with
torch
.
no_grad
():
output
=
model
(
input_ids
)[
0
]
expected_shape
=
torch
.
Size
((
1
,
11
,
50265
))
self
.
assertEqual
(
output
.
shape
,
expected_shape
)
...
...
@@ -504,6 +505,7 @@ class RobertaModelIntegrationTest(TestCasePlus):
model
=
RobertaModel
.
from_pretrained
(
"roberta-base"
)
input_ids
=
torch
.
tensor
([[
0
,
31414
,
232
,
328
,
740
,
1140
,
12695
,
69
,
46078
,
1588
,
2
]])
with
torch
.
no_grad
():
output
=
model
(
input_ids
)[
0
]
# compare the actual values for a slice.
expected_slice
=
torch
.
tensor
(
...
...
@@ -521,6 +523,7 @@ class RobertaModelIntegrationTest(TestCasePlus):
model
=
RobertaForSequenceClassification
.
from_pretrained
(
"roberta-large-mnli"
)
input_ids
=
torch
.
tensor
([[
0
,
31414
,
232
,
328
,
740
,
1140
,
12695
,
69
,
46078
,
1588
,
2
]])
with
torch
.
no_grad
():
output
=
model
(
input_ids
)[
0
]
expected_shape
=
torch
.
Size
((
1
,
3
))
self
.
assertEqual
(
output
.
shape
,
expected_shape
)
...
...
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