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

Commit

Permalink
Merge branch 'master' into r0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
avijit-nervana committed Apr 2, 2019
2 parents 6bae7fd + 987a300 commit e18b78f
Show file tree
Hide file tree
Showing 40 changed files with 1,678 additions and 235 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ if (NOT USE_PRE_BUILT_NGRAPH)
ExternalProject_Add(
ext_ngraph
GIT_REPOSITORY https://github.com/NervanaSystems/ngraph
GIT_TAG v0.16.0-rc.2
GIT_TAG v0.16.0-rc.3
CMAKE_ARGS
-DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE}
-DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ a variety of nGraph-enabled backends: CPU, GPU, and custom silicon like the
This will produce something like this:

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

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

git clone https://github.com/NervanaSystems/ngraph-tf.git
cd ngraph-tf
git checkout v0.12.0-rc1
git checkout v0.12.0-rc2


2. Next run the following Python script to build TensorFlow, nGraph and the bridge. Please use Python 3.5:
Expand Down
13 changes: 11 additions & 2 deletions build_ngtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def main():
help="Builds a distributed version of the nGraph components\n",
action="store")

parser.add_argument(
'--use_grappler_optimizer',
help="Use Grappler optimizer instead of the optimization passes\n",
action="store_true")

parser.add_argument(
'--artifacts_dir',
type=str,
help="Copy the artifacts to the given directory\n",
action="store")

arguments = parser.parse_args()

if (arguments.debug_build):
Expand All @@ -86,7 +90,7 @@ def main():
#-------------------------------

# Component versions
ngraph_version = "v0.16.0-rc.2"
ngraph_version = "v0.16.0-rc.3"
tf_version = "v1.13.1"

# Default directories
Expand Down Expand Up @@ -229,6 +233,11 @@ def main():
else:
ngraph_tf_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_ENABLE=FALSE"])

if (arguments.use_grappler_optimizer):
ngraph_tf_cmake_flags.extend(["-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER=TRUE"])
else:
ngraph_tf_cmake_flags.extend(["-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER=FALSE"])

# Now build the bridge
ng_tf_whl = build_ngraph_tf(build_dir, artifacts_location, ngraph_tf_src_dir, venv_dir,
ngraph_tf_cmake_flags, verbosity)
Expand Down
14 changes: 9 additions & 5 deletions diagnostics/model_accuracy/verify_inference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def run_inference(model_name, models_dir):
command_executor("export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`")
command_executor('git apply ' + pwd +
'/image_recognition.patch')

p = command_executor(data[i]["cmd"])
os.chdir(pwd)
return model_name, p
Expand All @@ -99,7 +98,7 @@ def check_accuracy(model, p):
data = json.loads(accuracy)

for line in p.splitlines():
print(line)
print(line.decode())
if ('eval/Accuracy'.encode() in line):
top1_accuracy = re.search("\[(.*?)\]", line.decode()).group(1)
#for now we just validate top 1 accuracy, but calculating top5 anyway.
Expand All @@ -111,13 +110,18 @@ def check_accuracy(model, p):
if (model in data[i]["model_name"]):
# Tolerance check
diff = abs(float(top1_accuracy) - float(data[i]["accuracy"]))
print('\033[1m' + '\nModel Accuracy Verification' + '\033[0m')
if (diff <= 0.001):
print("\nRESULT: Functional accuracy " + top1_accuracy +
print('\033[92m' + 'PASS' + '\033[0m' +
" Functional accuracy " + top1_accuracy +
" is as expected for " + data[i]["model_name"])
return True
else:
print("\nRESULT: Functional accuracy " + top1_accuracy +
print('\033[91m' + 'FAIL' + '\033[0m' +
" Functional accuracy " + top1_accuracy +
" is not as expected for " + data[i]["model_name"] +
"\nExpected accuracy is " + data[i]["accuracy"])
"\nExpected accuracy = " + data[i]["accuracy"])
return False


if __name__ == '__main__':
Expand Down
16 changes: 16 additions & 0 deletions examples/mnist/mnist_deep_simplified.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import time

from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.core.protobuf import rewriter_config_pb2

import tensorflow as tf
import ngraph_bridge
Expand Down Expand Up @@ -129,6 +130,15 @@ def train_mnist_cnn(FLAGS):
allow_soft_placement=True,
log_device_placement=False,
inter_op_parallelism_threads=1)
# Enable the custom optimizer using the rewriter config options
if (FLAGS.use_grappler):
rewrite_options = rewriter_config_pb2.RewriterConfig(custom_optimizers=[
rewriter_config_pb2.RewriterConfig.CustomGraphOptimizer(
name="ngraph-optimizer")
])
config.MergeFrom(
tf.ConfigProto(
graph_options=tf.GraphOptions(rewrite_options=rewrite_options)))

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

parser.add_argument(
'--use_grappler',
type=bool,
default=False,
help='Use grappler - NgraphOptimizer')

FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
15 changes: 8 additions & 7 deletions examples/mnist/mnist_softmax_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ def run_mnist(_):

# Test trained model
if not mon_sess.should_stop():
print("Accuracy: ",
mon_sess.run(
accuracy,
feed_dict={
x: mnist.test.images,
y_: mnist.test.labels
}))
print(
"Accuracy: ",
mon_sess.run(
accuracy,
feed_dict={
x: mnist.test.images,
y_: mnist.test.labels
}))

end = time.time()

