Skip to content

Commit

Permalink
Switch quantization dialect to use properties.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 629634333
  • Loading branch information
chsigg authored and tensorflower-gardener committed May 1, 2024
1 parent 40573b4 commit e7d3122
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include "mlir/IR/OpBase.td"
def QuantizationFork_Dialect : Dialect {
let name = "quantfork";
let cppNamespace = "::mlir::quantfork";
let usePropertiesForAttributes = 0;
}

#endif // QUANT_FORK_BASE
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func.func @import_stats_name(%arg0: tensor<4xf32>, %cst: tensor<i32>) -> (tensor
func.return %0#0, %0#1 : tensor<2xf32>, tensor<2xf32>

// CHECK-NEXT: %[[split:.*]]:2 = "tfl.split"
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) {layerStats = dense<[-1.000000e+00, 1.000000e+00]>
// CHECK-NEXT: %[[stats2:.*]] = "quantfork.stats"(%[[split]]#1) {layerStats = dense<[-1.000000e+00, 1.000000e+00]>
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) <{layerStats = dense<[-1.000000e+00, 1.000000e+00]>
// CHECK-NEXT: %[[stats2:.*]] = "quantfork.stats"(%[[split]]#1) <{layerStats = dense<[-1.000000e+00, 1.000000e+00]>
// CHECK-NEXT: return %[[stats1]], %[[stats2]] : tensor<2xf32>, tensor<2xf32>
}

Expand All @@ -30,7 +30,7 @@ func.func @import_stats_name_port(%arg0: tensor<4xf32>, %cst: tensor<i32>) -> (t
func.return %0#0, %0#1 : tensor<2xf32>, tensor<2xf32>

// CHECK-NEXT: %[[split:.*]]:2 = "tfl.split"
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) {layerStats = dense<[-2.000000e+00, 2.000000e+00]>
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) <{layerStats = dense<[-2.000000e+00, 2.000000e+00]>
// CHECK-NEXT: return %[[stats1]], %[[split]]#1 : tensor<2xf32>, tensor<2xf32>
}

