Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TF GNR-BASE #1415

Merged
merged 12 commits into from
Nov 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def create_tf_config(args):
config.allow_soft_placement = True
config.intra_op_parallelism_threads = OMP_NUM_THREADS
config.inter_op_parallelism_threads = 1
# additional options
config.graph_options.rewrite_options.function_optimization = rewriter_config_pb2.RewriterConfig.AGGRESSIVE
if args.precision == 'bfloat16':
config.graph_options.rewrite_options.auto_mixed_precision_mkl = rewriter_config_pb2.RewriterConfig.ON
return config
Expand Down
20 changes: 18 additions & 2 deletions neural_compressor/adaptor/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@
from .query import QueryBackendCapability

tensorflow = LazyImport("tensorflow")
spr_base_verions = ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323")
spr_base_verions = (
"2.11.0202242",
"2.11.0202250",
"2.11.0202317",
"2.11.0202323",
"2.14.0202335",
"2.14.dev202335",
"2.15.0202341",
)


@adaptor_registry
Expand Down Expand Up @@ -2146,7 +2154,15 @@ def _compare(version1, version2):
if self.version in sub_data["version"]["name"]:
return sub_data
else:
if sub_data["version"]["name"] == ["2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323"]:
if sub_data["version"]["name"] == [
"2.11.0202242",
"2.11.0202250",
"2.11.0202317",
"2.11.0202323",
"2.14.0202335",
"2.14.dev202335",
"2.15.0202341",
]:
continue
sorted_list = copy.deepcopy(sub_data["version"]["name"])
sorted_list.remove("default") if "default" in sorted_list else None
Expand Down
2 changes: 1 addition & 1 deletion neural_compressor/adaptor/tensorflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
---
-
version:
name: ['2.11.0202242', '2.11.0202250', '2.11.0202317', '2.11.0202323']
name: ['2.11.0202242', '2.11.0202250', '2.11.0202317', '2.11.0202323', '2.14.0202335', '2.14.dev202335', '2.15.0202341']

bf16: ["_MklLayerNorm", "Conv2D", "Conv2DBackpropFilter", "Conv2DBackpropInput", "Conv3D", "Conv3DBackpropFilterV2", "Conv3DBackpropInputV2",
"DepthwiseConv2dNative", "DepthwiseConv2dNativeBackpropFilter", "DepthwiseConv2dNativeBackpropInput", "GRUBlockCell",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.adaptor.tf_utils.util import TF_SPR_BASE_VERSIONS

from ..generic.dequantize_cast_optimizer import DequantizeCastOptimizer
from ..generic.graph_cse_optimizer import GraphCseOptimizer
from ..graph_base import GraphRewriterBase
from .dequantize_cast_optimizer import DequantizeCastOptimizer

DT_FLOAT32 = attr_value_pb2.AttrValue(type=dtypes.float32.as_datatype_enum)
DT_BFLOAT16 = attr_value_pb2.AttrValue(type=dtypes.bfloat16.as_datatype_enum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from neural_compressor.adaptor.tf_utils.graph_util import GraphAnalyzer
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.adaptor.tf_utils.util import TF_SPR_BASE_VERSIONS
from neural_compressor.utils.utility import dump_elapsed_time

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

import tensorflow as tf

if tf.version.VERSION not in ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323"):
if tf.version.VERSION not in TF_SPR_BASE_VERSIONS:
target_nodes = g.query_fusion_pattern_nodes([["MatMul", "Conv2D"], ["Add", "AddV2"]])
else:
target_nodes = g.query_fusion_pattern_nodes([["MatMul"], ["Add", "AddV2"]])
Expand Down
10 changes: 9 additions & 1 deletion neural_compressor/adaptor/tf_utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@

from .graph_util import GraphAnalyzer, GraphRewriterHelper

TF_SPR_BASE_VERSIONS = ("2.11.0202242", "2.11.0202250", "2.11.0202317", "2.11.0202323")
TF_SPR_BASE_VERSIONS = (
"2.11.0202242",
"2.11.0202250",
"2.11.0202317",
"2.11.0202323",
"2.14.0202335",
"2.14.dev202335",
"2.15.0202341",
)


def version1_lt_version2(version1, version2):
Expand Down
3 changes: 2 additions & 1 deletion neural_compressor/model/tensorflow_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def get_model_type(model):
return "graph"
elif isinstance(model, tf.compat.v1.GraphDef):
return "graph_def"
elif isinstance(model, tf.compat.v1.estimator.Estimator):
# tf.estimator is removed after tf2.14.0
elif version1_lt_version2(tf.__version__, "2.14.0") and isinstance(model, tf.compat.v1.estimator.Estimator):
return "estimator"
elif isinstance(model, str):
model = os.path.abspath(os.path.expanduser(model))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml
from tensorflow.python.framework import dtypes

from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.dequantize_cast_optimizer import DequantizeCastOptimizer
from neural_compressor.adaptor.tf_utils.graph_rewriter.bf16.dequantize_cast_optimizer import DequantizeCastOptimizer
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.adaptor.tf_utils.util import disable_random

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml
from tensorflow.python.framework import dtypes

from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.dequantize_cast_optimizer import DequantizeCastOptimizer
from neural_compressor.adaptor.tf_utils.graph_rewriter.bf16.dequantize_cast_optimizer import DequantizeCastOptimizer
from neural_compressor.adaptor.tf_utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.adaptor.tf_utils.util import disable_random

Expand Down
Loading