-
Notifications
You must be signed in to change notification settings - Fork 92
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
C++ ONNX parser performance issues #754
Comments
Hi @MatthewDaggitt , I think we do want to fix this performance issue. If on the small network I sent, parsing is already taking 20+ seconds it's not a good sign. I would be in favor of depending on an existing Tensor library. Do you think it'd be helpful to go to Pytorch or Tensorflow? While this might be a overkill for parsing, it would lay a good foundation for our future agenda of incorporating gradient-based method. We also need to look at the license of the library we choose. Maybe something to discuss next week. |
I'm not sure whether Pytorch or Tensorflow would help. We need efficient access to array operations over arbitrary-dimension C++ arrays, but I suspect the overhead of setting up an entire Pytorch/Tensorflow neural network just to compute them won't be worth it. Maybe I've misunderstood their capabilities though? I have found that
If we implement it ourselves this looks useful: Otherwise a third party library might be: |
I was suggesting using Pytoch/Tensorflow just for Tensor computation. From pytorch's documentation, they support general operations over tensors independent of machine learning. Though I haven't looked closely at it.. https://pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html |
Ah I didn't realise they supported pure tensor operations as well, although it makes perfect sense when you think about it. Having said that the C++ Pytorch documentation is very minimal (https://pytorch.org/cppdocs/api/namespace_at.html#namespace-at) but I guess it's workable with. |
@MatthewDaggitt , it'd be great if Pytorch is workable. That'd lay a great foundation for our future development work. Their license also seems quite permissive: https://github.com/pytorch/pytorch/blob/main/LICENSE |
Hmm so Pytorch is now being included fine, but I'm running into the problem that it also defines a |
I'm not sure we have a protocol for this.. The solution below seems sensible..? @guykatzz , do you have any suggestions about resolving conflict of macro definition? |
@MatthewDaggitt actually I just recall we have encountered similar issues, and undefining the clashing operations seem to be the solution. Marabou/src/engine/MaxConstraint.cpp Lines 29 to 32 in 8129640
|
Okay after much suffering I think I've finally got The whole experience has really made me really appreciate the sane package managers and hygenic scoping of more modern languages. The next step is now to try and actually use Torch to handle the tensors... |
I was over optimistic in my last comment. Unfortunately it seems like the act of simply adding the import @wu-haoze any chance you could confirm its the same on your machine? If you pull the branch |
Hmm you don't even have to include it in the header to trigger the problem. Simply linking against it is enough to degrade performance. I've asked a question on stack overflow here: 🤞 we get a useful answer |
My personal contact also says:
|
I tried it on my end and observed the same phenomenon. |
Does linking to the library at runtime requires building a dynamically linked pytorch library? |
I suspect so, but I'm unsure if that would solve the problem? Surely we'd have a similar bootup time whenever we imported the module instead? Which we always will thanks to the proposed dependency on ONNX... |
Okay I've been playing around with this some more, and I haven't found a way of avoiding the start-up cost. Having said that I've failed to get PyTorch to build from source. What are your opinions @wu-haoze? Is increasing the flat start-up time of Marabou by 2 seconds acceptable? |
I don't think we want to increase the start-up time by 2 seconds. |
I agree with Clark. Several use cases of Marabou involve solving short running queries many many times, and a 2 second start up time would be too much. :(
在 2024年3月20日,18:28,MatthewDaggitt ***@***.***> 写道:
Okay I've been playing around with this some more, and I haven't found a way of avoiding the start-up cost. Having said that I've failed to get PyTorch to build from source. What are your opinions @wu-haoze<https://github.com/wu-haoze>? Is increasing the flat start-up time of Marabou by 2 seconds acceptable?
—
Reply to this email directly, view it on GitHub<#754 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACRZF236DE2DDBU3R6C46B3YZIZUNAVCNFSM6AAAAABDLXKCFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJRGAYTSOJWGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Follow up from #744 (see the example network).
The C++ parser is currently slower than the ONNX one because my crude implementation of multi-dimensional tensors is not as elegant as those in numpy. In particular the two offending operations are
transpose
andMarabou/src/input_parsers/TensorUtils.h
Lines 80 to 89 in 571748e
and the all the lookups and broadcasting done here:
Marabou/src/input_parsers/OnnxParser.cpp
Lines 1637 to 1646 in 571748e
I'm a bit torn on how to address this. I can either continue to refine the tensor representation to incorporate strides which allows us to perform these operations much cheaper, or start to depend on an existing tensor library. For the latter case I'm not quite sure what I would use...
The text was updated successfully, but these errors were encountered: