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

Implement torchscript as a graph backend #273

Closed
justinchuby opened this issue Jan 4, 2023 · 4 comments · Fixed by #336
Closed

Implement torchscript as a graph backend #273

justinchuby opened this issue Jan 4, 2023 · 4 comments · Fixed by #336
Assignees
Labels
topic: torch_lib Related to the torch/aten function lib in development

Comments

@justinchuby
Copy link
Contributor

To use onnxscript APIs for constructing graphs in pytorch, we would like to create a version that uses torchscript as the graph IR. To do this, we probably need

  1. Implement an Evaluator that calls g.op to add ops and functions as nodes
  2. Implement a Tensor that wraps around the torch.Values
@titaiwangms
Copy link
Contributor

titaiwangms commented Jan 11, 2023

1/11 meeting log:

  1. Use context.manager to execute evaluator switch
  2. implement kwargs adapter
  3. Demo on multiple ops model (MUST use atenlib, which is ONNXFunction)

Future consideration:

  1. Tensor adapter
  2. Build the graph from scratch with onnxscript API

@gramalingam
Copy link
Collaborator

Just noting down a question here, hopefully our meeting later today will answer that: is the intention to have:

(i) a way of building torch IR using pythonic syntax (just like onnxscript), or
(ii) To have a deeper integration with onnxscript?

I am guessing it should be (i). In particular, do we ever expect core onnxscript to call the torch evaluator? I am assuming not.

@justinchuby
Copy link
Contributor Author

@titaiwangms for now, an aten function can be called like

from onnxscript.function_libs.torch_aten import ops

ops.core.aten_add()

@titaiwangms
Copy link
Contributor

@titaiwangms for now, an aten function can be called like

from onnxscript.function_libs.torch_aten import ops

ops.core.aten_add()

ops doesn't have module core, could you check on that? I am importing
from onnxscript.function_libs.torch_aten.ops import core

justinchuby added a commit that referenced this issue Feb 7, 2023
An evaluator using onnxscript API to build graph using torchscript (we
will have our own graph to replace torchscript.)

works with pytorch/pytorch#92717

1. Op object triggers graph_eval instead of eval to begin op insertion
for the graph (Need to figure out how to keep both functionality if they
need to stay on the same API.)
2. TorchscriptEvaluator serves as a manager of input/output graph. In
this demo, both of them are torchscript, so this class seems simple
(should be more complicated depending on ONNX graph builder API and
format requirements).
3. tensor.py is not modified because onnxscript does not really use the
graph value. That is, it will only have to be compatible with graph
builder type only in the future implementation.

Fixes #273

---------

Co-authored-by: AllenTiTaiWang <titaiwang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: torch_lib Related to the torch/aten function lib in development
Projects
3 participants