-
Notifications
You must be signed in to change notification settings - Fork 13
[TUZ-6] Add a direct Onnx to Relax Importer #14
Conversation
name = dim.dim_param | ||
value = dim.dim_value | ||
if value is None or value == 0: | ||
value = tvm.tir.Var("d", "int64") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why name the var "d"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we usually use 'd' for dynamic, although I'm not sure..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its just a stand-in dynamic shape. I've updated it to be dyn
for more clarity.
My overall high-level reactions (I will leave finer-grained comments in the code) from the perspective of documentation: Gut reaction for what docs we would expect
Specific reactions
How the importer should be tested
|
python/tvm/relax/op/manipulate.py
Outdated
|
||
|
||
@tvm.register_func("relax.run.broadcast_to") | ||
def torch_broadcast_to(data: tvm.nd.array, shape: tvm.nd.array) -> tvm.nd.array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely this is no longer needed if you can lower bcast to via emit_te
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, i dont think that lowering exists yet but as soon as it does we'll remove this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After taking a detailed look at the implementation, I've highlighted some areas in which the tests can be improved (many test cases do check all the branches, which is good). Overall, I stand by my earlier comments that there should be some outline of the overall structure of the converter. There should also be some explanation of how the existing Relay converter's methods are used (is that intended to remain permanently? Not sure it's good to depend on the Relay converter at all if we can avoid it, just another massive complication)
src/relax/op/tensor/manipulate.cc
Outdated
@@ -88,21 +88,22 @@ StructInfo InferStructInfoBroadcastTo(const Call& call, const BlockBuilder& ctx) | |||
const auto* old_len_int = old_len.as<IntImmNode>(); | |||
if (old_len_int != nullptr && old_len_int->value == 1) { | |||
continue; | |||
} else if (!analyzer->CanProveEqual(old_len, tgt_len)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why this was commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah this portion of code is specifically requiring shapes to be known and checking if those static shapes are compatible for broadcasting. My opinion is that we should not enforce that since dynamic broadcast_to shows up pretty frequently. This should be fully removed rather than commented out though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. The intent of the original code was to require using a MatchCast
to check the shape first. However, I agree with you that the operator implementation can do the checking, so that's unnecessary work for the user
check_correctness(model) | ||
|
||
|
||
def test_const(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be good to have tests for multiple types or for the edge case discussed in the implementation (not supporting strings)
converter, which should be `_impl_vx`. Number x is the biggest | ||
number smaller than or equal to opset belongs to all support versions. | ||
""" | ||
versions = [int(d.replace("_impl_v", "")) for d in dir(cls) if "_impl_v" in d] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might there be a simpler way to accomplish the dispatching by opset? E.g., as a property in the converter classes. Encoding it in the method names seems a little unusual. Is split the only operator that has multiple versions in this manner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, additionally, we should test the error case for rejecting an op due to version (we could test this function separately)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment -- yes, split is the only operator that has multiple versions. Probably in the future, this will not hold true.
I am not sure about using a different kind of encoding -- what is nice with this implementation is that each converter does not have to contain a different mapping opset version -> function implementation
@driazati, it looks like the build is failing due to the image not having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my principal concerns have been addressed and I thank those who made the changes. We can improve the documentation as we go along.
f36f4ea
to
1e14a30
Compare
* [Relax][Onnx] Implement Div, Sigmoid, Softmax, Transpose and Unsqueeze ops * skip test_reshape * [Relax][ONNX] Implement BiasGelu and Gelu ops * [Relax][ONNX] Implement Where op
…hape / Not / Tanh (#3) * Rebase w/ Equal, Not, Tanh, Sqrt, Relu, Clip, Conv, Pow, Erf. * Fix cumsum but still needs work.
* Add squeeze. * Add Constant. * Add sub.
…tend (#8) * [WIP] Support using Relay ops in the Relax ONNX frontend Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] small fixes Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] Support dynamic matmul and reshape Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Address PR comments --------- Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]>
* [WIP] add more ops. Some fail at the moment * skip some tests * Remove duplicate tests for squeeze
* [Relax][ONNX] Add Split op * Remove tmp
I'm going to merge this to help unblock other efforts. There are still a few CI related issues we should try to fix. Specifically, it seems like CI failed despite all tests passing because some of those tests triggered intentional errors. |
* Initial importer and testing scaffolding. * Implement matmul operator and tests. * Add a bunch of new operators. * Add new ops * [Relax][Onnx] Implement Div, Sigmoid, Softmax, Transpose and Unsqueeze ops * skip test_reshape * [Relax][ONNX] Implement BiasGelu and Gelu ops * [Relax][ONNX] Implement Where op * [Relax][ONNX] Add Multiple ONNX Frontend Support for Clip / Equal / Shape / Not / Tanh (#3) * Rebase w/ Equal, Not, Tanh, Sqrt, Relu, Clip, Conv, Pow, Erf. * Fix cumsum but still needs work. * Fix initializer for CumSum. (#9) * Add Constant, Squeeze & Sub (#10) * Add squeeze. * Add Constant. * Add sub. * Support reusing Relay ONNX operator convertors in the Relax ONNX frontend (#8) * [WIP] Support using Relay ops in the Relax ONNX frontend Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] small fixes Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] Support dynamic matmul and reshape Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Address PR comments --------- Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Add more ops (including all Reduce ops) using the relay frontend (#11) * [WIP] add more ops. Some fail at the moment * skip some tests * Remove duplicate tests for squeeze * Add Split op in the Relax ONNX frontend (#12) * [Relax][ONNX] Add Split op * Remove tmp * Fix layer normalizations and Shape operator. * Replace main loop with tvm testing. * Simplify Slice for opset 13. * [Relax][ONNX] Implement pad op * Incorporate pad op, add static constantofshape op. * Changes to shape to temporarily enable constantofshape in our models. * Add initial tensor_to_shape implementation. * Implemented dynamic broadcast_to to support expand and constantofshape. * Changes sufficient for vortex end to end run. * Formatting. * Format tests. * Re-add broadcast_to shape checking. * Fix formatting. * Remove overly strict manipulate check. * Fix typing * [Relax][Onnx] Implement Tile operator * Switch to native relax attention importer. * Address some of the PR comments * Check for the imported model IR version * switch from torch to numpy due to some incompatibility * Fix make format. * Clean up typing issues. * Clarify variable name. * Remove unneeded comprehension. * Remove circular dependency. * Add name sanitization for inputs * Disable reshape rewrite pass until fixed. * Fix long comment * Update cpu image. --------- Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: Xiyou Zhou <[email protected]> Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: sung <[email protected]>
* Initial importer and testing scaffolding. * Implement matmul operator and tests. * Add a bunch of new operators. * Add new ops * [Relax][Onnx] Implement Div, Sigmoid, Softmax, Transpose and Unsqueeze ops * skip test_reshape * [Relax][ONNX] Implement BiasGelu and Gelu ops * [Relax][ONNX] Implement Where op * [Relax][ONNX] Add Multiple ONNX Frontend Support for Clip / Equal / Shape / Not / Tanh (#3) * Rebase w/ Equal, Not, Tanh, Sqrt, Relu, Clip, Conv, Pow, Erf. * Fix cumsum but still needs work. * Fix initializer for CumSum. (#9) * Add Constant, Squeeze & Sub (#10) * Add squeeze. * Add Constant. * Add sub. * Support reusing Relay ONNX operator convertors in the Relax ONNX frontend (#8) * [WIP] Support using Relay ops in the Relax ONNX frontend Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] small fixes Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] Support dynamic matmul and reshape Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Address PR comments --------- Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Add more ops (including all Reduce ops) using the relay frontend (#11) * [WIP] add more ops. Some fail at the moment * skip some tests * Remove duplicate tests for squeeze * Add Split op in the Relax ONNX frontend (#12) * [Relax][ONNX] Add Split op * Remove tmp * Fix layer normalizations and Shape operator. * Replace main loop with tvm testing. * Simplify Slice for opset 13. * [Relax][ONNX] Implement pad op * Incorporate pad op, add static constantofshape op. * Changes to shape to temporarily enable constantofshape in our models. * Add initial tensor_to_shape implementation. * Implemented dynamic broadcast_to to support expand and constantofshape. * Changes sufficient for vortex end to end run. * Formatting. * Format tests. * Re-add broadcast_to shape checking. * Fix formatting. * Remove overly strict manipulate check. * Fix typing * [Relax][Onnx] Implement Tile operator * Switch to native relax attention importer. * Address some of the PR comments * Check for the imported model IR version * switch from torch to numpy due to some incompatibility * Fix make format. * Clean up typing issues. * Clarify variable name. * Remove unneeded comprehension. * Remove circular dependency. * Add name sanitization for inputs * Disable reshape rewrite pass until fixed. * Fix long comment * Update cpu image. --------- Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: Xiyou Zhou <[email protected]> Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: sung <[email protected]>
* Initial importer and testing scaffolding. * Implement matmul operator and tests. * Add a bunch of new operators. * Add new ops * [Relax][Onnx] Implement Div, Sigmoid, Softmax, Transpose and Unsqueeze ops * skip test_reshape * [Relax][ONNX] Implement BiasGelu and Gelu ops * [Relax][ONNX] Implement Where op * [Relax][ONNX] Add Multiple ONNX Frontend Support for Clip / Equal / Shape / Not / Tanh (#3) * Rebase w/ Equal, Not, Tanh, Sqrt, Relu, Clip, Conv, Pow, Erf. * Fix cumsum but still needs work. * Fix initializer for CumSum. (#9) * Add Constant, Squeeze & Sub (#10) * Add squeeze. * Add Constant. * Add sub. * Support reusing Relay ONNX operator convertors in the Relax ONNX frontend (#8) * [WIP] Support using Relay ops in the Relax ONNX frontend Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] small fixes Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * [WIP] Support dynamic matmul and reshape Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Address PR comments --------- Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> * Add more ops (including all Reduce ops) using the relay frontend (#11) * [WIP] add more ops. Some fail at the moment * skip some tests * Remove duplicate tests for squeeze * Add Split op in the Relax ONNX frontend (#12) * [Relax][ONNX] Add Split op * Remove tmp * Fix layer normalizations and Shape operator. * Replace main loop with tvm testing. * Simplify Slice for opset 13. * [Relax][ONNX] Implement pad op * Incorporate pad op, add static constantofshape op. * Changes to shape to temporarily enable constantofshape in our models. * Add initial tensor_to_shape implementation. * Implemented dynamic broadcast_to to support expand and constantofshape. * Changes sufficient for vortex end to end run. * Formatting. * Format tests. * Re-add broadcast_to shape checking. * Fix formatting. * Remove overly strict manipulate check. * Fix typing * [Relax][Onnx] Implement Tile operator * Switch to native relax attention importer. * Address some of the PR comments * Check for the imported model IR version * switch from torch to numpy due to some incompatibility * Fix make format. * Clean up typing issues. * Clarify variable name. * Remove unneeded comprehension. * Remove circular dependency. * Add name sanitization for inputs * Disable reshape rewrite pass until fixed. * Fix long comment * Update cpu image. --------- Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: Xiyou Zhou <[email protected]> Co-authored-by: Matthew Barrett <[email protected]> Co-authored-by: Michalis Papadimitriou <[email protected]> Co-authored-by: Florin Blanaru <[email protected]> Co-authored-by: sung <[email protected]>
This PR is the culmination of work for the Onnx importer epic. It implements a converter similar in spirit to the Onnx -> Relay importer and even reuses many of the operator converters directly. Other operators instead are converted by directly emitting tensorir functions using topi.
What should we put here?
What are the right tests to run?
This PR depends on importing onnx, how should we update CI to support new dependencies?