-
Notifications
You must be signed in to change notification settings - Fork 516
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
[custom op] Generalize shape library logic to work with dtypes #1594
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round of comments. Overall looks good. Will probably have a few more nits after these are addressed but not much more than that.
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/testing_framework.py
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/testing_framework.py
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/csrc/node_importer.cpp
Outdated
Show resolved
Hide resolved
cd6fd6f
to
1a31c0b
Compare
@silvasean, I've addressed the comments in separate commits. Also, I had to make this change to make all tests pass: a24b7c6. The commit message (pasted below) has the explanation:
|
I think that before we land this we should fix this so that the iterative lowering behaves as intended here (perhaps as easy as switching DecomposeComplexOps to use the greedy rewriter? and then perhaps move the final legality check into satisfiesBackendContract somehow?). That seems like an independently useful improvement as well as the right thing to do here. I would generally bias pretty heavily against keeping the old path in RefineTypes alive unless absolutely necessary -- when we migrate an op, we should delete the old support. That guarantees monotonic progress towards the new system by making the new system load-bearing. If the old system still works for these ops, it is easy to add support for ops in the new system, but the e2e test is still ends up using the old system for some reason and so weren't even testing the new code -- thus we accumulate buggy, untested code in the new system. |
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/library_generator.py
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/library_generator.py
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/library_generator.py
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/library_generator.py
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/registry.py
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/testing_framework.py
Outdated
Show resolved
Hide resolved
lib/Dialect/Torch/Transforms/ReifyAbstractInterpCalculationsUtils.h
Outdated
Show resolved
Hide resolved
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/abstract_interp_lib_gen.py
Outdated
Show resolved
Hide resolved
1a31c0b
to
de0bc05
Compare
This commit generalizes the shape library logic, so that dtype rules for ops can also be expressed using the same mechanism. In other words, each op can now have a shape function and a dtype function specified in Python that is imported during lowering to calculate the shapes and dtypes throught a program. For more information about how to specify a dtype function, see the updated `docs/adding_a_shape_and_dtype_function.md`. For those not familiar with how the shape library works, the file `docs/calculations_lib.md` provides an overview.
de0bc05
to
89c6332
Compare
I've replaced two of the ops I was using ( While running The best approach for moving those common ops into the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :) Let's do this!
…1594) * [custom op] Generalize shape library logic to work with dtypes This commit generalizes the shape library logic, so that dtype rules for ops can also be expressed using the same mechanism. In other words, each op can now have a shape function and a dtype function specified in Python that is imported during lowering to calculate the shapes and dtypes throught a program. For more information about how to specify a dtype function, see the updated `docs/adding_a_shape_and_dtype_function.md`. For those not familiar with how the shape library works, the file `docs/calculations_lib.md` provides an overview.
This commit generalizes the shape library logic, so that dtype rules
for ops can also be expressed using the same mechanism. In other
words, each op can now have a shape function and a dtype function
specified in Python that is imported during lowering to calculate the
shapes and dtypes throught a program. For more information about how
to specify a dtype function, see the updated
docs/adding_a_shape_and_dtype_function.md
.For those not familiar with how the shape library works, the file
docs/calculations_lib.md
provides an overview.To make the reviewing a bit easier, I suggest the following review
order:
Get familiar with the overall architecture by reading
docs/calculations_lib.md
New op declarations
include/torch-mlir/Dialect/Torch/IR/TorchOps.td
lib/Dialect/Torch/IR/TorchOps.cpp
New passes
include/torch-mlir/Dialect/Torch/Transforms/Passes.td
include/torch-mlir/Dialect/Torch/Transforms/Passes.h
lib/Dialect/Torch/Transforms/Passes.cpp
lib/Dialect/Torch/Transforms/ReifyDtypeCalculations.cpp
lib/Dialect/Torch/Transforms/SimplifyDtypeCalculations.cpp
lib/Dialect/Torch/Transforms/ReifyCalculationsUtils.cpp
lib/Dialect/Torch/Transforms/ReifyCalculationsUtils.h
lib/Dialect/Torch/Transforms/SimplifyCalculationsUtils.cpp
lib/Dialect/Torch/Transforms/SimplifyCalculationsUtils.h
The
*Utils.*
files include logic that is shared by dtype andshape passes.
Tests
test/Dialect/Torch/ops.mlir
test/Dialect/Torch/reify-dtype-calculations.mlir
test/Dialect/Torch/simplify-dtype-calculations.mlir
Introduce
torch_mlir_promote_dtypes
python/torch_mlir/dialects/torch/importer/jit_ir/csrc/node_importer.cpp
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/library_generator.py
Simple refactoring/generalizing
include/torch-mlir/Dialect/Torch/Utils/Utils.h
lib/Dialect/Torch/Utils/Utils.cpp
lib/Dialect/Torch/Transforms/DropCalculations.cpp
lib/Dialect/Torch/Transforms/RefineTypes.cpp
lib/Dialect/Torch/Transforms/ReifyShapeCalculations.cpp
lib/Dialect/Torch/Transforms/SimplifyShapeCalculations.cpp
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/registry.py
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/testing_framework.py
python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/calculations_lib_gen.py
lib/Dialect/Torch/Transforms/CalculationsLibrary.cpp
The rest of the files include minor changes
shape
withcalculations
m_TorchConstantIntList
withm_TorchListOfConstantInts
(needed to avoid ambiguity with newpattern
m_TorchListOfOptionalConstantInts
)