Skip to content
Merged
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
48 changes: 48 additions & 0 deletions neural_coder/coders/tensorflow/inc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ...utils.line_operation import get_line_left_hand_side

class TensorFlowKerasINC(object):
def __init__(self, file) -> None:
self.file = file
self.result = []

def transform(self):
# import pdb
# pdb.set_trace()
lines = self.file.split('\n')
for line in lines:
if self.is_modify(line):
self.result.append(line)
self.result.append("from neural_compressor.conf.config import QuantConf")
self.result.append("from neural_compressor.experimental import Quantization")
self.result.append("from neural_compressor.experimental import common")
self.result.append("quant_config = QuantConf()")
self.result.append("quant_config.usr_cfg.model.framework = 'tensorflow'")
self.result.append("quantizer = Quantization(quant_config)")
self.result.append("quantizer.model = common.Model(" + model_name + ")")
self.result.append(model_name + " = quantizer.fit()")
else:
self.result.append(line)
for index, line in enumerate(self.result):
if index != len(self.result)-1:
self.result[index] += '\n'
return ''.join(self.result)

def is_modify(self, s):
if 'model = tf.' in s:
return True
else:
return False
8 changes: 7 additions & 1 deletion neural_coder/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def enable(
"pytorch_aliblade",
"tensorflow_amp",
"keras_amp",
"onnx_inc_static_quant_qlinear"
"tensorflow_inc",
"onnx_inc_static_quant_qlinear",
"onnx_inc_static_quant_qdq",
"onnx_inc_dynamic_quant",
]
'''

Expand Down Expand Up @@ -350,6 +353,9 @@ def enable(
if "tensorflow_mixed_precision" in features:
from .coders.tensorflow.amp import TensorFlowKerasAMP
list_transformed_code[i] = TensorFlowKerasAMP(list_transformed_code[i]).transform()
if "tensorflow_inc" in features:
from .coders.tensorflow.inc import TensorFlowKerasINC
list_transformed_code[i] = TensorFlowKerasINC(list_transformed_code[i]).transform()
# Change Trainer to NLPTrainer (only for intel_extension_for_pytorch)
if "change_trainer_to_nlptrainer" in features:
from .coders.pytorch.change_trainer_to_nlptrainer import TrainerToNLPTrainer
Expand Down