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] Add shape check for ConcatenateRel and StackRel #3699

Merged
merged 16 commits into from
Sep 18, 2019
Merged

[Relay] Add shape check for ConcatenateRel and StackRel #3699

merged 16 commits into from
Sep 18, 2019

Conversation

Lyken17
Copy link
Contributor

@Lyken17 Lyken17 commented Aug 2, 2019

As discussed in [Relay][Concatenate] Missing shape checking for non-concat axes, it is better to add shape checking in the relay. This pull request aims to complete the missing shape checking for non-concating / non-stacking axes.

@slyubomirsky
Copy link
Contributor

Would it be possible to have test cases/regressions?

@Lyken17
Copy link
Contributor Author

Lyken17 commented Aug 3, 2019

Would it be possible to have test cases/regressions?

Yes, I can add test cases. Where can I find some examples (of test cases)?

Between, currently I am using reporter->AssertEQ when performing the check in Rel. But in topi:compute, there is no reporter. How can I compare two tvm::Expr?

@Lyken17
Copy link
Contributor Author

Lyken17 commented Aug 5, 2019

@slyubomirsky
Copy link
Contributor

slyubomirsky commented Aug 6, 2019

They could be like those, or tests in Python (see tests/python/relay/test_op_level[*].py)

@Lyken17
Copy link
Contributor Author

Lyken17 commented Aug 6, 2019

Concatenate is a fundamental operator so it should at level 1. Is my understanding correct?

@Lyken17
Copy link
Contributor Author

Lyken17 commented Aug 6, 2019

@slyubomirsky I have just added a test case. Please check.

Also, I note there is no check to stack relay. Consider the similar functionality of stack / concatenate, do you think it is necessary to add one?

y = relay.var('p2', shape=(2, 3))
c = relay.concatenate([x, y], axis=0)
func = relay.Function([x, y], c)
relay_module = relay.Module.from_expr(func)
Copy link
Member

Choose a reason for hiding this comment

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

Are you implicitly inferring type here? Should we have some assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain more here? Current action here is similar to run_infer_type() used in other tests.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I am saying that type inference implicit here when creating a module. We probably prefer to invoke run_infer_type directly and check the expected type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. But one weird thing I met is, if I use run_infer_type(), then no error is thrown

# no error 
x = relay.var('p1', shape=(2, 5))
y = relay.var('p2', shape=(2, 3))
z = relay.concatenate([x, y], axis=1)
zz = run_infer_type(z)

# throws tvm.Error
x = relay.var('p1', shape=(2, 5))
y = relay.var('p2', shape=(2, 3))
z = relay.concatenate([x, y], axis=1)
func = relay.Function([x, y], c)
zz = run_infer_type(func)

While run_infer_type() is

def run_infer_type(expr):
    mod = relay.Module.from_expr(expr)
    mod = transform.InferType()(mod)
    entry = mod["main"]
    return entry if isinstance(expr, relay.Function) else entry.body

It seems we have to pack it into a relay.Function then the error can be detected.

Copy link
Contributor

@slyubomirsky slyubomirsky Aug 8, 2019

Choose a reason for hiding this comment

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

That seems very strange, since module.from_expr is supposed to pack a non-function into a function anyway (see https://github.com/dmlc/tvm/blob/master/src/relay/ir/module.cc#L232).

Copy link
Contributor

@slyubomirsky slyubomirsky Aug 8, 2019

Choose a reason for hiding this comment

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

I checked out your branch and tried running the example you gave myself and did not get an error in either case, so I'm not sure what problem you might have had. Was there a problem before that you fixed?

src/relay/op/tensor/transform.cc Outdated Show resolved Hide resolved
src/relay/op/tensor/transform.cc Outdated Show resolved Hide resolved
src/relay/op/tensor/transform.cc Outdated Show resolved Hide resolved
src/relay/op/tensor/transform.cc Outdated Show resolved Hide resolved
@slyubomirsky
Copy link
Contributor

Thanks for writing tests, I will look it over when I get a chance.

@slyubomirsky
Copy link
Contributor

slyubomirsky commented Aug 8, 2019

Looks good to me, especially after Zhi's recommended changes. I think there should be a test for stack, since it was also modified by these changes (definitely an oversight that there wasn't one already).

@jroesch jroesch added status: need update need update based on feedbacks status: need review labels Sep 1, 2019
@tqchen
Copy link
Member

tqchen commented Sep 13, 2019

ping @Lyken17 can you look into the CI error?

@Lyken17
Copy link
Contributor Author

Lyken17 commented Sep 15, 2019

@tqchen Sorry the delay I will have a look at the CI error.

Seems the change lead to doc build failed on ssd example. But I cannot reproduce on local laptop.

generating gallery for tutorials/frontend... [  8%] from_onnx.py

generating gallery for tutorials/frontend... [ 16%] from_coreml.py

generating gallery for tutorials/frontend... [ 25%] deploy_ssd_gluoncv.py


Segmentation fault: 11



