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
8df97ff6
Unverified
Commit
8df97ff6
authored
Apr 07, 2020
by
Samuel
Committed by
GitHub
Apr 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Pytorch]layernorm bug fix and testcase updated (#5257)
parent
608e9458
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
python/tvm/relay/frontend/pytorch.py
+12
-8
tests/python/frontend/pytorch/test_forward.py
+10
-2
No files found.
python/tvm/relay/frontend/pytorch.py
View file @
8df97ff6
...
...
@@ -166,7 +166,8 @@ def _ones():
elif
isinstance
(
data
,
(
torch
.
Tensor
,
np
.
ndarray
)):
shape
=
data
.
shape
else
:
assert
"data type {} could not be parsed in ones op"
%
(
type
(
data
))
msg
=
"Data type
%
s could not be parsed in ones op"
%
(
type
(
data
))
raise
AssertionError
(
msg
)
dtype_map
=
{
6
:
"float32"
,
3
:
"int32"
}
dtype_id
=
inputs
[
1
]
...
...
@@ -186,7 +187,8 @@ def _zeros():
elif
isinstance
(
data
,
(
torch
.
Tensor
,
np
.
ndarray
)):
shape
=
data
.
shape
else
:
assert
"data type {} could not be parsed in zeros op"
%
(
type
(
data
))
msg
=
"Data type
%
s could not be parsed in zeros op"
%
(
type
(
data
))
raise
AssertionError
(
msg
)
dtype_map
=
{
6
:
"float32"
,
3
:
"int32"
}
dtype_id
=
inputs
[
1
]
...
...
@@ -354,7 +356,8 @@ def _convolution():
for
infer
in
inferred_shape
:
weight_shape
.
append
(
infer
)
else
:
assert
"data type {} could not be parsed in conv op"
%
(
type
(
weight
))
msg
=
"Data type
%
s could not be parsed in conv op"
%
(
type
(
weight
))
raise
AssertionError
(
msg
)
# Transposed convolutions have IOHW layout.
if
use_transpose
:
...
...
@@ -523,12 +526,12 @@ def _layer_norm():
assert
ndims
==
1
,
"Support only normalization over last one dimension."
return
_op
.
nn
.
layer_norm
(
data
,
gamma
=
inputs
[
1
],
beta
=
inputs
[
2
],
gamma
=
inputs
[
2
],
beta
=
inputs
[
3
],
axis
=-
1
,
epsilon
=
float
(
inputs
[
4
]),
center
=
Fals
e
,
scale
=
Fals
e
)
center
=
Tru
e
,
scale
=
Tru
e
)
return
_impl
def
_transpose
():
...
...
@@ -543,7 +546,8 @@ def _transpose():
elif
isinstance
(
data
,
(
torch
.
Tensor
,
np
.
ndarray
)):
ndims
=
data
.
shape
else
:
assert
"data type {} could not be parsed in transpose op"
%
(
type
(
data
))
msg
=
"Data type
%
s could not be parsed in transpose op"
%
(
type
(
data
))
raise
AssertionError
(
msg
)
if
isinstance
(
data
,
tvm
.
runtime
.
NDArray
):
ndims
=
len
(
data
.
shape
)
...
...
tests/python/frontend/pytorch/test_forward.py
View file @
8df97ff6
...
...
@@ -562,8 +562,16 @@ def test_forward_instancenorm():
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
init_weight
(
m
):
torch
.
nn
.
init
.
normal_
(
m
.
weight
,
0
,
0.01
)
torch
.
nn
.
init
.
normal_
(
m
.
bias
,
0.02
)
inp_2d
=
torch
.
rand
((
1
,
16
,
10
,
10
))
inp_3d
=
torch
.
rand
((
1
,
16
,
10
,
10
,
10
))
for
ln
,
inp
in
[(
torch
.
nn
.
LayerNorm
(
10
),
inp_2d
),
(
torch
.
nn
.
LayerNorm
(
10
),
inp_3d
)]:
init_weight
(
ln
.
eval
())
verify_model
(
ln
.
eval
(),
input_data
=
inp
)
def
test_forward_transpose
():
torch
.
set_grad_enabled
(
False
)
...
...
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