Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
262345fa
Commit
262345fa
authored
7 years ago
by
Tianqi Chen
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[TOPI] dense API to remove redudant use_bias (#476)
parent
833855e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
topi/python/topi/nn/dense.py
+10
-11
10 additions, 11 deletions
topi/python/topi/nn/dense.py
topi/tests/python/test_topi_dense.py
+1
-1
1 addition, 1 deletion
topi/tests/python/test_topi_dense.py
with
11 additions
and
12 deletions
topi/python/topi/nn/dense.py
+
10
−
11
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
This diff is collapsed.
Click to expand it.
topi/tests/python/test_topi_dense.py
+
1
−
1
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment