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
c47576ca
Unverified
Commit
c47576ca
authored
Feb 20, 2024
by
Fernando Pérez-García
Committed by
GitHub
Feb 20, 2024
Browse files
Fix drop path being ignored in DINOv2 (#29147)
Fix drop path not being used
parent
3c00b885
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
4 deletions
+3
-4
src/transformers/models/dinov2/modeling_dinov2.py
src/transformers/models/dinov2/modeling_dinov2.py
+3
-4
No files found.
src/transformers/models/dinov2/modeling_dinov2.py
View file @
c47576ca
...
...
@@ -380,7 +380,7 @@ class Dinov2Layer(nn.Module):
self
.
norm1
=
nn
.
LayerNorm
(
config
.
hidden_size
,
eps
=
config
.
layer_norm_eps
)
self
.
attention
=
Dinov2Attention
(
config
)
self
.
layer_scale1
=
Dinov2LayerScale
(
config
)
self
.
drop_path
1
=
Dinov2DropPath
(
config
.
drop_path_rate
)
if
config
.
drop_path_rate
>
0.0
else
nn
.
Identity
()
self
.
drop_path
=
Dinov2DropPath
(
config
.
drop_path_rate
)
if
config
.
drop_path_rate
>
0.0
else
nn
.
Identity
()
self
.
norm2
=
nn
.
LayerNorm
(
config
.
hidden_size
,
eps
=
config
.
layer_norm_eps
)
...
...
@@ -389,7 +389,6 @@ class Dinov2Layer(nn.Module):
else
:
self
.
mlp
=
Dinov2MLP
(
config
)
self
.
layer_scale2
=
Dinov2LayerScale
(
config
)
self
.
drop_path2
=
Dinov2DropPath
(
config
.
drop_path_rate
)
if
config
.
drop_path_rate
>
0.0
else
nn
.
Identity
()
def
forward
(
self
,
...
...
@@ -408,7 +407,7 @@ class Dinov2Layer(nn.Module):
outputs
=
self_attention_outputs
[
1
:]
# add self attentions if we output attention weights
# first residual connection
hidden_states
=
attention_output
+
hidden_states
hidden_states
=
self
.
drop_path
(
attention_output
)
+
hidden_states
# in Dinov2, layernorm is also applied after self-attention
layer_output
=
self
.
norm2
(
hidden_states
)
...
...
@@ -416,7 +415,7 @@ class Dinov2Layer(nn.Module):
layer_output
=
self
.
layer_scale2
(
layer_output
)
# second residual connection
layer_output
=
layer_output
+
hidden_states
layer_output
=
self
.
drop_path
(
layer_output
)
+
hidden_states
outputs
=
(
layer_output
,)
+
outputs
...
...
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