Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9fd8350
Made changes to NGraphAssignOp
Jul 13, 2019
8e5a8ea
Added utilities to remove the enteries from the catalog maps. Removed…
Jul 15, 2019
1685709
Remove entries from Catalog in NGVariable Destructors.
Jul 15, 2019
8c3dd80
Modifications to catalog. Compiles
Jul 16, 2019
6b7e296
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
Jul 19, 2019
6c2dd52
Code Format
Jul 19, 2019
b2f0f02
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
Jul 19, 2019
bc9b16a
Not using RemoveEdge Api. Made changes to RewritePass
Jul 23, 2019
a2f1336
changes to get var before compute
Jul 23, 2019
6f75433
Made changes to remove edges right way.Added syncing in encap
Jul 23, 2019
aeb8514
Removed Enacap Output Tensor Map
Jul 24, 2019
9059154
Updated Comments
Jul 24, 2019
48bf3fe
Updated Comments
Jul 24, 2019
5b40ff9
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
Jul 24, 2019
4b1a475
Integrate with output cache
Jul 24, 2019
6e49e07
Update ngraph_bridge/enable_variable_ops/ngraph_enter_in_catalog.h
Jul 24, 2019
c80ade7
Minor
Jul 24, 2019
9beda76
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
Jul 24, 2019
d4b647c
minor
Jul 24, 2019
19d1839
Formatted for formatting
Jul 24, 2019
b44cee0
Update ngraph_bridge/ngraph_encapsulate_op.cc
Jul 24, 2019
702c2ae
Merge branch 'master' into shrestha/Integrate_RemoveNGAssign
sayantan-nervana Jul 25, 2019
3fa1df0
Kanvi/remove additional attr check (#150)
kanvi-nervana Jul 25, 2019
ca9f62b
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
Jul 25, 2019
b4ed01a
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
Jul 25, 2019
b8944f7
Merge pull request #152 from tensorflow/shrestha/Integrate_RemoveNGAs…
Jul 25, 2019
65348d7
sarkars/destructor order (#146)
sayantan-nervana Jul 25, 2019
652cca8
Update bridge version number
sayantan-nervana Jul 26, 2019
a10636b
sarkars/Possible fix for backend settings (#159)
sayantan-nervana Jul 26, 2019
2454cc5
Sarkars/update tf2ngraph to use rewriterconfig (#149)
sayantan-nervana Jul 26, 2019
20a6394
Upgrade to 0.17.0rc1 (#163)
sayantan-nervana Jul 26, 2019
5a040c7
Upgrade nGraph Core to 0.24.0-rc.2 (#166)
Jul 26, 2019
0b64823
Avijit/bazel cleanup (#140)
avijit-nervana Jul 29, 2019
951ca46
Shrestha/Fix --num_inter_threads (#175)
Aug 1, 2019
f0e85ae
sarkars/Upgrade to ngcore24 (#180)
sayantan-nervana Aug 1, 2019
fd1d713
Sindhu/pad op python test (#187)
sindhu-nervana Aug 7, 2019
12aa7e9
Sindhu/bfloat16 op tests (#183)
sindhu-nervana Aug 8, 2019
01a5698
Merge remote-tracking branch 'origin/master' into shrestha/upgrade_r1…
Aug 8, 2019
a68e5b4
Fixed version issue
Aug 8, 2019
478c89e
Kanvi/bfloat16 tests (#185)
kanvi-nervana Aug 8, 2019
ae0d9c4
Merge remote-tracking branch 'origin/master' into shrestha/upgrade_r1…
Aug 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ngraph_bridge/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// candidate such as v0.7.0-rc0
// The code in master will always have the last released version number
// with a suffix of '-master'
#define NG_TF_VERSION_SUFFIX "-rc2"
#define NG_TF_VERSION_SUFFIX "-rc3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this version. Other changes are from merging with master


#define VERSION_STR_HELPER(x) #x
#define VERSION_STR(x) VERSION_STR_HELPER(x)
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ if (NGRAPH_PLAIDML_ENABLE)
endif()

add_subdirectory(python)
add_subdirectory(python/bfloat16)
add_subdirectory(model_level_tests)

if (DEFINED NGRAPH_TF_INSTALL_PREFIX)
Expand Down
23 changes: 23 additions & 0 deletions test/python/bfloat16/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2019 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.4)

file(GLOB files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.py")
foreach(file ${files})
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_SOURCE_DIR}/${file}
${CMAKE_CURRENT_BINARY_DIR}/${file}
)
endforeach()
107 changes: 107 additions & 0 deletions test/python/bfloat16/test_conv2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# ==============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""nGraph TensorFlow bridge Conv2d operation test

"""
import pytest

import tensorflow as tf
import numpy as np
import os

import ngraph_bridge

#Test Ngraph Op Convolution, TF Op:conv2d
# Implemented based on NNP's unit test TEST(test_assign_layout, convolution_special_case)

np.random.seed(5)

# Colvolution Op is placed on NNP and conerted to
# bfloat16 only for the special case below, otherwise it falls
# back to CPU for compute
# Check to assure:
# The input rank is 4-D
# The stride is less than the filter size
# The Window and Data dilation is {1,1}
# Filter shape is allowed
# If any fail, then we should place Op on CPU for compute

#Inputs
N = 1
C = 1
H = 3
W = 5

filter_size = np.random.rand(1, 1, 1, 2)
input_size_nhwc = [N, H, W, C]
input_size_nchw = [N, C, H, W]
input_nhwc = tf.placeholder(tf.float32, shape=input_size_nhwc, name='x')
input_nchw = tf.placeholder(tf.float32, shape=input_size_nchw, name='x')

n_np = np.random.rand(*input_size_nchw).astype('f')
#Tensorflow supports only NHWC, change input shapes from NCHW to NHWC
t_np = np.transpose(n_np, (0, 2, 3, 1))


#TF graph
def tf_model():
stride_nhwc = [1, 2, 2, 1]
x = tf.cast(input_nhwc, dtype=tf.bfloat16)
filter_cast = tf.cast(filter_size, dtype=tf.bfloat16)
m = tf.nn.conv2d(
x, filter_cast, stride_nhwc, "SAME", data_format="NHWC", name="m")
m = tf.cast(m, dtype=tf.float32)
return m, input_nhwc


#Ngraph graph
def ng_model():
stride_nchw = [1, 1, 2, 2]
m = tf.nn.conv2d(
input_nchw,
filter_size,
stride_nchw,
"SAME",
data_format="NCHW",
name="m")
return m, input_nchw


config = tf.ConfigProto(
allow_soft_placement=True,
log_device_placement=False,
inter_op_parallelism_threads=1)


def test_conv2d():
#Test 1: tf_model TF-native
with tf.Session(config=config) as sess_tf:
ngraph_bridge.disable()
tf_out, input_data = tf_model()
feed_dict = {input_data: t_np}
tf_outval = sess_tf.run(tf_out, feed_dict=feed_dict)

#Test 2: model2 with ngraph, NNP backend
with tf.Session(config=config) as sess_ng:
ngraph_bridge.enable()
ngraph_bridge.update_config(config)
os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1'
ng_out, input_data = ng_model()
feed_dict = {input_data: n_np}
ng_outval = sess_ng.run(ng_out, feed_dict=feed_dict)

assert np.allclose(
np.transpose(tf_outval, (0, 3, 1, 2)), ng_outval, rtol=0, atol=1e-02)
116 changes: 116 additions & 0 deletions test/python/bfloat16/test_conv2dbackpropfilter_nchw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# ==============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""nGraph TensorFlow bridge Conv2d operation test

"""
import pytest

import tensorflow as tf
import numpy as np
import os
from tensorflow.python.ops import nn_ops
import ngraph_bridge

#Tests Ngraph Op: ConvolutionBackpropFilters with data format NCHW
#TF Op: conv2d_backprop_filter

np.random.seed(5)
#Inputs
N = 1
H = 7
W = 6
C = 2

I = C
O = 2
filt_width = 3
filt_height = 3

input_sizes_nchw = [N, C, H, W]
input_sizes_nhwc = [N, H, W, C]
filter_size_hwio = [filt_height, filt_width, I, O]
out_backprop_valid = [1, 2, 3, 2]
out_backprop_same = [1, 2, 4, 3]
out_backprop_in_sizes = {"VALID": out_backprop_valid, "SAME": out_backprop_same}
stride_nhwc = [1, 2, 2, 1]
stride_nchw = [1, 1, 2, 2]


#TF graph
def tf_model(padding):
t1 = tf.placeholder(dtype=tf.float32, shape=input_sizes_nhwc, name='t1')
t2 = tf.constant(filter_size_hwio, dtype=tf.int32, name='t2')
t3 = tf.placeholder(
dtype=tf.float32, shape=out_backprop_in_sizes[padding], name='t3')

#reshaping the out_backprop to NHWC since TF does not support NCHW
t3 = tf.transpose(t3, [0, 2, 3, 1])

#Cast dtype to bfloat16 for TF because NNP casts ng_model inputs
t1 = tf.cast(t1, dtype=tf.bfloat16)
t3 = tf.cast(t3, dtype=tf.bfloat16)

filt = nn_ops.conv2d_backprop_filter(
t1, t2, t3, stride_nhwc, padding=padding, data_format='NHWC')

#Cast dtype back to float32 similar to NNP
filt = tf.cast(filt, dtype=tf.float32)
return filt, t1, t3


#Ngraph Graph
def ng_model(padding):
t1 = tf.placeholder(dtype=tf.float32, shape=input_sizes_nchw, name='t1')
t2 = tf.constant(filter_size_hwio, dtype=tf.int32, name='t2')
t3 = tf.placeholder(
dtype=tf.float32, shape=out_backprop_in_sizes[padding], name='t3')

filt = nn_ops.conv2d_backprop_filter(
t1, t2, t3, stride_nchw, padding=padding, data_format='NCHW')
return filt, t1, t3


config = tf.ConfigProto(
allow_soft_placement=True,
log_device_placement=False,
inter_op_parallelism_threads=1)


@pytest.mark.parametrize("padding", ("VALID", "SAME"))
def test_conv2dbackpropfilter_nchw(padding):
n_np_inp = np.random.rand(*input_sizes_nchw).astype('f')
n_np_out = np.random.rand(*out_backprop_in_sizes[padding]).astype('f')

#Reshape to NHWC for TF
t_np_inp = np.transpose(n_np_inp, (0, 2, 3, 1))
t_np_out = np.transpose(n_np_out, (0, 2, 3, 1))

with tf.Session(config=config) as sess_tf:
ngraph_bridge.disable()
tf_out, input_data, out_backprop = tf_model(padding)
feed_dict = {input_data: t_np_inp, out_backprop: t_np_out}
tf_outval = sess_tf.run(tf_out, feed_dict=feed_dict)

#Test 2: model2 with ngraph, NNP backend
with tf.Session(config=config) as sess_ng:
ngraph_bridge.enable()
ngraph_bridge.update_config(config)
os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1'
ng_out, input_data, out_backprop = ng_model(padding)
feed_dict = {input_data: n_np_inp, out_backprop: n_np_out}
ng_outval = sess_ng.run(ng_out, feed_dict=feed_dict)

assert np.allclose(tf_outval, ng_outval, rtol=0, atol=1e-02)
107 changes: 107 additions & 0 deletions test/python/bfloat16/test_conv2dbackpropfilter_nhwc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# ==============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""nGraph TensorFlow bridge Conv2d operation test

"""
import pytest

import tensorflow as tf
import numpy as np
import os
from tensorflow.python.ops import nn_ops
import ngraph_bridge

#Tests Ngraph Op: ConvolutionBackpropFilters with data format NHWC
#TF Op: conv2d_backprop_filter

np.random.seed(5)
#Inputs
N = 1
H = 7
W = 6
C = 2

I = C
O = 2
filt_width = 3
filt_height = 3

input_sizes_nhwc = [N, H, W, C]
filter_size_hwio = [filt_height, filt_width, I, O]
out_backprop_valid = [1, 3, 2, 2]
out_backprop_same = [1, 4, 3, 2]
out_backprop_in_sizes = {"VALID": out_backprop_valid, "SAME": out_backprop_same}
stride = [1, 2, 2, 1]


#TF graph
def tf_model(padding):
t1 = tf.placeholder(dtype=tf.float32, shape=input_sizes_nhwc, name='t1')
t2 = tf.constant(filter_size_hwio, dtype=tf.int32, name='t1')
t3 = tf.placeholder(
dtype=tf.float32, shape=out_backprop_in_sizes[padding], name='t3')

#Cast dtype to bfloat16 for TF because NNP casts ng_model inputs
t1 = tf.cast(t1, dtype=tf.bfloat16)
t3 = tf.cast(t3, dtype=tf.bfloat16)

filt = nn_ops.conv2d_backprop_filter(
t1, t2, t3, stride, padding=padding, data_format='NHWC')

#Cast dtype back to float32 similar to NNP
filt = tf.cast(filt, dtype=tf.float32)
return filt, t1, t3


#Ngraph Graph
def ng_model(padding):
t1 = tf.placeholder(dtype=tf.float32, shape=input_sizes_nhwc, name='t1')
t2 = tf.constant(filter_size_hwio, dtype=tf.int32, name='t1')
t3 = tf.placeholder(
dtype=tf.float32, shape=out_backprop_in_sizes[padding], name='t3')

filt = nn_ops.conv2d_backprop_filter(
t1, t2, t3, stride, padding=padding, data_format='NHWC')
return filt, t1, t3


config = tf.ConfigProto(
allow_soft_placement=True,
log_device_placement=False,
inter_op_parallelism_threads=1)


@pytest.mark.parametrize("padding", ("VALID", "SAME"))
def test_conv2dbackpropfilter_nhwc(padding):
np_inp = np.random.rand(*input_sizes_nhwc).astype('f')
np_out = np.random.rand(*out_backprop_in_sizes[padding]).astype('f')

with tf.Session(config=config) as sess_tf:
ngraph_bridge.disable()
tf_out, input_data, out_backprop = tf_model(padding)
feed_dict = {input_data: np_inp, out_backprop: np_out}
tf_outval = sess_tf.run(tf_out, feed_dict=feed_dict)

#Test 2: model2 with ngraph, NNP backend
with tf.Session(config=config) as sess_ng:
ngraph_bridge.enable()
ngraph_bridge.update_config(config)
os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1'
ng_out, input_data, out_backprop = ng_model(padding)
feed_dict = {input_data: np_inp, out_backprop: np_out}
ng_outval = sess_ng.run(ng_out, feed_dict=feed_dict)

assert np.allclose(tf_outval, ng_outval, rtol=0, atol=1e-02)
Loading