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

[torchlib] Allow calling shared functions from other onnx functions #834

Open
Tracked by #357
justinchuby opened this issue Jul 6, 2023 · 4 comments
Open
Tracked by #357
Labels
enhancement New feature or request topic: torch_lib Related to the torch/aten function lib in development
Milestone

Comments

@justinchuby
Copy link
Collaborator

Currently the torchscript evaluator does not support calling OnnxFunctions from within an OnnxFunction. We should enable this to allow shared implementations. To do this, we will need to keep references of the called functions inside an OnnxFunction.

@justinchuby justinchuby added the topic: torch_lib Related to the torch/aten function lib in development label Jul 6, 2023
@BowenBao
Copy link
Contributor

BowenBao commented Jul 7, 2023

Done by #725 ?

@justinchuby
Copy link
Collaborator Author

Ahh that’s right! I remember this pr but got a test error when I did this. I must have confused myself. Thanks!

@justinchuby
Copy link
Collaborator Author

justinchuby commented Jul 8, 2023

So we need to use add_module_call it seems? Looks like the graph builder is not handling cases where a function calls another (when using OnnxFunction to_function_proto).

I can think of two options:

  1. Create a new API in OnnxFunction to return a list of function protos used by the function (recursively) (deduplication would be an issue)
  2. Record the functions in the Graph on the fly Record OnnxFunctions in called functions #629
  3. Do what to_model_proto does (I haven't looked)

@BowenBao
Copy link
Contributor

@justinchuby We don't need add_module_call for this, the rest makes sense. There is existing api IRFunction.to_graph_and_functions / IRFunction.called_functions used by OnnxFunction.to_model_proto to grab inner functions. I believe all we need is exposing the api at OnnxFunction level and use it in TorchScriptGraph.add_function_call.

@justinchuby justinchuby added the enhancement New feature or request label Aug 4, 2023
@justinchuby justinchuby added this to the 0.2 milestone Aug 31, 2023
justinchuby added a commit that referenced this issue Oct 24, 2023
This change introduces two shared operators `Rank` and `IsScalar`. They
are used to replace the `Size(Shape())` pattern for code reuse and
readability.

I used a hack to always include these shared functions in the model
proto because without #834 we cannot dynamically add these functions to
the model as they are used. I added a TODO for this.

The first usage is in `aten_all`. I will update the rest of the
functions in a separate PR.

#1095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic: torch_lib Related to the torch/aten function lib in development
Projects
None yet
Development

No branches or pull requests

2 participants