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
4bf50422
Unverified
Commit
4bf50422
authored
May 12, 2020
by
Julien Chaumond
Committed by
GitHub
May 12, 2020
Browse files
Fix BART tests on GPU (#4298)
parent
e4512aab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
2 deletions
+6
-2
src/transformers/modeling_bart.py
src/transformers/modeling_bart.py
+1
-1
tests/test_modeling_bart.py
tests/test_modeling_bart.py
+5
-1
No files found.
src/transformers/modeling_bart.py
View file @
4bf50422
...
@@ -886,7 +886,7 @@ class BartForConditionalGeneration(PretrainedBartModel):
...
@@ -886,7 +886,7 @@ class BartForConditionalGeneration(PretrainedBartModel):
if
new_num_tokens
<=
old_num_tokens
:
if
new_num_tokens
<=
old_num_tokens
:
new_bias
=
self
.
final_logits_bias
[:,
:
new_num_tokens
]
new_bias
=
self
.
final_logits_bias
[:,
:
new_num_tokens
]
else
:
else
:
extra_bias
=
torch
.
zeros
((
1
,
new_num_tokens
-
old_num_tokens
))
extra_bias
=
torch
.
zeros
((
1
,
new_num_tokens
-
old_num_tokens
)
,
device
=
self
.
final_logits_bias
.
device
)
new_bias
=
torch
.
cat
([
self
.
final_logits_bias
,
extra_bias
],
dim
=
1
)
new_bias
=
torch
.
cat
([
self
.
final_logits_bias
,
extra_bias
],
dim
=
1
)
self
.
register_buffer
(
"final_logits_bias"
,
new_bias
)
self
.
register_buffer
(
"final_logits_bias"
,
new_bias
)
...
...
tests/test_modeling_bart.py
View file @
4bf50422
...
@@ -690,4 +690,8 @@ class TestSinusoidalPositionalEmbeddings(unittest.TestCase):
...
@@ -690,4 +690,8 @@ class TestSinusoidalPositionalEmbeddings(unittest.TestCase):
# test that forward pass is just a lookup, there is no ignore padding logic
# test that forward pass is just a lookup, there is no ignore padding logic
input_ids
=
torch
.
tensor
([[
4
,
10
,
pad
,
pad
,
pad
]],
dtype
=
torch
.
long
,
device
=
torch_device
)
input_ids
=
torch
.
tensor
([[
4
,
10
,
pad
,
pad
,
pad
]],
dtype
=
torch
.
long
,
device
=
torch_device
)
no_cache_pad_zero
=
emb1
(
input_ids
)
no_cache_pad_zero
=
emb1
(
input_ids
)
self
.
assertTrue
(
torch
.
allclose
(
torch
.
Tensor
(
self
.
desired_weights
),
no_cache_pad_zero
[:
3
,
:
5
],
atol
=
1e-3
))
self
.
assertTrue
(
torch
.
allclose
(
torch
.
tensor
(
self
.
desired_weights
,
device
=
torch_device
),
no_cache_pad_zero
[:
3
,
:
5
],
atol
=
1e-3
)
)
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