Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ python_init_repositories(
"3.10": "//:requirements_lock_3_10.txt",
"3.11": "//:requirements_lock_3_11.txt",
"3.12": "//:requirements_lock_3_12.txt",
"3.13": "//:requirements_lock_3_13.txt",
},
)

Expand Down
2 changes: 1 addition & 1 deletion ci/official/requirements_updater/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nvidia-cusparse-cu12 == 12.5.1.3
nvidia-nccl-cu12 == 2.25.1
nvidia-nvjitlink-cu12 == 12.5.82
# The dependencies below are needed for TF wheel testing.
tensorflow-io-gcs-filesystem==0.37.1
# tensorflow-io-gcs-filesystem==0.37.1
libclang >= 13.0.0
google_pasta ~= 0.2
flatbuffers ~= 24.3.25
744 changes: 744 additions & 0 deletions requirements_lock_3_13.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
load("//tensorflow:tensorflow.bzl", "tf_cc_test")
load("//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable")
load("//tensorflow/core/platform:rules_cc.bzl", "cc_library")

Expand Down Expand Up @@ -37,6 +38,62 @@ cc_library(
],
)

cc_library(
name = "quantization_lib",
srcs = [
"quantization_driver.cc",
"quantization_interface.cc.inc",
"quantization_utils.cc",
],
hdrs = [
"quantization_driver.h",
"quantization_interface.h.inc",
"quantization_traits.h",
"quantization_utils.h",
],
deps = [
":quantization_config",
":quantization_interfaces_inc_gen",
"//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
"//tensorflow/compiler/mlir/lite/quantization/lite/toco_legacy:portable_tensor_utils",
"//tensorflow/compiler/mlir/quantization/common/ir:QuantOps",
"//tensorflow/compiler/mlir/tools/optimize:quantization_utils",
"//tensorflow/core:lib_proto_parsing",
"//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:QuantOps",
"@llvm-project//mlir:Support",
],
)

tf_cc_test(
name = "quantization_driver_test",
srcs = ["quantization_driver_test.cc"],
deps = [
":quantization_lib",
"//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
"//tensorflow/compiler/mlir/quantization/common:attrs_and_constraints",
"//tensorflow/compiler/mlir/quantization/common:func",
"//tensorflow/compiler/mlir/quantization/common:test_base",
"//tensorflow/compiler/mlir/tensorflow",
"@com_google_absl//absl/strings:string_view",
"@com_google_googletest//:gtest_main",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:QuantOps",
"@llvm-project//mlir:Support",
],
)

td_library(
name = "quantization_td_files",
srcs = [
Expand Down Expand Up @@ -87,5 +144,7 @@ cc_library(
)

exports_files([
"quantization_traits.h",
"quantization_config.h",
"quantization_utils.h",
])
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ include "mlir/Dialect/Quant/IR/QuantBase.td"
// explicit signedness check to differentiate the signed/unsigned constraints
// predicates from one another at the TD level.
class QuantizedType<string n, list<int> params, bit signed>
: Type<And<[CPred<"$_self.isa<mlir::quant::QuantizedType>()">,
CPred<"$_self.cast<mlir::quant::QuantizedType>()" #
: Type<And<[CPred<"$_self.isa<mlir::TFL::QuantizedType>()">,
CPred<"$_self.cast<mlir::TFL::QuantizedType>()" #
".getStorageTypeIntegralWidth() == " # !head(params)>,
Or<[CPred<"$_self.cast<mlir::quant::QuantizedType>()" #
Or<[CPred<"$_self.cast<mlir::TFL::QuantizedType>()" #
".getStorageType().isSignlessInteger()">,
CPred<"$_self.cast<mlir::quant::QuantizedType>()" #
CPred<"$_self.cast<mlir::TFL::QuantizedType>()" #
".getStorageType().isSignedInteger() == " # signed>]>]>,
"Q" # !if (signed, "I", "UI") # !head(params) # " type"> {
string name = n;
Expand Down Expand Up @@ -73,6 +73,8 @@ def QI32 : QuantizedType<"Uniform", [32], 1>;

def FixedOutputRangeInterface : OpInterface<
"FixedOutputRangeInterface"> {
let cppNamespace = "TFL";

let description = [{
Interface for defining the fixed output range.
}];
Expand All @@ -88,6 +90,8 @@ def FixedOutputRangeInterface : OpInterface<

def AffineQuantizedOpInterface : OpInterface<
"AffineQuantizedOpInterface"> {
let cppNamespace = "TFL";

let description = [{
Interface for affine quantized ops (conv2d, fully_connected, etc.)
}];
Expand All @@ -113,6 +117,8 @@ def AffineQuantizedOpInterface : OpInterface<
}

def SameOperandsAndResultsScale : OpInterface<"SameScalesOpInterface"> {
let cppNamespace = "TFL";

let description = [{
Interface for ops potentially have same operands and results scales.
}];
Expand All @@ -131,12 +137,14 @@ def SameOperandsAndResultsScale : OpInterface<"SameScalesOpInterface"> {
];

let verify = [{
return quant::VerifySameScales($_op);
return TFL::VerifySameScales($_op);
}];
}

def DynamicRangeQuantizedOpInterface : OpInterface<
"DynamicRangeQuantizedOpInterface"> {
let cppNamespace = "TFL";

let description = [{
Interface for ops dynamic range quantization is supported.

Expand Down Expand Up @@ -196,24 +204,24 @@ def DynamicRangeQuantizedOpInterface : OpInterface<

// Specify this trait if the op has a fixed output value range.
class FixedResultScale<QuantizedType qt> : NativeOpTrait<!strconcat(
"quant::FixedResult", qt.name, "Scale<", qt.asTraitArgsStr, ">::Impl")>;
"TFL::FixedResult", qt.name, "Scale<", qt.asTraitArgsStr, ">::Impl")>;

// Specify this trait if the bias-th input of the op is a bias input, which
// needs a scale based on the scales of op1 and op2.
class AccumulatorUniformScale<int bias, int op1, int op2> : NativeOpTrait<
!strconcat("quant::AccumulatorUniformScale<",
!strconcat("TFL::AccumulatorUniformScale<",
!interleave([bias, op1, op2], ", "),
">::Impl")>;

// Specify the operand index of the coefficient operand for an affine op
// and also the quantization dimension if per-axis quantization is support.
// If the quantization dimension is -1, per-axis quantization isn't supported.
class AffineOpCoefficient<int dim, int index> : NativeOpTrait<
!strconcat("quant::AffineOpCoefficient<",
!strconcat("TFL::AffineOpCoefficient<",
!interleave([dim, index], ", "),
">::Impl")>;

// Specify this trait if the op does have quantizable output. Quantizers will
// apply quantization on this op.
def QuantizableResult : NativeOpTrait<"quant::QuantizableResult">;
def QuantizableResult : NativeOpTrait<"TFL::QuantizableResult">;
#endif // TF_Quantization
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ bool ParseInputNodeQuantSpecs(const absl::string_view node_names,
}

tensorflow::DataType final_type = tensorflow::DT_FLOAT;
if (!inference_type.empty() && !DataType_Parse(inference_type, &final_type)) {
if (!inference_type.empty() &&
!DataType_Parse(std::string(inference_type), &final_type)) {
return true;
}
return GetInputNodeQuantSpecs(input_nodes, node_mins, node_maxs, final_type,
Expand Down
Loading