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
262345fa
Commit
262345fa
authored
Sep 22, 2017
by
Tianqi Chen
Committed by
GitHub
Sep 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TOPI] dense API to remove redudant use_bias (#476)
parent
833855e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
12 deletions
+11
-12
topi/python/topi/nn/dense.py
+10
-11
topi/tests/python/test_topi_dense.py
+1
-1
No files found.
topi/python/topi/nn/dense.py
View file @
262345fa
...
...
@@ -4,7 +4,7 @@ import tvm
from
..
import
tag
def
dense
(
data
,
weight
,
bias
,
use_bias
=
Tru
e
):
def
dense
(
data
,
weight
,
bias
=
Non
e
):
"""Applies a linear transformation: :math:`Y = XW^T + b`.
Parameters
...
...
@@ -15,27 +15,26 @@ def dense(data, weight, bias, use_bias=True):
weight : tvm.Tensor
2-D with shape [out_dim, in_dim]
bias : tvm.Tensor
bias : tvm.Tensor
, optional
1-D with shape [out_dim]
use_bias : bool, optional, default=True
Whether to use bias parameter
Returns
-------
output : tvm.Tensor
2-D with shape [batch, out_dim]
"""
assert
len
(
data
.
shape
)
==
2
and
len
(
weight
.
shape
)
==
2
and
len
(
bias
.
shape
)
==
1
,
\
assert
len
(
data
.
shape
)
==
2
and
len
(
weight
.
shape
)
==
2
,
\
"only support 2-dim dense"
if
bias
:
assert
len
(
bias
.
shape
)
==
1
batch
,
in_dim
=
data
.
shape
out_dim
,
_
=
weight
.
shape
k
=
tvm
.
reduce_axis
((
0
,
in_dim
),
name
=
'k'
)
matmul
=
tvm
.
compute
((
batch
,
out_dim
),
\
lambda
i
,
j
:
tvm
.
sum
(
data
[
i
,
k
]
*
weight
[
j
,
k
],
axis
=
k
),
\
tag
=
'dense'
)
if
not
use_
bias
:
return
matmul
return
tvm
.
compute
((
batch
,
out_dim
)
,
\
lambda
i
,
j
:
matmul
[
i
,
j
]
+
bias
[
j
],
\
tag
=
tag
.
BROADCAST
)
if
bias
:
matmul
=
tvm
.
compute
((
batch
,
out_dim
),
\
lambda
i
,
j
:
matmul
[
i
,
j
]
+
bias
[
j
]
,
\
tag
=
tag
.
BROADCAST
)
return
matmul
topi/tests/python/test_topi_dense.py
View file @
262345fa
...
...
@@ -10,7 +10,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True):
A
=
tvm
.
placeholder
((
batch
,
in_dim
),
name
=
'A'
)
B
=
tvm
.
placeholder
((
out_dim
,
in_dim
),
name
=
'B'
)
C
=
tvm
.
placeholder
((
out_dim
,),
name
=
'C'
)
D
=
topi
.
nn
.
dense
(
A
,
B
,
C
,
use_bias
=
use_bias
)
D
=
topi
.
nn
.
dense
(
A
,
B
,
C
if
use_bias
else
None
)
D
=
topi
.
nn
.
relu
(
D
)
s
=
topi
.
cuda
.
schedule_dense
(
D
)
dtype
=
A
.
dtype
...
...
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