Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
a722c301
Unverified
Commit
a722c301
authored
Sep 21, 2021
by
Stas Bekman
Committed by
GitHub
Sep 21, 2021
Browse files
[SinusoidalPositionalEmbedding] incorrect dtype when make_weights in forward (#13665)
parent
1417978c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
8 deletions
+8
-8
src/transformers/models/fsmt/modeling_fsmt.py
src/transformers/models/fsmt/modeling_fsmt.py
+2
-2
src/transformers/models/m2m_100/modeling_m2m_100.py
src/transformers/models/m2m_100/modeling_m2m_100.py
+2
-2
src/transformers/models/speech_to_text/modeling_speech_to_text.py
...sformers/models/speech_to_text/modeling_speech_to_text.py
+2
-2
src/transformers/models/speech_to_text_2/modeling_speech_to_text_2.py
...mers/models/speech_to_text_2/modeling_speech_to_text_2.py
+2
-2
No files found.
src/transformers/models/fsmt/modeling_fsmt.py
View file @
a722c301
...
...
@@ -1272,8 +1272,8 @@ class SinusoidalPositionalEmbedding(nn.Embedding):
# in ___init__
super
().
__init__
(
num_positions
,
embedding_dim
,
padding_idx
,
_weight
=
weight
)
else
:
# in forward
weight
=
weight
.
to
(
self
.
weight
.
device
)
# in forward
put the weights on the correct dtype and device of the param
weight
=
weight
.
to
(
dtype
=
self
.
weight
.
dtype
,
device
=
self
.
weight
.
device
)
self
.
weight
=
nn
.
Parameter
(
weight
)
self
.
weight
.
detach_
()
self
.
weight
.
requires_grad
=
False
...
...
src/transformers/models/m2m_100/modeling_m2m_100.py
View file @
a722c301
...
...
@@ -126,8 +126,8 @@ class M2M100SinusoidalPositionalEmbedding(nn.Module):
def
make_weights
(
self
,
num_embeddings
:
int
,
embedding_dim
:
int
,
padding_idx
:
Optional
[
int
]
=
None
):
emb_weights
=
self
.
get_embedding
(
num_embeddings
,
embedding_dim
,
padding_idx
)
if
hasattr
(
self
,
"weights"
):
# in forward
,
put the weights on correct d
evice
emb_weights
=
emb_weights
.
to
(
self
.
weights
.
device
)
# in forward put the weights on
the
correct d
type and device of the param
emb_weights
=
emb_weights
.
to
(
dtype
=
self
.
weights
.
dtype
,
device
=
self
.
weights
.
device
)
self
.
weights
=
nn
.
Parameter
(
emb_weights
)
self
.
weights
.
requires_grad
=
False
...
...
src/transformers/models/speech_to_text/modeling_speech_to_text.py
View file @
a722c301
...
...
@@ -149,8 +149,8 @@ class Speech2TextSinusoidalPositionalEmbedding(nn.Module):
def
make_weights
(
self
,
num_embeddings
:
int
,
embedding_dim
:
int
,
padding_idx
:
Optional
[
int
]
=
None
):
emb_weights
=
self
.
get_embedding
(
num_embeddings
,
embedding_dim
,
padding_idx
)
if
hasattr
(
self
,
"weights"
):
# in forward
,
put the weights on correct d
evice
emb_weights
=
emb_weights
.
to
(
self
.
weights
.
device
)
# in forward put the weights on
the
correct d
type and device of the param
emb_weights
=
emb_weights
.
to
(
dtype
=
self
.
weights
.
dtype
,
device
=
self
.
weights
.
device
)
self
.
weights
=
nn
.
Parameter
(
emb_weights
)
self
.
weights
.
requires_grad
=
False
...
...
src/transformers/models/speech_to_text_2/modeling_speech_to_text_2.py
View file @
a722c301
...
...
@@ -90,8 +90,8 @@ class Speech2Text2SinusoidalPositionalEmbedding(nn.Module):
def
make_weights
(
self
,
num_embeddings
:
int
,
embedding_dim
:
int
,
padding_idx
:
Optional
[
int
]
=
None
):
emb_weights
=
self
.
get_embedding
(
num_embeddings
,
embedding_dim
,
padding_idx
)
if
hasattr
(
self
,
"weights"
):
# in forward
,
put the weights on correct d
evice
emb_weights
=
emb_weights
.
to
(
self
.
weights
.
device
)
# in forward put the weights on
the
correct d
type and device of the param
emb_weights
=
emb_weights
.
to
(
dtype
=
self
.
weights
.
dtype
,
device
=
self
.
weights
.
device
)
self
.
weights
=
nn
.
Parameter
(
emb_weights
)
self
.
weights
.
requires_grad
=
False
...
...
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