-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix getShapedFloat with APFloat value (#471)
- fix `getShapedValue` in ONNXToStablehloCommon to support APFloat with fp16 input
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
frontends/onnx-frontend/third_party/patches/OnnxMlirONNXToStablehloCommon.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
diff --git a/src/Conversion/ONNXToStablehlo/ONNXToStablehloCommon.hpp b/src/Conversion/ONNXToStablehlo/ONNXToStablehloCommon.hpp | ||
index 832e72b9..3d8e1d7f 100644 | ||
--- a/src/Conversion/ONNXToStablehlo/ONNXToStablehloCommon.hpp | ||
+++ b/src/Conversion/ONNXToStablehlo/ONNXToStablehloCommon.hpp | ||
@@ -71,14 +71,20 @@ Value getShapedFloat(Location loc, ConversionPatternRewriter &rewriter, | ||
const T &value, Value &inp) { | ||
Value broadcastedValue; | ||
ShapedType inpType = inp.getType().cast<ShapedType>(); | ||
+ float f32Value; | ||
+ if constexpr (std::is_same_v<APFloat, T>) { | ||
+ f32Value = cast<APFloat>(value).convertToFloat(); | ||
+ } else { | ||
+ f32Value = value; | ||
+ } | ||
if (inpType.hasStaticShape()) | ||
broadcastedValue = rewriter.create<stablehlo::ConstantOp>( | ||
loc, DenseElementsAttr::get(inpType, | ||
- rewriter.getFloatAttr(inpType.getElementType(), value))); | ||
+ rewriter.getFloatAttr(inpType.getElementType(), f32Value))); | ||
else { | ||
Type elemType = inpType.getElementType(); | ||
Value floatValue = rewriter.create<stablehlo::ConstantOp>( | ||
- loc, rewriter.getFloatAttr(elemType, value)); | ||
+ loc, rewriter.getFloatAttr(elemType, f32Value)); | ||
Value shape = rewriter.create<shape::ShapeOfOp>(loc, inp); | ||
broadcastedValue = rewriter.create<stablehlo::DynamicBroadcastInDimOp>( | ||
loc, inpType, floatValue, shape, rewriter.getI64TensorAttr({})); |