Open sdasgup3 opened 2 years ago
Relevant discussion: https://github.com/openxla/stablehlo/pull/353#discussion_r1000066688
Here is the current resolution as per the above chat thread (in Eugene's words).
Since this is a cross-cutting concern, i.e. it applies to a bunch of ops - not just reduce and not limited to the ops that https://github.com/openxla/stablehlo/issues/369 is talking about - I propose that we don't address it in this PR, but instead write the spec as if mixed precision is not a thing and then address all the ops at once.
I will work on this in next week.
Found a neat list of HLO opcodes which allow mixed precision: https://github.com/tensorflow/tensorflow/blob/1d69ba72834b963b72075a82c10959f6bb74e473/tensorflow/compiler/xla/service/hlo_verifier.cc#L1681-L1714.
There have been recent conversations about StableHLO having different behavior from HLO as far as mixed precision is concerned (StableHLO doesn't support it, HLO does). Furthermore, this has come up in the context of quantization: https://github.com/openxla/stablehlo/pull/1477/files#r1199398839. Moving this to Frontend Contract and raising priority.
Request description
Found a few disparities in inferring the return element type of operations involving reduction.
Lets first see the constraints we have on reducer function's type (from https://github.com/openxla/stablehlo/blob/8ec92006166d0602d0dca32e0267d169c2078e0d/stablehlo/dialect/TypeInference.cpp#L273 or https://github.com/tensorflow/tensorflow/blob/b362eaeb53cc21aa38f3eb1551500ced4fca0c97/tensorflow/compiler/xla/service/shape_inference.cc#L62, the former is inspired from the later)
Consider typical reduce-* op syntax:
The constraints that we verify are:
Informally,
Any element in P = {BI[i], R[i]} have same element type. Any element in Q = {I(i), V(j), BV(j)} has same element type modulo fp precision. For a in P and b in Q, a and b has same element type modulo fp precision.
Now the return type of the followings ops are inferred as follows:
From 1-4, it seems like for all the ops. we can say the element type of return is "element type of I(i) ignoring fp precision ".Should our spec use the same behavior as in HLO w.r.t ignoring precision?