Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELAY][ONNX] Support Deriving channels when it is not provided in AlterLayout. #2972

Merged
merged 1 commit into from
Apr 17, 2019
Merged

Conversation

cbalint13
Copy link
Contributor

Dear All,

I propose this patch that address issue #2941 and all related to subject of altering conv2d layout.

  • Patch was tested with THIS on: arm, mali, x86 and cuda.
  • It is based on already implemented infer_channels().

@tqchen tqchen added the status: need test case need test cases to cover the change label Apr 5, 2019
@tqchen
Copy link
Member

tqchen commented Apr 5, 2019

Thanks for the contribution, please add a regression test case as per https://docs.tvm.ai/contribute/code_review.html#ensure-test-coverage

@cbalint13
Copy link
Contributor Author

@tqchen & All,

Added testcases, with some comments:

  • The test case goes through all known alter_conv2d variants by iterating on target contexts and try to count the mull-accumulate amount after the possible optimization.
  • Currently on intel-cpu and intel-gpu the mac_count() returns zero (i think it's a bug, will try fix it in other PR) so the extra assert check is skipped for these cases.
  • The optimize will fail if one particular alter_conv2d is doing something odd so asserts on mac-accumulate counts are just bonus double check.

@cbalint13
Copy link
Contributor Author

@merrymercy , @tqchen ,

Regarding testcase:

  • Initial thought was to count MAC, but realized tvm can count only for nn.conv2d
  • For now I added an assertion that graph should be different, MAC comparasion is a ToDo

@merrymercy merrymercy removed the status: need test case need test cases to cover the change label Apr 17, 2019
@merrymercy
Copy link
Member

merrymercy commented Apr 17, 2019

LGTM. Only some nits. You can batch my suggestions and commit them.

@cbalint13
Copy link
Contributor Author

LGTM. Only some nits. You can batch my suggestions and commit them.

It is done, committed the suggestion comment even in +one more place, now all are covered.

@merrymercy merrymercy merged commit c91f714 into apache:master Apr 17, 2019
@merrymercy
Copy link
Member

@cbalint13 @tqchen Thanks. It is merged!

@@ -327,11 +327,16 @@ def _alter_conv2d_layout(attrs, inputs, tinfo, F):

copy_inputs = [s for s in inputs]
new_attrs = {k : attrs[k] for k in attrs.keys()}

if F == tvm.relay.op:
Copy link
Contributor

@apivovarov apivovarov Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merrymercy @cbalint13 This call fails if user uses nnvm.compiler.build. You need to import relay from tvm first. It fails only for nnvm.compiler.build, not for relay.build

Compile using nnvm...
Traceback (most recent call last):
  File "./compile.py", line 62, in <module>
    graph, lib, params = nnvm.compiler.build(sym, target, shape={"data": data_shape}, dtype=dtype, params=params, target_host=target_host)
  File "/usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/compiler/build_module.py", line 297, in build
    graph = optimize(graph, shape, dtype, layout)
  File "/usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/compiler/build_module.py", line 186, in optimize
    graph = graph.apply(["InferShape", "InferType", "AlterOpLayout"])
  File "/usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/graph.py", line 250, in apply
    check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
  File "/usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/_base.py", line 91, in check_call
    raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: AttributeError: module 'tvm' has no attribute 'relay'
Stack trace:
    if F == tvm.relay.op:
  File "/usr/local/lib/python3.6/dist-packages/topi-0.6.dev0-py3.6.egg/topi/x86/conv2d.py", line 331, in _alter_conv2d_layout
    return dispatch_dict[k](*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/target.py", line 372, in dispatch_func
  File "</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-18>", line 2, in conv2d_alter_layout
    return topi.nn.conv2d_alter_layout(attrs, inputs, tinfos, sym)
  File "/usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/top/nn.py", line 194, in alter_conv2d_layout
  File "tvm/_ffi/_cython/./function.pxi", line 55, in tvm._ffi._cy3.core.tvm_callback
Stack trace:
  [bt] (0) /usr/local/lib/python3.6/dist-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x8e7f8b) [0x7f2ecdc9af8b]
  [bt] (1) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0x12ab65) [0x7f2ec8404b65]
  [bt] (2) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0xe5623) [0x7f2ec83bf623]
  [bt] (3) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0xe7c93) [0x7f2ec83c1c93]
  [bt] (4) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0xea0c9) [0x7f2ec83c40c9]
  [bt] (5) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0xc0800) [0x7f2ec839a800]
  [bt] (6) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(+0x85a11) [0x7f2ec835fa11]
  [bt] (7) /usr/local/lib/python3.6/dist-packages/nnvm-0.8.0-py3.6.egg/nnvm/libnnvm_compiler.so(NNGraphApplyPasses+0x320) [0x7f2ec833df00]
  [bt] (8) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c) [0x7f2eee480dae]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apivovarov ,

  • Could make it in a new PR ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we had nnvm compilation tests then your PR would not pass CI tests and you needed to fix your code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apivovarov ,

Agree.

  • Will add as a new PR today, with testcase using nnvm symbols instead of relay.op
  • I'll keep you on Cc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbalint13 I'm not sure we want to import relay if user decided to use nnvm.compiler.build.
Can we use string comparison here? e.g.

if F.__name__ == 'tvm.relay.op':

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue discussion in
#3044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants