Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
0cc26614
Unverified
Commit
0cc26614
authored
Apr 07, 2020
by
Samuel
Committed by
GitHub
Apr 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PYTORCH]LayerNorm support added (#5249)
parent
5e50f476
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
python/tvm/relay/frontend/pytorch.py
+29
-0
tests/python/frontend/pytorch/test_forward.py
+4
-0
No files found.
python/tvm/relay/frontend/pytorch.py
View file @
0cc26614
...
...
@@ -503,6 +503,34 @@ def _instance_norm():
scale
=
scale
)
return
_impl
def
_get_dims
(
data
):
import
torch
if
isinstance
(
data
,
_expr
.
Expr
):
dims
=
_infer_shape
(
data
)
elif
isinstance
(
data
,
list
):
dims
=
data
elif
isinstance
(
data
,
(
torch
.
Tensor
,
np
.
ndarray
)):
dims
=
data
.
shape
else
:
msg
=
"Data type
%
s could not be parsed"
%
type
(
data
)
raise
AssertionError
(
msg
)
return
dims
def
_layer_norm
():
def
_impl
(
inputs
,
input_types
):
data
=
inputs
[
0
]
ndims
=
len
(
_get_dims
(
inputs
[
1
]))
assert
ndims
==
1
,
"Support only normalization over last one dimension."
return
_op
.
nn
.
layer_norm
(
data
,
gamma
=
inputs
[
1
],
beta
=
inputs
[
2
],
axis
=-
1
,
epsilon
=
float
(
inputs
[
4
]),
center
=
False
,
scale
=
False
)
return
_impl
def
_transpose
():
def
_impl
(
inputs
,
input_types
):
data
=
inputs
[
0
]
...
...
@@ -1050,6 +1078,7 @@ _convert_map = {
"aten::contiguous"
:
_contiguous
(),
"aten::batch_norm"
:
_batch_norm
(),
"aten::instance_norm"
:
_instance_norm
(),
"aten::layer_norm"
:
_layer_norm
(),
"aten::transpose"
:
_transpose
(),
"aten::transpose_"
:
_transpose
(),
"aten::t"
:
_transpose
(),
...
...
tests/python/frontend/pytorch/test_forward.py
View file @
0cc26614
...
...
@@ -561,6 +561,9 @@ def test_forward_instancenorm():
(
torch
.
nn
.
InstanceNorm3d
(
16
),
inp_3d
)]:
verify_model
(
ins_norm
.
eval
(),
input_data
=
inp
)
def
test_forward_layernorm
():
inp
=
torch
.
rand
((
20
,
5
,
10
,
10
))
verify_model
(
torch
.
nn
.
LayerNorm
(
10
)
.
eval
(),
input_data
=
inp
)
def
test_forward_transpose
():
torch
.
set_grad_enabled
(
False
)
...
...
@@ -1132,6 +1135,7 @@ if __name__ == "__main__":
test_forward_contiguous
()
test_forward_batchnorm
()
test_forward_instancenorm
()
test_forward_layernorm
()
test_forward_transpose
()
test_forward_size
()
test_forward_view
()
...
...
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