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
[Relax] Default purity as unknown, instead of pure #16744
base: main
Are you sure you want to change the base?
Conversation
I think this idea is very promising, though we should be certain of some corners of the design:
|
I think the key point is at I'd propose the following: Unknown purity is always allowed in non-dataflow blocks, regardless of where they occur in lowering, because non-dataflow blocks have no purity requirements. Impure functions are never allowed in dataflow blocks (current behavior). Unknown purity is allowed in a dataflow block, but must be resolved
I think the non-local purity inference pass can be run as often as desired. It is not required to resolve every unknown purity, and may output functions with unknown purity, if they contain calls to other functions of unknown purity. Then, during This would be similar to the way we handle shape inference for
I think I'd have the local analysis of a
Hmm. I'd been defaulting to unknown, in case there is additional information provided at a later stage. The main thing I was picturing was replacing an I think for |
That was a lot of breakage across different unit tests, and good to sort it out. I think it's a point in favor of the local-inference of function purity that #16687 didn't run into any of that type of failure. |
Using ToNonDataflow makes sense as a final threshold for making sure dataflow blocks are correctly formed, so I like that. |
c1aa0d2
to
e3b8d71
Compare
Prior to this commit, the constructors for `relax.Function` and `relax.FuncStructInfo` provided a default annotation as a pure function. While this could be overridden, it This commit updates the IR to store purity as `Optional<Bool>` instead of `bool`, and changes the default to `NullOpt`. A function's purity can have three possible values: - `Bool(true)`: The function is known to be pure. - `Bool(false)`: The function is known to be impure. - `NullOpt`: The function's purity is unknown. In most cases `Bool(false)` and `NullOpt` should be treated equivalently, as they both indicate a function that may contain side effects. However, in the future, inference of purity may occur when the purity is `NullOpt`, based on analysis of a function's body. A function with purity of `Bool(false)` is known to be impure, and further analysis is unnecessary.
5258e66
to
1698f50
Compare
Prior to this commit, the constructors for
relax.Function
andrelax.FuncStructInfo
provided a default annotation as a pure function. While this could be overridden, itThis commit updates the IR to store purity as
Optional<Bool>
instead ofbool
, and changes the default toNullOpt
.A function's purity can have three possible values:
Bool(true)
: The function is known to be pure.Bool(false)
: The function is known to be impure.NullOpt
: The function's purity is unknown.In most cases
Bool(false)
andNullOpt
should be treated equivalently, as they both indicate a function that may contain side effects. However, in the future, inference of purity may occur when the purity isNullOpt
, based on analysis of a function's body. A function with purity ofBool(false)
is known to be impure, and further analysis is unnecessary.