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
8a9e65c7
Commit
8a9e65c7
authored
Oct 07, 2019
by
雾雨魔理沙
Committed by
Wuwei Lin
Oct 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add gradient for log-softmax (#4069)
parent
776fd6bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
python/tvm/relay/op/_tensor_grad.py
+9
-0
tests/python/relay/test_op_grad_level1.py
+9
-4
No files found.
python/tvm/relay/op/_tensor_grad.py
View file @
8a9e65c7
...
...
@@ -305,6 +305,15 @@ def softmax_grad(orig, grad):
return
[(
grad
-
_sum
(
grad
*
orig
,
orig
.
attrs
.
axis
,
True
))
*
orig
]
@register_gradient
(
"nn.log_softmax"
)
def
log_softmax_grad
(
orig
,
grad
):
"""Gradient of log_softmax"""
x
=
orig
.
args
[
0
]
sm
=
_nn
.
softmax
(
x
,
axis
=
orig
.
attrs
.
axis
)
grad
=
grad
/
sm
return
softmax_grad
(
sm
,
grad
)
@register_gradient
(
"nn.bias_add"
)
def
bias_add_grad
(
orig
,
grad
):
"""Returns gradient of bias_add"""
...
...
tests/python/relay/test_op_grad_level1.py
View file @
8a9e65c7
...
...
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import
numpy
as
np
import
pytest
import
tvm
from
tvm
import
relay
...
...
@@ -100,7 +101,13 @@ def test_binary_op():
def
test_softmax_grad
():
data
=
relay
.
var
(
"data"
,
relay
.
TensorType
((
1
,
16
),
"float64"
))
fwd_func
=
relay
.
Function
([
data
],
relay
.
nn
.
softmax
(
data
))
check_grad
(
fwd_func
)
check_grad
(
fwd_func
,
scale
=
1
)
def
test_log_softmax_grad
():
data
=
relay
.
var
(
"data"
,
relay
.
TensorType
((
2
,
16
),
"float64"
))
fwd_func
=
relay
.
Function
([
data
],
relay
.
nn
.
log_softmax
(
data
))
check_grad
(
fwd_func
,
scale
=
1
)
def
test_bias_add_grad
():
...
...
@@ -111,6 +118,4 @@ def test_bias_add_grad():
if
__name__
==
"__main__"
:
test_unary_op
()
test_binary_op
()
test_bias_add_grad
()
pytest
.
main
([
__file__
])
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