Expand All @@ -41,7 +41,7 @@ func.func @import_stats_name_regex(%arg0: tensor<4xf32>, %cst: tensor<i32>) -> (
func.return %0#0, %0#1 : tensor<2xf32>, tensor<2xf32>

// CHECK-NEXT: %[[split:.*]]:2 = "tfl.split"
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) {layerStats = dense<[-3.000000e+00, 3.000000e+00]>
// CHECK-NEXT: %[[stats2:.*]] = "quantfork.stats"(%[[split]]#1) {layerStats = dense<[-3.000000e+00, 3.000000e+00]>
// CHECK-NEXT: %[[stats1:.*]] = "quantfork.stats"(%[[split]]#0) <{layerStats = dense<[-3.000000e+00, 3.000000e+00]>
// CHECK-NEXT: %[[stats2:.*]] = "quantfork.stats"(%[[split]]#1) <{layerStats = dense<[-3.000000e+00, 3.000000e+00]>
// CHECK-NEXT: return %[[stats1]], %[[stats2]] : tensor<2xf32>, tensor<2xf32>
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ std::optional<std::unique_ptr<tflite::ModelT>> InjectStatsToFullyConnected(

// CHECK-LABEL: func @main(%arg0: tensor<40x37xf32>, %arg1: tensor<40x37xf32>)
// CHECK-SAME: -> tensor<40x40xf32>
// CHECK: %[[stat:.*]] = "quantfork.stats"(%arg0) {layerStats = dense<
// CHECK-SAME: [-1.000000e+00, 1.000000e+00]> : tensor<2xf32>}
// CHECK: %[[stat:.*]] = "quantfork.stats"(%arg0) <{layerStats = dense
// CHECK-SAME: <[-1.000000e+00, 1.000000e+00]> : tensor<2xf32>}>
// CHECK-SAME: : (tensor<40x37xf32>) -> tensor<40x37xf32>
// CHECK-NEXT: %[[cst:.*]] = "tfl.pseudo_const"() {value = dense<
// CHECK-SAME: 1.000000e+00> : tensor<40xf32>} : () -> tensor<40xf32>
// CHECK-NEXT: %[[fc:.*]]:2 = "tfl.fully_connected"(%[[stat]], %arg1,
// CHECK-NEXT: %[[stat1:.*]] = "quantfork.stats"(%[[fc]]#0)
// CHECK-SAME: {axis = 1 : i64,
// CHECK-SAME: <{axis = 1 : i64,
// CHECK-SAME: axisStats = dense<{{\[}}[-0.000000e+00, 0.000000e+00],
// CHECK-SAME: [-1.000000e+00, 1.000000e+00],
// CHECK-SAME: [-2.000000e+00, 2.000000e+00]
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/compiler/mlir/lite/tests/flatbuffer2mlir/lstm.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: json_to_flatbuffer %p/test_schema.fbs %s | flatbuffer_translate --tflite-flatbuffer-to-mlir -o - | FileCheck %s
// RUN: json_to_flatbuffer %p/test_schema.fbs %s | flatbuffer_translate --tflite-flatbuffer-to-mlir -o - | flatbuffer_translate -mlir-to-tflite-flatbuffer - -o - | flatbuffer_to_string - | FileCheck --check-prefix=RoundTrip %s

// CHECK-DAG: %[[input_18:.*]] = "quantfork.stats"({{.*}}) {layerStats = dense<[-8.000000e-01, 1.600000e+00]> : tensor<2xf32>} : (tensor<1x4xf32>) -> tensor<1x4xf32>
// CHECK-DAG: %[[input_19:.*]] = "quantfork.stats"({{.*}}) {layerStats = dense<[-2.000000e+00, 4.000000e+00]> : tensor<2xf32>} : (tensor<1x2xf32>) -> tensor<1x2xf32>
// CHECK-DAG: %[[input_18:.*]] = "quantfork.stats"({{.*}}) <{layerStats = dense<[-8.000000e-01, 1.600000e+00]> : tensor<2xf32>}> : (tensor<1x4xf32>) -> tensor<1x4xf32>
// CHECK-DAG: %[[input_19:.*]] = "quantfork.stats"({{.*}}) <{layerStats = dense<[-2.000000e+00, 4.000000e+00]> : tensor<2xf32>}> : (tensor<1x2xf32>) -> tensor<1x2xf32>

// CHECK: "tfl.unidirectional_sequence_lstm"({{.*}}, %[[input_18]], %[[input_19]], %{{[0-9]+}}, %{{[0-9]+}}, %{{[0-9]+}}, %{{[0-9]+}})
// CHECK-SAME: effective_hidden_scale_intermediate = tensor<*x!quant.calibrated<f32<-5.000000e-01:5.000000e-01>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

func.func @main(%arg0: tensor<1x512x672x8xf32>) -> tensor<1x512x672x8xf32> {
// CHECK-LABEL: @main
// CHECK: %[[RES0:.*]] = "quantfork.stats"(%arg0) {layerStats = dense<[0.000000e+00, 2.550000e+02]> : tensor<2xf32>} : (tensor<1x512x672x8xf32>) -> tensor<1x512x672x8xf32>
// CHECK: %[[RES0:.*]] = "quantfork.stats"(%arg0) <{layerStats = dense<[0.000000e+00, 2.550000e+02]> : tensor<2xf32>}> : (tensor<1x512x672x8xf32>) -> tensor<1x512x672x8xf32>

%0 = "quantfork.stats"(%arg0) {layerStats = dense<[0.000000e+00, 2.550000e+02]> : tensor<2xf32>} : (tensor<1x512x672x8xf32>) -> tensor<1x512x672x8xf32>
func.return %0 : tensor<1x512x672x8xf32>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include "mlir/IR/OpBase.td"
def Quant_Dialect : Dialect {
let name = "quantization";
let cppNamespace = "::mlir::quant::ir";
let usePropertiesForAttributes = 0;
}

#endif // QUANTIZATION_BASE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func.func @customAggregator(%arg0: tensor<8x8x8x8xf32>) -> (tensor<8x8x8x8xf32>,
func.return %0#0, %1#0 : tensor<8x8x8x8xf32>, tensor<8x8x8x8xf32>
}
// CHECK: func @customAggregator
// CHECK-NEXT: %[[stats:.*]] = "quantfork.stats"(%arg0) {layerStats = dense<[-1.000000e-01, 2.000000e-01]> : tensor<2xf32>} : (tensor<8x8x8x8xf32>) -> tensor<8x8x8x8xf32>
// CHECK-NEXT: %[[stats:.*]] = "quantfork.stats"(%arg0) <{layerStats = dense<[-1.000000e-01, 2.000000e-01]> : tensor<2xf32>}> : (tensor<8x8x8x8xf32>) -> tensor<8x8x8x8xf32>
// CHECK-NEXT: return %[[stats]], %arg0

func.func @doNotHandleNoMinMaxCases(%arg0: tensor<8x8x8x8xf32>) -> (tensor<8x8x8x8xf32>, tensor<8x8x8x8xf32>, tensor<8x8x8x8xf32>) {
Expand Down

0 comments on commit e7d3122

Please sign in to comment.