Fix output type of custom calls while lowering quant/dequant torch op to HLO #6283
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#5763 allows lowering the torch quantize/dequantize operations to HLO custom calls. For example,
the following PyTorch code
is lowered to the following HLO operations:
Note that the output of custom call corresponding to quantize op has element type
f32
. The fact that the output of custom_call (for quantize operation) is a float is more of a logical problem as the the result of quantization is generally expected to be in integer domain. Also, note that the choice of output type should not effect the eventual conversion of HLO custom calls to mhlouniform.quantize
/uniform.dequantize
operations.Moreover, based on https://github.com/pytorch/pytorch/blob/0b72ce1bd1a4a0596dde4053899b8a9a7999bc47/torch/ao/quantization/fx/_decomposed.py#L164 we set the output element type of dequatize operation to be
f32
Finally improved the debuggability of the map queries using proper error messages.
cc @GleasonK