Stack trace:

  [bt] (0) /usr/local/lib/python3.6/dist-packages/mxnet/libmxnet.so(+0x2b64150) [0x7f71ead82150]

  [bt] (1) /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f72814114b0]

  [bt] (2) /workspace/build/libtvm.so(tvm::relay::GetValidCountRel(tvm::Array<tvm::relay::Type, void> const&, int, tvm::Attrs const&, tvm::relay::TypeReporter const&)+0x18b) [0x7f72651511eb]

  [bt] (3) /workspace/build/libtvm.so(std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), void tvm::runtime::TypedPackedFunc<bool (tvm::Array<tvm::relay::Type, void> const&, int, tvm::Attrs const&, tvm::relay::TypeReporter const&)>::AssignTypedLambda<bool (*)(tvm::Array<tvm::relay::Type, void> const&, int, tvm::Attrs const&, tvm::relay::TypeReporter const&)>(bool (*)(tvm::Array<tvm::relay::Type, void> const&, int, tvm::Attrs const&, tvm::relay::TypeReporter const&))::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)+0xd4) [0x7f7265008dd4]

  [bt] (4) /workspace/build/libtvm.so(tvm::relay::TypeSolver::Solve()+0x4e1) [0x7f7265176571]

  [bt] (5) /workspace/build/libtvm.so(tvm::relay::TypeInferencer::Infer(tvm::relay::Expr)+0x55) [0x7f7265183cc5]

  [bt] (6) /workspace/build/libtvm.so(tvm::relay::InferType(tvm::relay::Function const&, tvm::relay::Module const&, tvm::relay::GlobalVar const&)+0x33f) [0x7f726518513f]

  [bt] (7) /workspace/build/libtvm.so(tvm::relay::ModuleNode::Add(tvm::relay::GlobalVar const&, tvm::relay::Function const&, bool)+0x344) [0x7f7264fffc04]

  [bt] (8) /workspace/build/libtvm.so(tvm::relay::ModuleNode::FromExpr(tvm::relay::Expr const&, tvm::Map<tvm::relay::GlobalVar, tvm::relay::Function, void, void> const&, tvm::Map<tvm::relay::GlobalTypeVar, tvm::relay::TypeData, void, void> const&)+0x18f) [0x7f7265001fbf]

make: *** [html] Error 255

Makefile:70: recipe for target 'html' failed

script returned exit code 2

@tqchen
Copy link
Member

tqchen commented Sep 16, 2019

could it has something to do with the mxnet version? The error seems does correlates with the concat op if that helps

@Lyken17
Copy link
Contributor Author

Lyken17 commented Sep 17, 2019

@tqchen I have resolved the CI issue. Can you have a check?

@Lyken17
Copy link
Contributor Author

Lyken17 commented Sep 18, 2019

seems tianqi is busy. @zhiics @jroesch @slyubomirsky can u have a check?

src/relay/op/tensor/transform.h Outdated Show resolved Hide resolved
src/relay/op/tensor/transform.cc Outdated Show resolved Hide resolved
Copy link
Member

@zhiics zhiics left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiics zhiics merged commit cdbf4d8 into apache:master Sep 18, 2019
@zhiics zhiics added status: accepted and removed status: need review status: need update need update based on feedbacks labels Sep 18, 2019
tqchen pushed a commit to tqchen/tvm that referenced this pull request Sep 20, 2019
* [Relay] add shape check for concat

* [Relay] add shape check for stack

* add test case for shape mismatch

* [typo] add the missing assert

* fix lint errors.

* replace int with size_t.

* statically cast param->axis to size_t.

* switch to run_infer_type.

* fix checking for negative index

* add static_cast for param->axis

* merge to latest tvm

* fix lint error

* Fix an error with negative index.

* Update transform.h

* Update transform.cc
wweic pushed a commit to wweic/tvm that referenced this pull request Sep 30, 2019
* [Relay] add shape check for concat

* [Relay] add shape check for stack

* add test case for shape mismatch

* [typo] add the missing assert

* fix lint errors.

* replace int with size_t.

* statically cast param->axis to size_t.

* switch to run_infer_type.

* fix checking for negative index

* add static_cast for param->axis

* merge to latest tvm

* fix lint error

* Fix an error with negative index.

* Update transform.h

* Update transform.cc
wweic pushed a commit to wweic/tvm that referenced this pull request Sep 30, 2019
* [Relay] add shape check for concat

* [Relay] add shape check for stack

* add test case for shape mismatch

* [typo] add the missing assert

* fix lint errors.

* replace int with size_t.

* statically cast param->axis to size_t.

* switch to run_infer_type.

* fix checking for negative index

* add static_cast for param->axis

* merge to latest tvm

* fix lint error

* Fix an error with negative index.

* Update transform.h

* Update transform.cc
wweic pushed a commit to neo-ai/tvm that referenced this pull request Oct 1, 2019
* [Relay] add shape check for concat

* [Relay] add shape check for stack

* add test case for shape mismatch

* [typo] add the missing assert

* fix lint errors.

* replace int with size_t.

* statically cast param->axis to size_t.

* switch to run_infer_type.

* fix checking for negative index

* add static_cast for param->axis

* merge to latest tvm

* fix lint error

* Fix an error with negative index.

* Update transform.h

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

Successfully merging this pull request may close these issues.

5 participants