Skip to content

Commit

Permalink
Support Dynamic Reshape in StableHLO Quantizer
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 609759860
  • Loading branch information
tensorflower-gardener authored and TensorFlow MLIR Team committed Feb 23, 2024
1 parent 1acfa49 commit 9622017
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1278,9 +1278,10 @@ class ConvertGenericOp : public ConversionPattern {
Operation *op, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const override {
// This pattern only handle selected ops.
if (!isa<mhlo::BroadcastInDimOp, mhlo::ConcatenateOp, mhlo::ConstantOp,
mhlo::BitcastConvertOp, mhlo::GatherOp, mhlo::MaxOp, mhlo::MinOp,
mhlo::PadOp, mhlo::ReduceWindowOp, mhlo::ReshapeOp, mhlo::ReturnOp,
if (!isa<mhlo::BitcastConvertOp, mhlo::BroadcastInDimOp,
mhlo::ConcatenateOp, mhlo::ConstantOp, mhlo::DynamicReshapeOp,
mhlo::GatherOp, mhlo::MaxOp, mhlo::MinOp, mhlo::PadOp,
mhlo::ReduceWindowOp, mhlo::ReshapeOp, mhlo::ReturnOp,
mhlo::SelectOp, mhlo::SliceOp, mhlo::TransposeOp,
mhlo::GetDimensionSizeOp, mhlo::DynamicBroadcastInDimOp>(op)) {
return failure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,21 @@ func.func @reshape(

// -----

// CHECK-LABEL: func @dynamic_reshape
func.func @dynamic_reshape(
%arg0: tensor<?x3x!quant.uniform<i8:f32, 0.13170163023705575:-1>>,
%arg1: tensor<2xi32>
) -> tensor<?x1x!quant.uniform<i8:f32, 0.13170163023705575:-1>> {
// CHECK: mhlo.dynamic_reshape
// CHECK-SAME: (tensor<?x3xi8>, tensor<2xi32>) -> tensor<?x1xi8>
%0 = "mhlo.dynamic_reshape"(%arg0, %arg1) : (
tensor<?x3x!quant.uniform<i8:f32, 0.13170163023705575:-1>>, tensor<2xi32>
) -> tensor<?x1x!quant.uniform<i8:f32, 0.13170163023705575:-1>>
return %0 : tensor<?x1x!quant.uniform<i8:f32, 0.13170163023705575:-1>>
}

// -----

// CHECK-LABEL: func @select
func.func @select(
%arg0: tensor<1x3xi1>,
Expand Down

0 comments on commit 9622017

Please sign in to comment.