• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_
17 #define TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "llvm/ADT/ArrayRef.h"
23 #include "tensorflow/compiler/mlir/lite/quantization/quantization_config.h"
24 
25 namespace mlir {
26 namespace TFL {
27 
28 // A config that controls which passes get run as part TFLite converter.
29 struct PassConfig {
PassConfigPassConfig30   explicit PassConfig(QuantizationSpecs specs)
31       : emit_builtin_tflite_ops(true),
32         lower_tensor_list_ops(false),
33         trim_functions_allowlist({}),
34         quant_specs(std::move(specs)),
35         form_clusters(false),
36         unfold_batch_matmul(true),
37         legalize_tf_while(true),
38         shape_inference(true),
39         runtime_verification(true),
40         enable_tflite_variables(false),
41         disable_variable_freezing(false),
42         unfold_large_splat_constant(false),
43         guarantee_all_funcs_one_use(false) {}
44 
45   // If `emit_builtin_tflite_ops` is true, TF Lite legalization passes will be
46   // added, which produces TF Lite ops.
47   bool emit_builtin_tflite_ops;
48   // If `lower_tensor_list_ops` is true, tensorlist ops will be lowered to basic
49   // TF ops before legalization to TF Lite dialect.
50   bool lower_tensor_list_ops;
51   // The allowlist of functions that would be preserved after trimming.
52   llvm::ArrayRef<std::string> trim_functions_allowlist;
53   // All information about quantization.
54   QuantizationSpecs quant_specs;
55   // If `form_clusters` is true , clusters are formed by grouping consecutive
56   // ops of the same device, under a `tf_device.launch` op.
57   bool form_clusters;
58   // if `unfold_batch_matmul` is true, the tf.BatchMatMul is unfolded to a set
59   // of tfl.fully_connected ops.
60   bool unfold_batch_matmul;
61   // Whether to legalize TF While to TFL While.
62   // Note: This is staging step and will be removed.
63   // TODO(b/137395003): Remove post switching legalization.
64   bool legalize_tf_while;
65   // Whether to do shape inference.
66   bool shape_inference;
67   // Whether to do TFLite runtime verification.
68   bool runtime_verification;
69   // Whether to enable TFLite variables or not, this will allow
70   // mutable variables and produce ReadVariable/AssignVariable ops in TFLite.
71   bool enable_tflite_variables;
72   // Whether to disable the variable freezing pass or not.
73   // By default we freeze all variables and disallow mutable variables. When
74   // 'enable_tflite_variables' is true then we allow mutable variable only.
75   bool disable_variable_freezing;
76   // Whether to unfold large splat constant tensors and replace them with
77   // fill operation.
78   bool unfold_large_splat_constant;
79   // Whether to run the `GuaranteeAllFuncsOneUsePass` to ensure each function
80   // has a single use.
81   bool guarantee_all_funcs_one_use;
82 };
83 
84 }  // namespace TFL
85 }  // namespace mlir
86 
87 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_
88