-
Notifications
You must be signed in to change notification settings - Fork 62
Shrestha/upgrade r17 to master #189
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
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9fd8350
Made changes to NGraphAssignOp
8e5a8ea
Added utilities to remove the enteries from the catalog maps. Removed…
1685709
Remove entries from Catalog in NGVariable Destructors.
8c3dd80
Modifications to catalog. Compiles
6b7e296
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
6c2dd52
Code Format
b2f0f02
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
bc9b16a
Not using RemoveEdge Api. Made changes to RewritePass
a2f1336
changes to get var before compute
6f75433
Made changes to remove edges right way.Added syncing in encap
aeb8514
Removed Enacap Output Tensor Map
9059154
Updated Comments
48bf3fe
Updated Comments
5b40ff9
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
4b1a475
Integrate with output cache
6e49e07
Update ngraph_bridge/enable_variable_ops/ngraph_enter_in_catalog.h
c80ade7
Minor
9beda76
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
d4b647c
minor
19d1839
Formatted for formatting
b44cee0
Update ngraph_bridge/ngraph_encapsulate_op.cc
702c2ae
Merge branch 'master' into shrestha/Integrate_RemoveNGAssign
sayantan-nervana 3fa1df0
Kanvi/remove additional attr check (#150)
kanvi-nervana ca9f62b
Merge remote-tracking branch 'origin/master' into shrestha/Integrate_…
b4ed01a
Merge branch 'shrestha/Integrate_RemoveNGAssign' of https://github.co…
b8944f7
Merge pull request #152 from tensorflow/shrestha/Integrate_RemoveNGAs…
65348d7
sarkars/destructor order (#146)
sayantan-nervana 652cca8
Update bridge version number
sayantan-nervana a10636b
sarkars/Possible fix for backend settings (#159)
sayantan-nervana 2454cc5
Sarkars/update tf2ngraph to use rewriterconfig (#149)
sayantan-nervana 20a6394
Upgrade to 0.17.0rc1 (#163)
sayantan-nervana 5a040c7
Upgrade nGraph Core to 0.24.0-rc.2 (#166)
0b64823
Avijit/bazel cleanup (#140)
avijit-nervana 951ca46
Shrestha/Fix --num_inter_threads (#175)
f0e85ae
sarkars/Upgrade to ngcore24 (#180)
sayantan-nervana fd1d713
Sindhu/pad op python test (#187)
sindhu-nervana 12aa7e9
Sindhu/bfloat16 op tests (#183)
sindhu-nervana 01a5698
Merge remote-tracking branch 'origin/master' into shrestha/upgrade_r1…
a68e5b4
Fixed version issue
478c89e
Kanvi/bfloat16 tests (#185)
kanvi-nervana ae0d9c4
Merge remote-tracking branch 'origin/master' into shrestha/upgrade_r1…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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