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
fc1fbae4
Commit
fc1fbae4
authored
Aug 21, 2019
by
LysandreJik
Browse files
XLM can be pruned
parent
42e00cf9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
1 deletion
+6
-1
pytorch_transformers/modeling_xlm.py
pytorch_transformers/modeling_xlm.py
+6
-0
pytorch_transformers/tests/modeling_common_test.py
pytorch_transformers/tests/modeling_common_test.py
+0
-1
No files found.
pytorch_transformers/modeling_xlm.py
View file @
fc1fbae4
...
@@ -559,6 +559,12 @@ class XLMModel(XLMPreTrainedModel):
...
@@ -559,6 +559,12 @@ class XLMModel(XLMPreTrainedModel):
self
.
ffns
.
append
(
TransformerFFN
(
self
.
dim
,
self
.
hidden_dim
,
self
.
dim
,
config
=
config
))
self
.
ffns
.
append
(
TransformerFFN
(
self
.
dim
,
self
.
hidden_dim
,
self
.
dim
,
config
=
config
))
self
.
layer_norm2
.
append
(
nn
.
LayerNorm
(
self
.
dim
,
eps
=
config
.
layer_norm_eps
))
self
.
layer_norm2
.
append
(
nn
.
LayerNorm
(
self
.
dim
,
eps
=
config
.
layer_norm_eps
))
if
hasattr
(
config
,
"pruned_heads"
):
pruned_heads
=
config
.
pruned_heads
.
copy
().
items
()
for
layer
,
heads
in
pruned_heads
:
if
self
.
attentions
[
int
(
layer
)].
n_heads
==
config
.
n_heads
:
self
.
prune_heads
({
int
(
layer
):
list
(
map
(
int
,
heads
))})
self
.
apply
(
self
.
init_weights
)
self
.
apply
(
self
.
init_weights
)
def
_resize_token_embeddings
(
self
,
new_num_tokens
):
def
_resize_token_embeddings
(
self
,
new_num_tokens
):
...
...
pytorch_transformers/tests/modeling_common_test.py
View file @
fc1fbae4
...
@@ -269,7 +269,6 @@ class CommonTestCases:
...
@@ -269,7 +269,6 @@ class CommonTestCases:
shutil
.
rmtree
(
directory
)
shutil
.
rmtree
(
directory
)
def
test_head_pruning_save_load_from_config_init
(
self
):
def
test_head_pruning_save_load_from_config_init
(
self
):
print
(
self
.
test_pruning
)
if
not
self
.
test_pruning
:
if
not
self
.
test_pruning
:
return
return
...
...
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