1 | /* Copyright 2016 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_CORE_COMMON_RUNTIME_QUANTIZE_TRAINING_H_ |
17 | #define TENSORFLOW_CORE_COMMON_RUNTIME_QUANTIZE_TRAINING_H_ |
18 | |
19 | #include "tensorflow/core/graph/graph.h" |
20 | |
21 | namespace tensorflow { |
22 | // Rewrites graph for quantized training. |
23 | // Rewrites the forward pass to include the precision loss with quantization so |
24 | // the model can learn to deal with such loss and achieve better accuracy when |
25 | // it is quantized later for inference. |
26 | // Note that the num_bits should be in [1, 63] and 'g' must be not null. |
27 | // quant_op_type specifies which quantization op should be used. |
28 | // Current ops supported: |
29 | // - QuantizeAndDequantizeV2. |
30 | // - FakeQuantWithMinMaxVars. |
31 | // |
32 | // On success, returns OK. |
33 | // |
34 | // On failure, returns the error status. Possible errors include: |
35 | // - num_bits out of range. |
36 | // - g is null. |
37 | // - More than 1 unknown ops encountered. |
38 | Status DoQuantizeTraining(int32_t num_bits, const string& quant_op_type, |
39 | Graph* g); |
40 | |
41 | // Converts the input serialized GraphDef and returns a rewritten serialized |
42 | // GraphDef for quantized training. |
43 | Status DoQuantizeTrainingOnSerializedGraphDef(const string& input_graph, |
44 | int32_t num_bits, |
45 | const string& quant_op_type, |
46 | string* result_graph); |
47 | |
48 | // Converts the input GraphDef and returns a rewritten GraphDef for quantized |
49 | // training. |
50 | Status DoQuantizeTrainingOnGraphDef(const GraphDef& input_graphdef, |
51 | int32_t num_bits, |
52 | const string& quant_op_type, |
53 | GraphDef* result_graphdef); |
54 | |
55 | } // namespace tensorflow |
56 | |
57 | #endif // TENSORFLOW_CORE_COMMON_RUNTIME_QUANTIZE_TRAINING_H_ |
58 | |