Expand Down
18 changes: 9 additions & 9 deletions maint/apply-code-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare SRC_DIRS="src examples test logging tools diagnostics python"
# - The particular version of the `clang-format` program being used.
#
# For this reason, this script specifies the exact version of clang-format to be used.
# Similarly for python/yapf, we shall use Python 2 and yapf 0.24
# Similarly for python/yapf, we shall use Python 3 and yapf 0.26.0
declare _intelnervana_clang_format_lib_SCRIPT_NAME="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}"
declare _maint_SCRIPT_DIR="$( cd $(dirname "${_intelnervana_clang_format_lib_SCRIPT_NAME}") && pwd )"
source "${_maint_SCRIPT_DIR}/bash_lib.sh"
Expand All @@ -36,11 +36,11 @@ else
SED_FLAGS='-rn'
fi

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

declare CLANG_FORMAT_BASENAME="clang-format-3.9"
declare REQUIRED_CLANG_FORMAT_VERSION=3.9
if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
declare YAPF_FORMAT_BASENAME="yapf"
declare REQUIRED_YAPF_FORMAT_VERSION=0.24
declare REQUIRED_YAPF_FORMAT_VERSION=0.26
fi

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

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

format_lib_verify_version "${CLANG_FORMAT_PROG}" "${REQUIRED_CLANG_FORMAT_VERSION}" "CLANG"
bash_lib_status "Verified that '${CLANG_FORMAT_PROG}' has version '${REQUIRED_CLANG_FORMAT_VERSION}'"
if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
format_lib_verify_version "${YAPF_FORMAT_PROG}" "${REQUIRED_YAPF_FORMAT_VERSION}" "YAPF"
bash_lib_status "Verified that '${YAPF_FORMAT_PROG}' has version '${REQUIRED_YAPF_FORMAT_VERSION}'"
fi
Expand Down Expand Up @@ -104,7 +104,7 @@ for ROOT_SUBDIR in ${SRC_DIRS}; do

bash_lib_status "Done."

if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
bash_lib_status "About to format Python code in directory tree '$(pwd)/${ROOT_SUBDIR}' ..."
declare SRC_FILE
# ignore the .in.py file (python/setup.in.py) which has format that crashes yapf
Expand Down
20 changes: 10 additions & 10 deletions maint/check-code-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare SRC_DIRS="src examples test logging tools diagnostics python"
# - The particular version of the `clang-format` program being used.
#
# For this reason, this script specifies the exact version of clang-format to be used.
# Similarly for python/yapf, we shall use Python 2 and yapf 0.24
# Similarly for python/yapf, we shall use Python 3 and yapf 0.26.0

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

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

declare CLANG_FORMAT_BASENAME="clang-format-3.9"
declare REQUIRED_CLANG_FORMAT_VERSION=3.9
if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
declare YAPF_FORMAT_BASENAME="yapf"
declare REQUIRED_YAPF_FORMAT_VERSION=0.24
declare REQUIRED_YAPF_FORMAT_VERSION=0.26
fi

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

if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
declare YAPF_FORMAT_PROG
if ! YAPF_FORMAT_PROG="$(which "${YAPF_FORMAT_BASENAME}")"; then
bash_lib_die "Unable to find program ${YAPF_FORMAT_BASENAME}" >&2
Expand All @@ -76,7 +76,7 @@ format_lib_verify_version "${CLANG_FORMAT_PROG}" "${REQUIRED_CLANG_FORMAT_VERSIO
bash_lib_status "Verified that '${CLANG_FORMAT_PROG}' has version '${REQUIRED_CLANG_FORMAT_VERSION}'"
declare -a FAILED_FILES_CLANG=()
declare NUM_FILES_CHECKED_CLANG=0
if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
format_lib_verify_version "${YAPF_FORMAT_PROG}" "${REQUIRED_YAPF_FORMAT_VERSION}" "YAPF"
bash_lib_status "Verified that '${YAPF_FORMAT_PROG}' has version '${REQUIRED_YAPF_FORMAT_VERSION}'"
declare -a FAILED_FILES_YAPF=()
Expand Down Expand Up @@ -109,7 +109,7 @@ for ROOT_SUBDIR in ${SRC_DIRS}; do
NUM_FILES_CHECKED_CLANG=$((NUM_FILES_CHECKED_CLANG+1))
done

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

if [[ "2" == "${PYTHON_VERSION}" ]]; then
if [[ "3" == "${PYTHON_VERSION}" ]]; then
if [[ ${#FAILED_FILES_YAPF[@]} -eq 0 ]]; then
bash_lib_status "All ${NUM_FILES_CHECKED_YAPF} Python files pass the code-format check."
else
Expand Down
2 changes: 1 addition & 1 deletion python/setup.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_tag(self):

setup(
name='ngraph_tensorflow_bridge',
version='0.12.0rc1',
version='0.12.0rc2',
description='Intel nGraph compiler and runtime for TensorFlow',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ set(SRC
ngraph_freshness_tracker.cc
ngraph_mark_for_clustering.cc
ngraph_rewrite_for_tracking.cc
ngraph_rewrite_pass.cc
ngraph_tracked_variable.cc
ngraph_utils.cc
ngraph_timer.cc
Expand All @@ -52,6 +51,15 @@ set(SRC
version.cc
)

if(NGRAPH_TF_USE_GRAPPLER_OPTIMIZER)
list(APPEND SRC grappler/ngraph_optimizer.cc)
add_definitions(-DNGRAPH_TF_USE_GRAPPLER_OPTIMIZER)
else()
list(APPEND SRC ngraph_rewrite_pass.cc)
endif()

message(STATUS "NGRAPH_TF_USE_GRAPPLER_OPTIMIZER: ${NGRAPH_TF_USE_GRAPPLER_OPTIMIZER}")

add_library(${LIB_NAME} SHARED ${SRC})

target_link_libraries( ${LIB_NAME} ngraph_logger)
Expand Down
Loading

0 comments on commit e18b78f

Please sign in to comment.