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
d0c45648
Commit
d0c45648
authored
Jun 12, 2019
by
Jared Roesch
Committed by
Tianqi Chen
Jun 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay][Backend] Fix interpreter argument conversion for tuples. (#3349)
* Support taking a tuple as an argument * Add test
parent
499adfdb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
python/tvm/relay/backend/interpreter.py
+2
-0
tests/python/relay/test_backend_interpreter.py
+26
-0
No files found.
python/tvm/relay/backend/interpreter.py
View file @
d0c45648
...
...
@@ -118,6 +118,8 @@ def _arg_to_ast(arg):
return
Constant
(
arg
.
data
.
copyto
(
nd
.
cpu
(
0
)))
elif
isinstance
(
arg
,
TupleValue
):
return
Tuple
([
_arg_to_ast
(
field
)
for
field
in
arg
.
fields
])
elif
isinstance
(
arg
,
tuple
):
return
Tuple
([
_arg_to_ast
(
field
)
for
field
in
arg
])
elif
isinstance
(
arg
,
RefValue
):
return
RefCreate
(
_arg_to_ast
(
arg
.
value
))
elif
isinstance
(
arg
,
ConstructorValue
):
...
...
tests/python/relay/test_backend_interpreter.py
View file @
d0c45648
...
...
@@ -217,6 +217,31 @@ def test_function_taking_adt_ref_tuple():
tvm
.
testing
.
assert_allclose
(
res_tuple
.
fields
[
i
]
.
asnumpy
(),
tuple_value
.
fields
[
i
]
.
asnumpy
())
def
test_tuple_passing
():
x
=
relay
.
var
(
'x'
,
type_annotation
=
relay
.
ty
.
TupleType
([
relay
.
ty
.
TensorType
((),
'int64'
),
relay
.
ty
.
TensorType
((),
'int64'
)]))
fn
=
relay
.
Function
([
x
],
relay
.
expr
.
TupleGetItem
(
x
,
0
))
mod
=
relay
.
Module
({})
gv
=
relay
.
GlobalVar
(
'fn'
)
mod
[
gv
]
=
fn
mod
.
entry_func
=
gv
mod
[
gv
]
=
relay
.
ir_pass
.
infer_type
(
mod
[
gv
],
mod
=
mod
)
ctx
=
tvm
.
cpu
()
target
=
tvm
.
target
.
create
(
'llvm'
)
exec
=
relay
.
create_executor
(
mod
=
mod
,
ctx
=
ctx
,
target
=
target
)
f
=
exec
.
evaluate
(
gv
)
# First use a Python tuple.
out
=
f
((
10
,
8
))
tvm
.
testing
.
assert_allclose
(
out
.
asnumpy
(),
np
.
array
(
10
))
# Second use a tuple value.
value_tuple
=
TupleValue
(
TensorValue
(
np
.
array
(
11
)),
TensorValue
(
np
.
array
(
12
)))
out
=
f
(
value_tuple
)
tvm
.
testing
.
assert_allclose
(
out
.
asnumpy
(),
np
.
array
(
11
))
if
__name__
==
"__main__"
:
test_id
()
...
...
@@ -232,3 +257,4 @@ if __name__ == "__main__":
test_tuple_value
()
test_tuple_getitem
()
test_function_taking_adt_ref_tuple
()
test_tuple_passing
()
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