-
Notifications
You must be signed in to change notification settings - Fork 112
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
Verification of ReduceOp and ReduceWindowOp is not strict enough. #394
Comments
While re-thinking on that: |
There is a similar issue with ReduceWindowOp stablehlo/stablehlo/dialect/TypeInference.cpp Lines 1044 to 1055 in 5e41ad2
|
This is a pure refactor PR which fixes #400 (deprecated) and #623 (new) As in the #623 , "we only need this for ops with regions", a full list of ops with region extract from https://github.com/openxla/stablehlo/blob/main/stablehlo/dialect/StablehloOps.td includes **11 ops** in total: | Op | what's done | | --- | --- | | AllReduceOp | No change (already split) | | CaseOp | No change (region is indispensable for type inference) | | IfOp | No change (region is indispensable for type inference) | | MapOp | No change (region is indispensable for type inference) | | ReduceOp | Split | | ReduceScatterOp | No change (Type Inference implementation on hold see #725) | | ReduceWindowOp | Split | | ScatterOp | No change (already split) | | SelectAndScatterOp | No change (already split) | | SortOp | Split | | WhileOp | Split | The ideal split is that verifiers contain as almost all verifications, and the shape functions are simple as possible, but note: 1. `IfOp/CaseOp/MapOp`: We need info from region(s) to infer the return type, so an init function without regions is always invalid and should not exist. No change for them in this PR. 2. As both verifier & shape function need verification of the inputs/attrs, so we need put them in a separate utils functions. `ReduceOp`: introduce new util `verifyReduceOpInputsAndInferShape()` `ReduceWindow`: introduce new util `verifyReduceWindowOpInputsAndInferWindow()` In each op, verifier does (1) call this new util function (2) verify region shape function: (1) call this new util function (2) generate inferred type from the intermediate result from (1) 3. Besides, the verification logic needs further fix see #394, but this is out of scope of this PR.
This problem become a little more complicate after we add bounds support in #737: we also need verify bounds are compatible with each other: a.bounds >= b.dim, final bound = min(every bound), etc.f |
This is a pure refactor PR which fixes openxla#400 (deprecated) and openxla#623 (new) As in the openxla#623 , "we only need this for ops with regions", a full list of ops with region extract from https://github.com/openxla/stablehlo/blob/main/stablehlo/dialect/StablehloOps.td includes **11 ops** in total: | Op | what's done | | --- | --- | | AllReduceOp | No change (already split) | | CaseOp | No change (region is indispensable for type inference) | | IfOp | No change (region is indispensable for type inference) | | MapOp | No change (region is indispensable for type inference) | | ReduceOp | Split | | ReduceScatterOp | No change (Type Inference implementation on hold see openxla#725) | | ReduceWindowOp | Split | | ScatterOp | No change (already split) | | SelectAndScatterOp | No change (already split) | | SortOp | Split | | WhileOp | Split | The ideal split is that verifiers contain as almost all verifications, and the shape functions are simple as possible, but note: 1. `IfOp/CaseOp/MapOp`: We need info from region(s) to infer the return type, so an init function without regions is always invalid and should not exist. No change for them in this PR. 2. As both verifier & shape function need verification of the inputs/attrs, so we need put them in a separate utils functions. `ReduceOp`: introduce new util `verifyReduceOpInputsAndInferShape()` `ReduceWindow`: introduce new util `verifyReduceWindowOpInputsAndInferWindow()` In each op, verifier does (1) call this new util function (2) verify region shape function: (1) call this new util function (2) generate inferred type from the intermediate result from (1) 3. Besides, the verification logic needs further fix see openxla#394, but this is out of scope of this PR.
Adding more ops which involves matching shapes and need to deal with the same issue. As previously discussed it would make sense to collect the size and bound for each dimension individually and use that for verification/type inference.
|
Request description
https://source.corp.google.com/piper///depot/google3/third_party/stablehlo/stablehlo/dialect/TypeInference.cpp;rcl=482658831;l=914
input shapes
tensor<?x4xi32>
,tensor<?x5xi32>
are incompatible, but verifier allows it, because it checks the compatibility with the first argument that has typetensor<?x?xf32>
.I think it should infer the "most static" shape first and then try to check whether the arguments are compatible with it. It would be nice to enforce arguments to have the same shape by inserting casts to this inferred type.
The text was updated successfully, but these errors were encountered: