• 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 
43   // If `emit_builtin_tflite_ops` is true, TF Lite legalization passes will be
44   // added, which produces TF Lite ops.
45   bool emit_builtin_tflite_ops;
46   // If `lower_tensor_list_ops` is true, tensorlist ops will be lowered to basic
47   // TF ops before legalization to TF Lite dialect.
48   bool lower_tensor_list_ops;
49   // The allowlist of functions that would be preserved after trimming.
50   llvm::ArrayRef<std::string> trim_functions_allowlist;
51   // All information about quantization.
52   QuantizationSpecs quant_specs;
53   // If `form_clusters` is true , clusters are formed by grouping consecutive
54   // ops of the same device, under a `tf_device.launch` op.
55   bool form_clusters;
56   // if `unfold_batch_matmul` is true, the tf.BatchMatMul is unfolded to a set
57   // of tfl.fully_connected ops.
58   bool unfold_batch_matmul;
59   // Whether to legalize TF While to TFL While.
60   // Note: This is staging step and will be removed.
61   // TODO(b/137395003): Remove post switching legalization.
62   bool legalize_tf_while;
63   // Whether to do shape inference.
64   bool shape_inference;
65   // Whether to do TFLite runtime verification.
66   bool runtime_verification;
67   // Whether to enable TFLite variables or not, this will allow
68   // mutable variables and produce ReadVariable/AssignVariable ops in TFLite.
69   bool enable_tflite_variables;
70   // Whether to disable the variable freezing pass or not.
71   // By default we freeze all variables and disallow mutable variables. When
72   // 'enable_tflite_variables' is true then we allow mutable variable only.
73   bool disable_variable_freezing;
74 };
75 
76 }  // namespace TFL
77 }  // namespace mlir
78 
79 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_
80