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
f3558bbc
Unverified
Commit
f3558bbc
authored
Jun 18, 2021
by
Xa9aX ツ
Committed by
GitHub
Jun 18, 2021
Browse files
Depreciate pythonic Mish and support PyTorch 1.9 version of Mish (#12240)
* Moved Mish to Torch 1.9 version * Run black formatting
parent
47a97683
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
9 deletions
+11
-9
src/transformers/activations.py
src/transformers/activations.py
+11
-1
src/transformers/models/mobilebert/modeling_mobilebert.py
src/transformers/models/mobilebert/modeling_mobilebert.py
+0
-4
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_{{cookiecutter.lowercase_modelname}}.py
...elname}}/modeling_{{cookiecutter.lowercase_modelname}}.py
+0
-4
No files found.
src/transformers/activations.py
View file @
f3558bbc
...
@@ -73,10 +73,20 @@ else:
...
@@ -73,10 +73,20 @@ else:
silu
=
nn
.
functional
.
silu
silu
=
nn
.
functional
.
silu
def
mish
(
x
):
def
_mish_python
(
x
):
"""
See Mish: A Self-Regularized Non-Monotonic Activation Function (Misra., https://arxiv.org/abs/1908.08681). Also
visit the official repository for the paper: https://github.com/digantamisra98/Mish
"""
return
x
*
torch
.
tanh
(
nn
.
functional
.
softplus
(
x
))
return
x
*
torch
.
tanh
(
nn
.
functional
.
softplus
(
x
))
if
version
.
parse
(
torch
.
__version__
)
<
version
.
parse
(
"1.9"
):
mish
=
_mish_python
else
:
mish
=
nn
.
functional
.
mish
def
linear_act
(
x
):
def
linear_act
(
x
):
return
x
return
x
...
...
src/transformers/models/mobilebert/modeling_mobilebert.py
View file @
f3558bbc
...
@@ -140,10 +140,6 @@ def load_tf_weights_in_mobilebert(model, config, tf_checkpoint_path):
...
@@ -140,10 +140,6 @@ def load_tf_weights_in_mobilebert(model, config, tf_checkpoint_path):
return
model
return
model
def
mish
(
x
):
return
x
*
torch
.
tanh
(
nn
.
functional
.
softplus
(
x
))
class
NoNorm
(
nn
.
Module
):
class
NoNorm
(
nn
.
Module
):
def
__init__
(
self
,
feat_size
,
eps
=
None
):
def
__init__
(
self
,
feat_size
,
eps
=
None
):
super
().
__init__
()
super
().
__init__
()
...
...
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_{{cookiecutter.lowercase_modelname}}.py
View file @
f3558bbc
...
@@ -138,10 +138,6 @@ def load_tf_weights_in_{{cookiecutter.lowercase_modelname}}(model, config, tf_ch
...
@@ -138,10 +138,6 @@ def load_tf_weights_in_{{cookiecutter.lowercase_modelname}}(model, config, tf_ch
return
model
return
model
def
mish
(
x
):
return
x
*
torch
.
tanh
(
nn
.
functional
.
softplus
(
x
))
# Copied from transformers.models.bert.modeling_bert.BertEmbeddings with Bert->{{cookiecutter.camelcase_modelname}}
# Copied from transformers.models.bert.modeling_bert.BertEmbeddings with Bert->{{cookiecutter.camelcase_modelname}}
class
{{
cookiecutter
.
camelcase_modelname
}}
Embeddings
(
nn
.
Module
):
class
{{
cookiecutter
.
camelcase_modelname
}}
Embeddings
(
nn
.
Module
):
"""Construct the embeddings from word, position and token_type embeddings."""
"""Construct the embeddings from word, position and token_type embeddings."""
...
...
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