Skip to content

Commit 8160c71

Browse files
Support TF GNR-BASE (#1415)
Signed-off-by: zehao-intel <zehao.huang@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d131832 commit 8160c71

File tree

10 files changed

+37
-9
lines changed

10 files changed

+37
-9
lines changed

examples/tensorflow/oob_models/quantization/ptq/tf_benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def create_tf_config(args):
9494
config.allow_soft_placement = True
9595
config.intra_op_parallelism_threads = OMP_NUM_THREADS
9696
config.inter_op_parallelism_threads = 1
97+
# additional options
98+
config.graph_options.rewrite_options.function_optimization = rewriter_config_pb2.RewriterConfig.AGGRESSIVE
9799
if args.precision == 'bfloat16':
98100
config.graph_options.rewrite_options.auto_mixed_precision_mkl = rewriter_config_pb2.RewriterConfig.ON
99101
return config

neural_compressor/adaptor/tensorflow.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@
4444
from .query import QueryBackendCapability
4545

4646
tensorflow = LazyImport("tensorflow")
47-
spr_base_verions = ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323")
47+
spr_base_verions = (
48+
"2.11.0202242",
49+
"2.11.0202250",
50+
"2.11.0202317",
51+
"2.11.0202323",
52+
"2.14.0202335",
53+
"2.14.dev202335",
54+
"2.15.0202341",
55+
)
4856

4957

5058
@adaptor_registry
@@ -2146,7 +2154,15 @@ def _compare(version1, version2):
21462154
if self.version in sub_data["version"]["name"]:
21472155
return sub_data
21482156
else:
2149-
if sub_data["version"]["name"] == ["2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323"]:
2157+
if sub_data["version"]["name"] == [
2158+
"2.11.0202242",
2159+
"2.11.0202250",
2160+
"2.11.0202317",
2161+
"2.11.0202323",
2162+
"2.14.0202335",
2163+
"2.14.dev202335",
2164+
"2.15.0202341",
2165+
]:
21502166
continue
21512167
sorted_list = copy.deepcopy(sub_data["version"]["name"])
21522168
sorted_list.remove("default") if "default" in sorted_list else None

neural_compressor/adaptor/tensorflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
---
1717
-
1818
version:
19-
name: ['2.11.0202242', '2.11.0202250', '2.11.0202317', '2.11.0202323']
19+
name: ['2.11.0202242', '2.11.0202250', '2.11.0202317', '2.11.0202323', '2.14.0202335', '2.14.dev202335', '2.15.0202341']
2020

2121
bf16: ["_MklLayerNorm", "Conv2D", "Conv2DBackpropFilter", "Conv2DBackpropInput", "Conv3D", "Conv3DBackpropFilterV2", "Conv3DBackpropInputV2",
2222
"DepthwiseConv2dNative", "DepthwiseConv2dNativeBackpropFilter", "DepthwiseConv2dNativeBackpropInput", "GRUBlockCell",

neural_compressor/adaptor/tf_utils/graph_rewriter/bf16/bf16_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
3232
from neural_compressor.adaptor.tf_utils.util import TF_SPR_BASE_VERSIONS
3333

34-
from ..generic.dequantize_cast_optimizer import DequantizeCastOptimizer
3534
from ..generic.graph_cse_optimizer import GraphCseOptimizer
3635
from ..graph_base import GraphRewriterBase
36+
from .dequantize_cast_optimizer import DequantizeCastOptimizer
3737

3838
DT_FLOAT32 = attr_value_pb2.AttrValue(type=dtypes.float32.as_datatype_enum)
3939
DT_BFLOAT16 = attr_value_pb2.AttrValue(type=dtypes.bfloat16.as_datatype_enum)

neural_compressor/adaptor/tf_utils/graph_rewriter/generic/convert_add_to_biasadd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from neural_compressor.adaptor.tf_utils.graph_util import GraphAnalyzer
2323
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
24+
from neural_compressor.adaptor.tf_utils.util import TF_SPR_BASE_VERSIONS
2425
from neural_compressor.utils.utility import dump_elapsed_time
2526

2627
from ..graph_base import GraphRewriterBase
@@ -38,7 +39,7 @@ def do_transformation(self):
3839

3940
import tensorflow as tf
4041

41-
if tf.version.VERSION not in ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323"):
42+
if tf.version.VERSION not in TF_SPR_BASE_VERSIONS:
4243
target_nodes = g.query_fusion_pattern_nodes([["MatMul", "Conv2D"], ["Add", "AddV2"]])
4344
else:
4445
target_nodes = g.query_fusion_pattern_nodes([["MatMul"], ["Add", "AddV2"]])

neural_compressor/adaptor/tf_utils/util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@
3838

3939
from .graph_util import GraphAnalyzer, GraphRewriterHelper
4040

41-
TF_SPR_BASE_VERSIONS = ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323")
41+
TF_SPR_BASE_VERSIONS = (
42+
"2.11.0202242",
43+
"2.11.0202250",
44+
"2.11.0202317",
45+
"2.11.0202323",
46+
"2.14.0202335",
47+
"2.14.dev202335",
48+
"2.15.0202341",
49+
)
4250

4351

4452
def version1_lt_version2(version1, version2):

neural_compressor/model/tensorflow_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def get_model_type(model):
8181
return "graph"
8282
elif isinstance(model, tf.compat.v1.GraphDef):
8383
return "graph_def"
84-
elif isinstance(model, tf.compat.v1.estimator.Estimator):
84+
# tf.estimator is removed after tf2.14.0
85+
elif version1_lt_version2(tf.__version__, "2.14.0") and isinstance(model, tf.compat.v1.estimator.Estimator):
8586
return "estimator"
8687
elif isinstance(model, str):
8788
model = os.path.abspath(os.path.expanduser(model))

test/adaptor/tensorflow_adaptor/test_tensorflow_graph_dequantize_cast_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77
from tensorflow.python.framework import dtypes
88

9-
from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.dequantize_cast_optimizer import DequantizeCastOptimizer
9+
from neural_compressor.adaptor.tf_utils.graph_rewriter.bf16.dequantize_cast_optimizer import DequantizeCastOptimizer
1010
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
1111
from neural_compressor.adaptor.tf_utils.util import disable_random
1212

test/tfnewapi/test_tensorflow_graph_dequantize_cast_optimizer_newapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77
from tensorflow.python.framework import dtypes
88

9-
from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.dequantize_cast_optimizer import DequantizeCastOptimizer
9+
from neural_compressor.adaptor.tf_utils.graph_rewriter.bf16.dequantize_cast_optimizer import DequantizeCastOptimizer
1010
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
1111
from neural_compressor.adaptor.tf_utils.util import disable_random
1212

0 commit comments

Comments
 (0)