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
2f3a4210
Commit
2f3a4210
authored
Nov 06, 2019
by
Julien Chaumond
Browse files
Fix other PyTorch models
parent
d5319793
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
templates/adding_a_new_model/modeling_xxx.py
templates/adding_a_new_model/modeling_xxx.py
+4
-2
transformers/modeling_distilbert.py
transformers/modeling_distilbert.py
+3
-1
No files found.
templates/adding_a_new_model/modeling_xxx.py
View file @
2f3a4210
...
...
@@ -309,10 +309,12 @@ class XxxModel(XxxPreTrainedModel):
else
:
raise
ValueError
(
"You have to specify either input_ids or inputs_embeds"
)
device
=
input_ids
.
device
if
input_ids
is
not
None
else
inputs_embeds
.
device
if
attention_mask
is
None
:
attention_mask
=
torch
.
ones
(
input_shape
)
attention_mask
=
torch
.
ones
(
input_shape
,
device
=
device
)
if
token_type_ids
is
None
:
token_type_ids
=
torch
.
zeros
(
input_shape
,
dtype
=
torch
.
long
)
token_type_ids
=
torch
.
zeros
(
input_shape
,
dtype
=
torch
.
long
,
device
=
device
)
# We create a 3D attention mask from a 2D tensor mask.
# Sizes are [batch_size, 1, 1, to_seq_length]
...
...
transformers/modeling_distilbert.py
View file @
2f3a4210
...
...
@@ -450,8 +450,10 @@ class DistilBertModel(DistilBertPreTrainedModel):
else
:
raise
ValueError
(
"You have to specify either input_ids or inputs_embeds"
)
device
=
input_ids
.
device
if
input_ids
is
not
None
else
inputs_embeds
.
device
if
attention_mask
is
None
:
attention_mask
=
torch
.
ones
(
input_shape
)
# (bs, seq_length)
attention_mask
=
torch
.
ones
(
input_shape
,
device
=
device
)
# (bs, seq_length)
# Prepare head mask if needed
# 1.0 in head_mask indicate we keep the head
...
...
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