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
f4ef78af
Unverified
Commit
f4ef78af
authored
Oct 12, 2022
by
Mathieu Jouffroy
Committed by
GitHub
Oct 12, 2022
Browse files
using trunc_normal for weight init & cls_token (#19486)
parent
5760a8fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
src/transformers/models/cvt/modeling_cvt.py
src/transformers/models/cvt/modeling_cvt.py
+6
-4
No files found.
src/transformers/models/cvt/modeling_cvt.py
View file @
f4ef78af
...
...
@@ -451,7 +451,11 @@ class CvtStage(nn.Module):
self
.
config
=
config
self
.
stage
=
stage
if
self
.
config
.
cls_token
[
self
.
stage
]:
self
.
cls_token
=
nn
.
Parameter
(
torch
.
zeros
(
1
,
1
,
self
.
config
.
embed_dim
[
-
1
]))
self
.
cls_token
=
nn
.
Parameter
(
nn
.
init
.
trunc_normal_
(
torch
.
zeros
(
1
,
1
,
self
.
config
.
embed_dim
[
-
1
]),
mean
=
0.0
,
std
=
config
.
initializer_range
)
)
self
.
embedding
=
CvtEmbeddings
(
patch_size
=
config
.
patch_sizes
[
self
.
stage
],
...
...
@@ -547,9 +551,7 @@ class CvtPreTrainedModel(PreTrainedModel):
def
_init_weights
(
self
,
module
):
"""Initialize the weights"""
if
isinstance
(
module
,
(
nn
.
Linear
,
nn
.
Conv2d
)):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module
.
weight
.
data
.
normal_
(
mean
=
0.0
,
std
=
self
.
config
.
initializer_range
)
module
.
weight
.
data
=
nn
.
init
.
trunc_normal_
(
module
.
weight
.
data
,
mean
=
0.0
,
std
=
self
.
config
.
initializer_range
)
if
module
.
bias
is
not
None
:
module
.
bias
.
data
.
zero_
()
elif
isinstance
(
module
,
nn
.
LayerNorm
):
...
...
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