-
Notifications
You must be signed in to change notification settings - Fork 48
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
onnx.Loop #332
Comments
(you'll need to extend the importer for this as it is a "special" op) |
I suspected I'll need more infra for this. Have simple test case onnx, will meet with rob to figure this out. |
Deprioritizing this now. |
Back on it. |
Todo list for now:
|
Torch ops to translate to:PrimLoopOp PrimIfOp
PrimIfYieldOp Methods / types of interest:mlir::Region PrimIfOp::getThenRegion |
Rob's Guide for Implementing If and Loop Constructs with Regions in ONNX LoweringTLDR:
Some conceptsBlock: A basic block with a single entry and exit point. Fundamental unit within a region.
How Linalg and SCF use Regions
|
Rob gave this reference for manipulating regions: https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/TosaToSCF/TosaToSCF.cpp Inline if case Rewrite terminators: the region's parent defines the rules about what terminators the region has. E.g. "must have 1 terminator block that ends in a particular op. e.g. functions must end with return" e.g. in SCF, 2 blocks for If / else. Has to "scf yield" at the end. What's getting returned is given in the yield. e.g. in while, one of the blocks has to have a conditional, and the other block has to have a yield block. before / after block for for style loops do while: before block and after block. scf while: yield op is both the conditional and the before block |
onnx binder:
RegionRange.size() |
Move the regions to torch, then translate the ops inside the regions. |
Running this to test if import: wget -O onnx_conditional_example.py https://gist.githubusercontent.com/renxida/6e859dbfab286916dd8b99542c0a2332/raw/e38d1558a2bdc9553a14338ca84c8f1ae4bb40b5/onnx_conditional_example.py
python onnx_conditional_example.py
PYTHONPATH=~/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir python -m torch_mlir.tools.import_onnx ./conditional_example.onnx -o conditional_example.mlir Current failure:
|
continuing here: llvm/torch-mlir#3136 |
Support onnx.If #2825 llvm/torch-mlir#2825 |
support - llvm/torch-mlir#3408 |
loop failed again for dlrm pytorch model |
llvm/torch-mlir#3408 |
module {
func.func @tf2onnx(%arg0: !torch.vtensor<[?,?,?,3],ui8>, %arg33: !torch.vtensor<[],si64>, %arg32: !torch.vtensor<[],i1>, %arg31: !torch.vtensor<[],si32>, %arg41: !torch.vtensor<[4],si64>, %arg42: !torch.vtensor<[],i1>, %arg43: !torch.vtensor<[],si32>, %arg44: !torch.vtensor<[3,300,300],f32>, %arg45: !torch.vtensor<[3],si32>) -> (!torch.vtensor<[],si32>, !torch.vtensor<[?,3,300,300],f32>, !torch.vtensor<[?,3],si32>) attributes {torch.onnx_meta.ir_version = 7 : si64, torch.onnx_meta.opset_version = 17 : si64, torch.onnx_meta.producer_name = "onnx.quantize", torch.onnx_meta.producer_version = "0.1.0"} {
%621:3 = torch.operator "onnx.Loop"(%arg33, %arg32, %arg31) : (!torch.vtensor<[],si64>, !torch.vtensor<[],i1>, !torch.vtensor<[],si32>) -> (!torch.vtensor<[],si32>, !torch.vtensor<[?,3,300,300],f32>, !torch.vtensor<[?,3],si32>) {
^bb0(%arg1: !torch.vtensor<[],si64>, %arg2: !torch.vtensor<[],i1>, %arg3: !torch.vtensor<[],si32>):
torch.operator_terminator %arg42, %arg43, %arg44, %arg45 : !torch.vtensor<[],i1>, !torch.vtensor<[],si32>, !torch.vtensor<[3,300,300],f32>, !torch.vtensor<[3],si32>
}
return %621#0, %621#1, %621#2 : !torch.vtensor<[],si32>, !torch.vtensor<[?,3,300,300],f32>, !torch.vtensor<[?,3],si32>
}
} |
complete IR |
@PhaneeshB is innx.loop not done yet? Should this issue be closed? |
This contains some notes from @renxida on onnx.If
@PhaneeshB is currently working on onnx.Loop
Find the if in retinanet_resnet50_fpn_vaiq_int8 model support
#199
The text was updated successfully, but these errors were encountered: