Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit e18b78f

Browse files
Merge branch 'master' into r0.12
2 parents 6bae7fd + 987a300 commit e18b78f

40 files changed

+1678
-235
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ if (NOT USE_PRE_BUILT_NGRAPH)
239239
ExternalProject_Add(
240240
ext_ngraph
241241
GIT_REPOSITORY https://github.com/NervanaSystems/ngraph
242-
GIT_TAG v0.16.0-rc.2
242+
GIT_TAG v0.16.0-rc.3
243243
CMAKE_ARGS
244244
-DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE}
245245
-DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ a variety of nGraph-enabled backends: CPU, GPU, and custom silicon like the
4242
This will produce something like this:
4343

4444
TensorFlow version: 1.13.1
45-
nGraph bridge version: b'0.12.0-rc1'
45+
nGraph bridge version: b'0.12.0-rc2'
4646
nGraph version used for this build: b'0.21.0-rc.0+b638705'
4747
TensorFlow version used for this build: v1.13.1-0-g6612da8951
4848

@@ -84,7 +84,7 @@ The installation prerequisites are the same as described in the TensorFlow
8484

8585
git clone https://github.com/NervanaSystems/ngraph-tf.git
8686
cd ngraph-tf
87-
git checkout v0.12.0-rc1
87+
git checkout v0.12.0-rc2
8888

8989

9090
2. Next run the following Python script to build TensorFlow, nGraph and the bridge. Please use Python 3.5:

build_ngtf.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ def main():
6565
help="Builds a distributed version of the nGraph components\n",
6666
action="store")
6767

68+
parser.add_argument(
69+
'--use_grappler_optimizer',
70+
help="Use Grappler optimizer instead of the optimization passes\n",
71+
action="store_true")
72+
6873
parser.add_argument(
6974
'--artifacts_dir',
7075
type=str,
7176
help="Copy the artifacts to the given directory\n",
7277
action="store")
73-
7478
arguments = parser.parse_args()
7579

7680
if (arguments.debug_build):
@@ -86,7 +90,7 @@ def main():
8690
#-------------------------------
8791

8892
# Component versions
89-
ngraph_version = "v0.16.0-rc.2"
93+
ngraph_version = "v0.16.0-rc.3"
9094
tf_version = "v1.13.1"
9195

9296
# Default directories
@@ -229,6 +233,11 @@ def main():
229233
else:
230234
ngraph_tf_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_ENABLE=FALSE"])
231235

236+
if (arguments.use_grappler_optimizer):
237+
ngraph_tf_cmake_flags.extend(["-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER=TRUE"])
238+
else:
239+
ngraph_tf_cmake_flags.extend(["-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER=FALSE"])
240+
232241
# Now build the bridge
233242
ng_tf_whl = build_ngraph_tf(build_dir, artifacts_location, ngraph_tf_src_dir, venv_dir,
234243
ngraph_tf_cmake_flags, verbosity)

diagnostics/model_accuracy/verify_inference_model.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def run_inference(model_name, models_dir):
8282
command_executor("export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`")
8383
command_executor('git apply ' + pwd +
8484
'/image_recognition.patch')
85-
8685
p = command_executor(data[i]["cmd"])
8786
os.chdir(pwd)
8887
return model_name, p
@@ -99,7 +98,7 @@ def check_accuracy(model, p):
9998
data = json.loads(accuracy)
10099

101100
for line in p.splitlines():
102-
print(line)
101+
print(line.decode())
103102
if ('eval/Accuracy'.encode() in line):
104103
top1_accuracy = re.search("\[(.*?)\]", line.decode()).group(1)
105104
#for now we just validate top 1 accuracy, but calculating top5 anyway.
@@ -111,13 +110,18 @@ def check_accuracy(model, p):
111110
if (model in data[i]["model_name"]):
112111
# Tolerance check
113112
diff = abs(float(top1_accuracy) - float(data[i]["accuracy"]))
113+
print('\033[1m' + '\nModel Accuracy Verification' + '\033[0m')
114114
if (diff <= 0.001):
115-
print("\nRESULT: Functional accuracy " + top1_accuracy +
115+
print('\033[92m' + 'PASS' + '\033[0m' +
116+
" Functional accuracy " + top1_accuracy +
116117
" is as expected for " + data[i]["model_name"])
118+
return True
117119
else:
118-
print("\nRESULT: Functional accuracy " + top1_accuracy +
120+
print('\033[91m' + 'FAIL' + '\033[0m' +
121+
" Functional accuracy " + top1_accuracy +
119122
" is not as expected for " + data[i]["model_name"] +
120-
"\nExpected accuracy is " + data[i]["accuracy"])
123+
"\nExpected accuracy = " + data[i]["accuracy"])
124+
return False
121125

122126

123127
if __name__ == '__main__':

examples/mnist/mnist_deep_simplified.py

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import time
3636

3737
from tensorflow.examples.tutorials.mnist import input_data
38+
from tensorflow.core.protobuf import rewriter_config_pb2
3839

3940
import tensorflow as tf
4041
import ngraph_bridge
@@ -129,6 +130,15 @@ def train_mnist_cnn(FLAGS):
129130
allow_soft_placement=True,
130131
log_device_placement=False,
131132
inter_op_parallelism_threads=1)
133+
# Enable the custom optimizer using the rewriter config options
134+
if (FLAGS.use_grappler):
135+
rewrite_options = rewriter_config_pb2.RewriterConfig(custom_optimizers=[
136+
rewriter_config_pb2.RewriterConfig.CustomGraphOptimizer(
137+
name="ngraph-optimizer")
138+
])
139+
config.MergeFrom(
140+
tf.ConfigProto(
141+
graph_options=tf.GraphOptions(rewrite_options=rewrite_options)))
132142

133143
# Note: Additional configuration option to boost performance is to set the
134144
# following environment for the run:
@@ -250,5 +260,11 @@ def main(_):
250260
default='./mnist_trained/',
251261
help='enter model dir')
252262

263+
parser.add_argument(
264+
'--use_grappler',
265+
type=bool,
266+
default=False,
267+
help='Use grappler - NgraphOptimizer')
268+
253269
FLAGS, unparsed = parser.parse_known_args()
254270
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)

examples/mnist/mnist_softmax_distributed.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,14 @@ def run_mnist(_):
116116

117117
# Test trained model
118118
if not mon_sess.should_stop():
119-
print("Accuracy: ",
120-
mon_sess.run(
121-
accuracy,
122-
feed_dict={
123-
x: mnist.test.images,
124-
y_: mnist.test.labels
125-
}))
119+
print(
120+
"Accuracy: ",
121+
mon_sess.run(
122+
accuracy,
123+
feed_dict={
124+
x: mnist.test.images,
125+
y_: mnist.test.labels
126+
}))
126127

127128
end = time.time()
128129

maint/apply-code-format.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare SRC_DIRS="src examples test logging tools diagnostics python"
2525
# - The particular version of the `clang-format` program being used.
2626
#
2727
# For this reason, this script specifies the exact version of clang-format to be used.
28-
# Similarly for python/yapf, we shall use Python 2 and yapf 0.24
28+
# Similarly for python/yapf, we shall use Python 3 and yapf 0.26.0
2929
declare _intelnervana_clang_format_lib_SCRIPT_NAME="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}"
3030
declare _maint_SCRIPT_DIR="$( cd $(dirname "${_intelnervana_clang_format_lib_SCRIPT_NAME}") && pwd )"
3131
source "${_maint_SCRIPT_DIR}/bash_lib.sh"
@@ -36,11 +36,11 @@ else
3636
SED_FLAGS='-rn'
3737
fi
3838

39-
# Find out python version. Use yapf only when in Python 2
39+
# Find out python version. Use yapf only when in Python 3
4040
if PYTHON_VERSION=$(python -c 'import sys; print(sys.version_info[:][0])')
4141
then
42-
if [[ "2" != "${PYTHON_VERSION}" ]]; then
43-
echo "Python reports version number '${PYTHON_VERSION}' so will skip yapf formatting. Please use Python2"
42+
if [[ "3" != "${PYTHON_VERSION}" ]]; then
43+
echo "Python reports version number '${PYTHON_VERSION}' so will skip yapf formatting. Please use Python3"
4444
fi
4545
else
4646
bash_lib_print_error "Failed invocation of Python."
@@ -50,9 +50,9 @@ fi
5050

5151
declare CLANG_FORMAT_BASENAME="clang-format-3.9"
5252
declare REQUIRED_CLANG_FORMAT_VERSION=3.9
53-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
53+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
5454
declare YAPF_FORMAT_BASENAME="yapf"
55-
declare REQUIRED_YAPF_FORMAT_VERSION=0.24
55+
declare REQUIRED_YAPF_FORMAT_VERSION=0.26
5656
fi
5757

5858
declare THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -65,7 +65,7 @@ if ! CLANG_FORMAT_PROG="$(which "${CLANG_FORMAT_BASENAME}")"; then
6565
bash_lib_die "Unable to find program ${CLANG_FORMAT_BASENAME}" >&2
6666
fi
6767

68-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
68+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
6969
declare YAPF_FORMAT_PROG
7070
if ! YAPF_FORMAT_PROG="$(which "${YAPF_FORMAT_BASENAME}")"; then
7171
bash_lib_die "Unable to find program ${YAPF_FORMAT_BASENAME}" >&2
@@ -74,7 +74,7 @@ fi
7474

7575
format_lib_verify_version "${CLANG_FORMAT_PROG}" "${REQUIRED_CLANG_FORMAT_VERSION}" "CLANG"
7676
bash_lib_status "Verified that '${CLANG_FORMAT_PROG}' has version '${REQUIRED_CLANG_FORMAT_VERSION}'"
77-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
77+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
7878
format_lib_verify_version "${YAPF_FORMAT_PROG}" "${REQUIRED_YAPF_FORMAT_VERSION}" "YAPF"
7979
bash_lib_status "Verified that '${YAPF_FORMAT_PROG}' has version '${REQUIRED_YAPF_FORMAT_VERSION}'"
8080
fi
@@ -104,7 +104,7 @@ for ROOT_SUBDIR in ${SRC_DIRS}; do
104104

105105
bash_lib_status "Done."
106106

107-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
107+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
108108
bash_lib_status "About to format Python code in directory tree '$(pwd)/${ROOT_SUBDIR}' ..."
109109
declare SRC_FILE
110110
# ignore the .in.py file (python/setup.in.py) which has format that crashes yapf

maint/check-code-format.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare SRC_DIRS="src examples test logging tools diagnostics python"
2525
# - The particular version of the `clang-format` program being used.
2626
#
2727
# For this reason, this script specifies the exact version of clang-format to be used.
28-
# Similarly for python/yapf, we shall use Python 2 and yapf 0.24
28+
# Similarly for python/yapf, we shall use Python 3 and yapf 0.26.0
2929

3030
declare _intelnervana_clang_format_lib_SCRIPT_NAME="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}"
3131
declare _maint_SCRIPT_DIR="$( cd $(dirname "${_intelnervana_clang_format_lib_SCRIPT_NAME}") && pwd )"
@@ -37,11 +37,11 @@ else
3737
SED_FLAGS='-rn'
3838
fi
3939

40-
# Find out python version. Use yapf only when in Python 2
40+
# Find out python version. Use yapf only when in Python 3
4141
if PYTHON_VERSION=$(python -c 'import sys; print(sys.version_info[:][0])')
4242
then
43-
if [[ "2" != "${PYTHON_VERSION}" ]]; then
44-
echo "Python reports version number '${PYTHON_VERSION}' so will skip yapf formatting. Please use Python2"
43+
if [[ "3" != "${PYTHON_VERSION}" ]]; then
44+
echo "Python reports version number '${PYTHON_VERSION}' so will skip yapf formatting. Please use Python3"
4545
fi
4646
else
4747
bash_lib_print_error "Failed invocation of Python."
@@ -50,9 +50,9 @@ fi
5050

5151
declare CLANG_FORMAT_BASENAME="clang-format-3.9"
5252
declare REQUIRED_CLANG_FORMAT_VERSION=3.9
53-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
53+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
5454
declare YAPF_FORMAT_BASENAME="yapf"
55-
declare REQUIRED_YAPF_FORMAT_VERSION=0.24
55+
declare REQUIRED_YAPF_FORMAT_VERSION=0.26
5656
fi
5757

5858
declare THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -65,7 +65,7 @@ if ! CLANG_FORMAT_PROG="$(which "${CLANG_FORMAT_BASENAME}")"; then
6565
bash_lib_die "Unable to find program ${CLANG_FORMAT_BASENAME}" >&2
6666
fi
6767

68-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
68+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
6969
declare YAPF_FORMAT_PROG
7070
if ! YAPF_FORMAT_PROG="$(which "${YAPF_FORMAT_BASENAME}")"; then
7171
bash_lib_die "Unable to find program ${YAPF_FORMAT_BASENAME}" >&2
@@ -76,7 +76,7 @@ format_lib_verify_version "${CLANG_FORMAT_PROG}" "${REQUIRED_CLANG_FORMAT_VERSIO
7676
bash_lib_status "Verified that '${CLANG_FORMAT_PROG}' has version '${REQUIRED_CLANG_FORMAT_VERSION}'"
7777
declare -a FAILED_FILES_CLANG=()
7878
declare NUM_FILES_CHECKED_CLANG=0
79-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
79+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
8080
format_lib_verify_version "${YAPF_FORMAT_PROG}" "${REQUIRED_YAPF_FORMAT_VERSION}" "YAPF"
8181
bash_lib_status "Verified that '${YAPF_FORMAT_PROG}' has version '${REQUIRED_YAPF_FORMAT_VERSION}'"
8282
declare -a FAILED_FILES_YAPF=()
@@ -109,7 +109,7 @@ for ROOT_SUBDIR in ${SRC_DIRS}; do
109109
NUM_FILES_CHECKED_CLANG=$((NUM_FILES_CHECKED_CLANG+1))
110110
done
111111

112-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
112+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
113113
bash_lib_status "About to check formatting of Python code in directory tree '$(pwd)/${ROOT_SUBDIR}' ..."
114114
declare SRC_FILE
115115
# ignore the .in.py file (python/setup.in.py) which has format that crashes yapf
@@ -139,7 +139,7 @@ else
139139
exit 1
140140
fi
141141

142-
if [[ "2" == "${PYTHON_VERSION}" ]]; then
142+
if [[ "3" == "${PYTHON_VERSION}" ]]; then
143143
if [[ ${#FAILED_FILES_YAPF[@]} -eq 0 ]]; then
144144
bash_lib_status "All ${NUM_FILES_CHECKED_YAPF} Python files pass the code-format check."
145145
else

python/setup.in.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_tag(self):
3939

4040
setup(
4141
name='ngraph_tensorflow_bridge',
42-
version='0.12.0rc1',
42+
version='0.12.0rc2',
4343
description='Intel nGraph compiler and runtime for TensorFlow',
4444
long_description=long_description,
4545
long_description_content_type="text/markdown",

src/CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ set(SRC
4343
ngraph_freshness_tracker.cc
4444
ngraph_mark_for_clustering.cc
4545
ngraph_rewrite_for_tracking.cc
46-
ngraph_rewrite_pass.cc
4746
ngraph_tracked_variable.cc
4847
ngraph_utils.cc
4948
ngraph_timer.cc
@@ -52,6 +51,15 @@ set(SRC
5251
version.cc
5352
)
5453

54+
if(NGRAPH_TF_USE_GRAPPLER_OPTIMIZER)
55+
list(APPEND SRC grappler/ngraph_optimizer.cc)
56+
add_definitions(-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER)
57+
else()
58+
list(APPEND SRC ngraph_rewrite_pass.cc)
59+
endif()
60+
61+
message(STATUS "NGRAPH_TF_USE_GRAPPLER_OPTIMIZER: ${NGRAPH_TF_USE_GRAPPLER_OPTIMIZER}")
62+
5563
add_library(${LIB_NAME} SHARED ${SRC})
5664

5765
target_link_libraries( ${LIB_NAME} ngraph_logger)

0 commit comments

Comments
 (0)