Coder Social home page Coder Social logo

Comments (6)

thiagocrepaldi avatar thiagocrepaldi commented on May 18, 2024

torch.onnx.export is based on TorchScript technilogy (aka torch.jit.script) which is not compatible with Dynamo by default

Instead, try using torch.onnx.dynamo_export to export models to ONNX based on either torch.nn.Module or Dynamo's graphs

Refer to the tutorial to get started at https://pytorch.org/tutorials/beginner/onnx/export_simple_model_to_onnx_tutorial.html

from pytorch.

srcarroll avatar srcarroll commented on May 18, 2024

@thiagocrepaldi thanks. i did try with dynamo_export too and almost positive i ran accross the same exact issue. i'll double check. nor doees this tutorial help at all with getting it to work with autograd. i can get torch.onnx.export working fine with dynamo, but without autograd

from pytorch.

srcarroll avatar srcarroll commented on May 18, 2024

I would be extremely grateful if you could point to an example of using aot_module with torch.onnx.dynamo_export. I've searched a lot and couldn't find one example anywhere. My assumption is that it's because it doesn't work. :P

from pytorch.

thiagocrepaldi avatar thiagocrepaldi commented on May 18, 2024

@xadupre and @wschin can help you in more depth, as they are the maintainers for the onnx backend on torch.compile

an untested repro would be something like

import torch

class Linear(torch.nn.Module):
    def __init__(self):
        super(Linear, self).__init__()
        self.linear = torch.nn.Linear(128, 10)
        self.activation = torch.nn.ReLU()

    def forward(self, *inputs):
        input = self.linear(inputs[0])
        input = self.activation(input)
        return input

model = Linear()
model.train()
loss_fn = torch.nn.MSELoss()

input = torch.randn((64, 128), requires_grad=True)
labels = torch.randn((64, 10), requires_grad=True)

compiled_model = torch.compile(model, backend="onnxrt")
output = compiled_model(*input)
loss = loss_fn(output, labels)
loss.backward()

from pytorch.

thiagocrepaldi avatar thiagocrepaldi commented on May 18, 2024

Refer to this https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html

from pytorch.

srcarroll avatar srcarroll commented on May 18, 2024

@thiagocrepaldi thanks again. i do know how to use torch.compile for inference, but i believe your example does not work for backward graph compilation. as i understand, that's what aot autograd is for.

it would be preferable to have something that works directly on module (either nn.Module or fx.GraphModule is fine) like aot_module is supposed to, but at this point i'd take any example that works with onnx (i have yet to see any non trivial examples). for example i've tried defining backward functions and compiling that with both torch.compile and aot_function but with no success. i look forward to hear what others suggest.

from pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.