forked from llvm/torch-mlir
-
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.
Add minimal support for Union types.
A recent PyTorch commit made ConstantPad2d call a helper function with a `Union[int, float]` type annotated. This commit adds minimal support for representing and dealing with that. pytorch/pytorch#73287 Changes: - Adding support for `!torch.union<T1, T2, T3>`/`Torch::UnionType`, along with the importer and CAPI code. - Add support in isValidSubtype for union types. - Adding a canonicalizer for `torch.derefine` to help simplify some code that derefines to a UnionType (this also fixes llvm#664). There is still more work to do for really supporting UnionType well, such as canonicalizing UnionType's so that they can be compared with pointer equality.
- Loading branch information
Showing
11 changed files
with
189 additions
and
19 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
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
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
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,24 @@ | ||
# -*- Python -*- | ||
# This file is licensed under a pytorch-style license | ||
# See LICENSE.pytorch for license information. | ||
|
||
from typing import Union | ||
|
||
import torch | ||
from torch_mlir.dialects.torch.importer.jit_ir import ModuleBuilder | ||
|
||
# RUN: %PYTHON %s | torch-mlir-opt | FileCheck %s | ||
|
||
mb = ModuleBuilder() | ||
|
||
# CHECK-LABEL: func @__torch__.f( | ||
# CHECK-SAME: %{{.*}}: !torch.union<float, int>) -> !torch.none { | ||
|
||
@mb.import_function | ||
@torch.jit.script | ||
def f(x: Union[int, float]): | ||
return | ||
|
||
assert isinstance(f, torch.jit.ScriptFunction) | ||
mb.module.operation.print() | ||
print() |