-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) This commit adds support for passing to `torch_mlir.compile` the result of running `torch.jit.trace` on a model by relaxing the condition that checks if the model is already in JIT IR to allow any `torch.jit.ScriptModule`. Fixes #1739
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# Also available under a BSD-style license. See LICENSE. | ||
|
||
# RUN: %PYTHON %s | FileCheck %s | ||
|
||
import torch | ||
import torch_mlir | ||
|
||
class BasicModule(torch.nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.sin(x) | ||
|
||
example_arg = torch.ones(2, 3) | ||
example_args = torch_mlir.ExampleArgs.get(example_arg) | ||
|
||
traced = torch.jit.trace(BasicModule(), example_arg) | ||
print(torch_mlir.compile(traced, example_args)) | ||
# CHECK: module | ||
# CHECK-DAG: func.func @forward | ||
|
||
traced = torch.jit.trace(BasicModule(), example_arg) | ||
try: | ||
# CHECK: Model does not have exported method 'nonexistent', requested in `example_args`. Consider adding `@torch.jit.export` to the method definition. | ||
torch_mlir.compile(traced, torch_mlir.ExampleArgs().add_method("nonexistent", example_arg)) | ||
except Exception as e: | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters