Skip to content

Commit d67ab4f

Browse files
zehao-intelchensuyue
authored andcommitted
TF support version detection update (#947)
1 parent 24e5552 commit d67ab4f

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ Intel® Neural Compressor supports systems based on [Intel 64 architecture or co
100100
<tbody>
101101
<tr align="center">
102102
<th>Version</th>
103-
<td class="tg-7zrl"><a href=https://github.com/tensorflow/tensorflow/tree/v2.8.0>2.8.0</a><br>
104-
<a href=https://github.com/tensorflow/tensorflow/tree/v2.7.0>2.7.0</a><br>
105-
<a href=https://github.com/tensorflow/tensorflow/tree/v2.6.2>2.6.2</a></td>
103+
<td class="tg-7zrl"><a href=https://github.com/tensorflow/tensorflow/tree/v2.9.1>2.9.1</a><br>
104+
<a href=https://github.com/tensorflow/tensorflow/tree/v2.8.2>2.8.2</a><br>
105+
<a href=https://github.com/tensorflow/tensorflow/tree/v2.7.3>2.7.3</a><br>
106106
<td class="tg-7zrl"><a href=https://github.com/Intel-tensorflow/tensorflow/tree/v2.8.0>2.8.0</a><br>
107107
<a href=https://github.com/Intel-tensorflow/tensorflow/tree/v2.7.0>2.7.0</a><br>
108108
<a href=https://github.com/Intel-tensorflow/tensorflow/tree/v1.15.0up3>1.15.0UP3</a></td>
@@ -122,7 +122,8 @@ Intel® Neural Compressor supports systems based on [Intel 64 architecture or co
122122
</tbody>
123123
</table>
124124

125-
> Note: Starting from official TensorFlow 2.6.0, oneDNN has been default in the binary. Please set the environment variable TF_ENABLE_ONEDNN_OPTS=1 before running the quantization process or deploying the quantized model with official TensorFlow.
125+
> Note: 1.Starting from official TensorFlow 2.6.0, oneDNN has been default in the binary. Please set the environment variable TF_ENABLE_ONEDNN_OPTS=1 to enable the oneDNN optimizations.
126+
> 2.Starting from official TensorFlow 2.9.0, oneDNN optimizations are enabled by default on CPUs with neural-network-focused hardware features such as AVX512_VNNI, AVX512_BF16, AMX, etc. No need to set environment variable.
126127
127128
### Validated Models
128129
Intel® Neural Compressor validated 420+ [examples](./examples) with performance speedup geomean 2.2x and up to 4.2x on VNNI while minimizing the accuracy loss.

neural_compressor/adaptor/tf_utils/graph_converter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import logging
2222
import tempfile
2323
import tensorflow as tf
24+
2425
from collections import OrderedDict, UserDict
2526
from tensorflow.core.framework import graph_pb2
2627
from tensorflow.python.framework import tensor_util
@@ -62,7 +63,7 @@
6263
from neural_compressor.adaptor.tf_utils.graph_rewriter.graph_util import GraphRewriterHelper as Helper
6364

6465

65-
TF_SUPPORTED_MAX_VERSION = '2.8.0'
66+
TF_SUPPORTED_MAX_VERSION = '2.9.1'
6667
TF_SUPPORTED_MIN_VERSION = '1.14.0'
6768

6869
logger = logging.getLogger()
@@ -200,6 +201,9 @@ def _check_tf_version(self):
200201
if tf.version.VERSION >= '2.6.0' and os.getenv('TF_ENABLE_ONEDNN_OPTS') == '1':
201202
is_supported_version = True
202203

204+
if tf.version.VERSION >= '2.9.0':
205+
is_supported_version = True
206+
203207
except Exception as e:
204208
raise ValueError(e)
205209
finally:
@@ -213,11 +217,12 @@ def _check_tf_version(self):
213217
TF_SUPPORTED_MAX_VERSION))
214218
if tf.version.VERSION == '2.5.0' and os.getenv('TF_ENABLE_MKL_NATIVE_FORMAT') != '0':
215219
logger.fatal("Please set environment variable TF_ENABLE_MKL_NATIVE_FORMAT=0 "
216-
"when Tensorflow 2.5.0 installed.")
220+
"when TensorFlow 2.5.0 installed.")
217221

218-
if tf.version.VERSION >= '2.6.0' and os.getenv('TF_ENABLE_ONEDNN_OPTS') != '1':
222+
if tf.version.VERSION >= '2.6.0' and tf.version.VERSION < '2.9.0' \
223+
and os.getenv('TF_ENABLE_ONEDNN_OPTS') != '1':
219224
logger.fatal("Please set environment variable TF_ENABLE_ONEDNN_OPTS=1 "
220-
"when Tensorflow >= 2.6.0 installed.")
225+
"when TensorFlow >= 2.6.0 and < 2.9.0 installed.")
221226

222227
if not is_supported_version:
223228
raise ValueError(

neural_compressor/adaptor/tf_utils/graph_converter_without_calib.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
import logging
2222
import tensorflow as tf
23+
2324
from tensorflow.python.platform import gfile
2425
from neural_compressor.conf.dotdict import deep_get
2526
from neural_compressor.experimental.common import Model
@@ -45,7 +46,7 @@
4546
from .graph_rewriter.int8.rnn_convert import QuantizedRNNConverter
4647

4748

48-
TF_SUPPORTED_MAX_VERSION = '2.6.2'
49+
TF_SUPPORTED_MAX_VERSION = '2.9.1'
4950
TF_SUPPORTED_MIN_VERSION = '1.14.0'
5051

5152
logger = logging.getLogger()
@@ -102,9 +103,13 @@ def _check_tf_version(self):
102103
from tensorflow.python._pywrap_util_port import IsMklEnabled
103104
if IsMklEnabled() and (TF_SUPPORTED_MIN_VERSION <= tf.version.VERSION):
104105
is_supported_version = True
106+
107+
if tf.version.VERSION >= '2.6.0' and os.getenv('TF_ENABLE_ONEDNN_OPTS') == '1':
108+
is_supported_version = True
105109

106-
if tf.version.VERSION.find('2.6.') != -1 and os.getenv('TF_ENABLE_ONEDNN_OPTS') == '1':
110+
if tf.version.VERSION >= '2.9.0':
107111
is_supported_version = True
112+
108113
except Exception as e:
109114
raise ValueError(e)
110115
finally:# pragma: no cover
@@ -117,12 +122,13 @@ def _check_tf_version(self):
117122
TF_SUPPORTED_MIN_VERSION,
118123
TF_SUPPORTED_MAX_VERSION))
119124
if tf.version.VERSION == '2.5.0' and os.getenv('TF_ENABLE_MKL_NATIVE_FORMAT') != '0':
120-
logger.warning("Please set environment variable TF_ENABLE_MKL_NATIVE_FORMAT=0 "
121-
"when Tensorflow 2.5.0 installed.")
125+
logger.fatal("Please set environment variable TF_ENABLE_MKL_NATIVE_FORMAT=0 "
126+
"when TensorFlow 2.5.0 installed.")
122127

123-
if tf.version.VERSION.find('2.6.') != -1 and os.getenv('TF_ENABLE_ONEDNN_OPTS') != '1':
124-
logger.warning("Please set environment variable TF_ENABLE_ONEDNN_OPTS=1 "
125-
"when Tensorflow 2.6.x installed.")
128+
if tf.version.VERSION >= '2.6.0' and tf.version.VERSION < '2.9.0' \
129+
and os.getenv('TF_ENABLE_ONEDNN_OPTS') != '1':
130+
logger.fatal("Please set environment variable TF_ENABLE_ONEDNN_OPTS=1 "
131+
"when TensorFlow >= 2.6.0 and < 2.9.0 installed.")
126132

127133
if not is_supported_version:
128134
raise ValueError(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def do_transformation(self):
3737
valid_ops = ('BiasAdd', 'Add', 'AddV2', 'AddN')
3838
target_nodes = g.query_fusion_pattern_nodes([['MatMul', 'Conv2D'],])
3939
for i in target_nodes:
40-
# only apply this pass for tensorflow release 2.8.0 and lower version for
40+
# only apply this pass for tensorflow release 2.9.1 and lower version for
4141
# old quantization API.
4242
# use conv+dummy_biasadd+relu because TF do not support conv+relu now.
43-
if tf.version.VERSION >= '2.9.0':
43+
if tf.version.VERSION > '2.9.1':
4444
continue
4545
if i[0] in self.outputs:
4646
continue

0 commit comments

Comments
 (0)