-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
12 deletions.
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
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 |
---|---|---|
|
@@ -22,3 +22,5 @@ matplotlib | |
mlp_mixer_pytorch | ||
opencv-python | ||
xlsxwriter | ||
onnx | ||
onnxruntime |
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,25 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import torch | ||
from torch import nn | ||
import pytest | ||
|
||
import tt_torch | ||
from tt_torch.tools.verify import verify_module | ||
from tt_torch.tools.utils import CompilerConfig | ||
|
||
|
||
def test_add(): | ||
class Basic(nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, x, y): | ||
return torch.add(x, y) | ||
|
||
torch_model = Basic() | ||
torch_input = (torch.randn(256, 256), torch.randn(256, 256)) | ||
torch.onnx.export(torch_model, torch_input, "add.onnx") | ||
|
||
verify_module("add.onnx") |
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
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
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,4 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from .onnx_compile import compile_onnx |
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,31 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import onnx | ||
from torch_mlir.extras import onnx_importer | ||
import tt_mlir | ||
from torch_mlir.ir import Context | ||
from torch_mlir.dialects import torch as torch_dialect | ||
|
||
from torch_mlir.compiler_utils import ( | ||
OutputType, | ||
run_pipeline_with_repro_report, | ||
lower_mlir_module, | ||
) | ||
|
||
|
||
def compile_onnx(module: onnx.ModelProto): | ||
context = Context() | ||
torch_dialect.register_dialect(context) | ||
module_info = onnx_importer.ModelInfo(module) | ||
module = module_info.create_module(context=context).operation | ||
imp = onnx_importer.NodeImporter.define_function(module_info.main_graph, module) | ||
imp.import_all() | ||
|
||
run_pipeline_with_repro_report( | ||
module, | ||
"builtin.module(torch-onnx-to-torch-backend-pipeline)", | ||
"Lowering Torch Onnx IR -> Torch Backend IR", | ||
) | ||
lower_mlir_module(False, OutputType.STABLEHLO, module) | ||
return tt_mlir.compile(module.operation.get_asm()) |
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