Skip to content

Commit 41734d7

Browse files
Automated rollback of change 137740850
Change: 137747341
1 parent 1dd44f3 commit 41734d7

28 files changed

+714
-162
lines changed

tensorflow/contrib/cmake/tf_python.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,38 @@ function(RELATIVE_PROTOBUF_GENERATE_PYTHON ROOT_DIR SRCS)
9494
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
9595
endfunction()
9696

97+
function(RELATIVE_PROTOBUF_GENERATE_CPP SRCS HDRS ROOT_DIR)
98+
if(NOT ARGN)
99+
message(SEND_ERROR "Error: RELATIVE_PROTOBUF_GENERATE_CPP() called without any proto files")
100+
return()
101+
endif()
102+
103+
set(${SRCS})
104+
set(${HDRS})
105+
foreach(FIL ${ARGN})
106+
set(ABS_FIL ${ROOT_DIR}/${FIL})
107+
get_filename_component(FIL_WE ${FIL} NAME_WE)
108+
get_filename_component(FIL_DIR ${ABS_FIL} PATH)
109+
file(RELATIVE_PATH REL_DIR ${ROOT_DIR} ${FIL_DIR})
110+
111+
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${REL_DIR}/${FIL_WE}.pb.cc")
112+
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${REL_DIR}/${FIL_WE}.pb.h")
113+
114+
add_custom_command(
115+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${REL_DIR}/${FIL_WE}.pb.cc"
116+
"${CMAKE_CURRENT_BINARY_DIR}/${REL_DIR}/${FIL_WE}.pb.h"
117+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
118+
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${ROOT_DIR} ${ABS_FIL} -I ${PROTOBUF_INCLUDE_DIRS}
119+
DEPENDS ${ABS_FIL} protobuf
120+
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
121+
VERBATIM )
122+
endforeach()
123+
124+
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
125+
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
126+
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
127+
endfunction()
128+
97129
file(GLOB_RECURSE tf_protos_python_srcs RELATIVE ${tensorflow_source_dir}
98130
"${tensorflow_source_dir}/tensorflow/core/*.proto"
99131
"${tensorflow_source_dir}/tensorflow/python/*.proto"
@@ -102,6 +134,12 @@ RELATIVE_PROTOBUF_GENERATE_PYTHON(
102134
${tensorflow_source_dir} PYTHON_PROTO_GENFILES ${tf_protos_python_srcs}
103135
)
104136

137+
RELATIVE_PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS
138+
${tensorflow_source_dir} ${tf_protos_python_srcs}
139+
)
140+
141+
add_library(tf_python_protos_cc ${PROTO_SRCS} ${PROTO_HDRS})
142+
105143
# tf_python_touchup_modules adds empty __init__.py files to all
106144
# directories containing Python code, so that Python will recognize
107145
# them as modules.
@@ -201,6 +239,7 @@ function(GENERATE_PYTHON_OP_LIB tf_python_op_lib_name)
201239
)
202240
target_link_libraries(${tf_python_op_lib_name}_gen_python PRIVATE
203241
tf_protos_cc
242+
tf_python_protos_cc
204243
${tensorflow_EXTERNAL_LIBRARIES}
205244
)
206245

@@ -312,6 +351,7 @@ target_link_libraries(pywrap_tensorflow
312351
${tf_core_gpu_kernels_lib}
313352
${tensorflow_EXTERNAL_LIBRARIES}
314353
tf_protos_cc
354+
tf_python_protos_cc
315355
${PYTHON_LIBRARIES}
316356
)
317357

tensorflow/core/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ tf_gen_op_libs(
379379
"no_op",
380380
"parsing_ops",
381381
"random_ops",
382+
"resource_variable_ops",
382383
"sdca_ops",
383384
"script_ops",
384385
"sendrecv_ops",
@@ -542,6 +543,7 @@ cc_library(
542543
"//tensorflow/core/kernels:parsing",
543544
"//tensorflow/core/kernels:random_ops",
544545
"//tensorflow/core/kernels:required",
546+
"//tensorflow/core/kernels:resource_variable_ops",
545547
"//tensorflow/core/kernels:sdca_ops",
546548
"//tensorflow/core/kernels:sparse",
547549
"//tensorflow/core/kernels:state",

tensorflow/core/common_runtime/shape_refiner.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Status ShapeRefiner::AddNode(const Node* node) {
4242
// indexed by 'node's input.
4343
std::vector<Node*> input_nodes(node->num_inputs());
4444
std::vector<ShapeHandle> input_shapes(node->num_inputs());
45+
std::vector<DataType> input_handle_dtypes(node->num_inputs());
46+
std::vector<ShapeHandle> input_handle_shapes(node->num_inputs());
4547
for (const Edge* e : node->in_edges()) {
4648
if (e->IsControlEdge()) continue;
4749

@@ -57,6 +59,15 @@ Status ShapeRefiner::AddNode(const Node* node) {
5759
DCHECK_GE(e->dst_input(), 0);
5860
input_nodes[e->dst_input()] = input;
5961
input_shapes[e->dst_input()] = c->output(e->src_output());
62+
63+
// Only propagate handle xshape and dtype of edges which are carrying
64+
// resource handles.
65+
if (e->src()->output_type(e->src_output()) == DT_RESOURCE) {
66+
input_handle_dtypes[e->dst_input()] =
67+
c->output_handle_dtype(e->src_output());
68+
input_handle_shapes[e->dst_input()] =
69+
c->output_handle_shape(e->src_output());
70+
}
6071
}
6172

6273
// Get the shape function for this node
@@ -76,9 +87,9 @@ Status ShapeRefiner::AddNode(const Node* node) {
7687
std::vector<ShapeHandle> input_tensors_as_shapes;
7788

7889
// Create the inference context for this node with the existing input shapes.
79-
std::unique_ptr<InferenceContext> c(
80-
new InferenceContext(&node->def(), node->op_def(), input_shapes,
81-
input_tensors, input_tensors_as_shapes));
90+
std::unique_ptr<InferenceContext> c(new InferenceContext(
91+
&node->def(), node->op_def(), input_shapes, input_tensors,
92+
input_tensors_as_shapes, input_handle_shapes, input_handle_dtypes));
8293
if (!c->construction_status().ok()) {
8394
return c->construction_status();
8495
}

tensorflow/core/framework/common_shape_fns_test.cc

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TEST(CommonShapeFnsTest, NoOutputShapeTest) {
5656
.Input({{"data", 0, DT_FLOAT}})
5757
.Finalize(&def));
5858

59-
InferenceContext c(&def, op_def, {S({}), S({10})}, {}, {});
59+
InferenceContext c(&def, op_def, {S({}), S({10})}, {}, {}, {}, {});
6060
TF_EXPECT_OK(NoOutputs(&c));
6161
EXPECT_EQ(0, c.num_outputs());
6262
}
@@ -74,14 +74,14 @@ TEST(CommonShapeFnsTest, ScalarShapeTest) {
7474
NodeDefBuilder("test", "L2Loss").Input("t", 0, DT_FLOAT).Finalize(&def));
7575

7676
{
77-
InferenceContext c(&def, op_def, {S({})}, {}, {});
77+
InferenceContext c(&def, op_def, {S({})}, {}, {}, {}, {});
7878
TF_EXPECT_OK(ScalarShape(&c));
7979
ShapeHandle output = c.output(0);
8080
EXPECT_EQ(0, c.Rank(output));
8181
}
8282

8383
{
84-
InferenceContext c(&def, op_def, {S({1, 23, 4, 4, 2})}, {}, {});
84+
InferenceContext c(&def, op_def, {S({1, 23, 4, 4, 2})}, {}, {}, {}, {});
8585
TF_EXPECT_OK(ScalarShape(&c));
8686
ShapeHandle output = c.output(0);
8787
EXPECT_EQ(0, c.Rank(output));
@@ -108,7 +108,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
108108
.Finalize(&def));
109109

110110
{
111-
InferenceContext c(&def, op_def, {S({2, 3}), S({3, 4})}, {}, {});
111+
InferenceContext c(&def, op_def, {S({2, 3}), S({3, 4})}, {}, {}, {}, {});
112112
TF_EXPECT_OK(MatMulShape(&c));
113113
ShapeHandle output = c.output(0);
114114
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -117,7 +117,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
117117

118118
{
119119
// Unknown inner dimension for one
120-
InferenceContext c(&def, op_def, {S({2, -1}), S({3, 4})}, {}, {});
120+
InferenceContext c(&def, op_def, {S({2, -1}), S({3, 4})}, {}, {}, {}, {});
121121
TF_EXPECT_OK(MatMulShape(&c));
122122
ShapeHandle output = c.output(0);
123123
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -126,7 +126,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
126126

127127
{
128128
// Invalid rank.
129-
InferenceContext c(&def, op_def, {S({2}), S({3, 4})}, {}, {});
129+
InferenceContext c(&def, op_def, {S({2}), S({3, 4})}, {}, {}, {}, {});
130130
auto s = MatMulShape(&c);
131131
EXPECT_FALSE(s.ok());
132132
EXPECT_TRUE(
@@ -136,7 +136,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
136136

137137
{
138138
// Unknown outer dimension
139-
InferenceContext c(&def, op_def, {S({2, 3}), S({3, -1})}, {}, {});
139+
InferenceContext c(&def, op_def, {S({2, 3}), S({3, -1})}, {}, {}, {}, {});
140140
TF_EXPECT_OK(MatMulShape(&c));
141141
ShapeHandle output = c.output(0);
142142
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -145,7 +145,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
145145

146146
{
147147
// Inner shapes not compatible
148-
InferenceContext c(&def, op_def, {S({2, 5}), S({3, 4})}, {}, {});
148+
InferenceContext c(&def, op_def, {S({2, 5}), S({3, 4})}, {}, {}, {}, {});
149149
auto s = MatMulShape(&c);
150150
EXPECT_FALSE(s.ok());
151151
EXPECT_TRUE(
@@ -156,7 +156,8 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
156156

157157
{
158158
// Inner shapes not compatible
159-
InferenceContext c(&def, op_def, {S({2, 5, 3}), S({3, 5, 4})}, {}, {});
159+
InferenceContext c(&def, op_def, {S({2, 5, 3}), S({3, 5, 4})}, {}, {}, {},
160+
{});
160161
auto s = MatMulShape(&c);
161162
EXPECT_FALSE(s.ok());
162163
EXPECT_TRUE(
@@ -174,7 +175,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
174175
.Attr("type", DT_FLOAT)
175176
.Finalize(&def));
176177

177-
InferenceContext c(&def, op_def, {S({3, 2}), S({3, 4})}, {}, {});
178+
InferenceContext c(&def, op_def, {S({3, 2}), S({3, 4})}, {}, {}, {}, {});
178179
auto s = MatMulShape(&c);
179180
ShapeHandle output = c.output(0);
180181
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -191,7 +192,7 @@ TEST(CommonShapeFnsTest, MatMulShapeTest) {
191192
.Attr("type", DT_FLOAT)
192193
.Finalize(&def));
193194

194-
InferenceContext c(&def, op_def, {S({2, 3}), S({4, 3})}, {}, {});
195+
InferenceContext c(&def, op_def, {S({2, 3}), S({4, 3})}, {}, {}, {}, {});
195196
auto s = MatMulShape(&c);
196197
ShapeHandle output = c.output(0);
197198
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -215,7 +216,7 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
215216
.Finalize(&def));
216217

217218
{
218-
InferenceContext c(&def, op_def, {S({2, 10}), S({10})}, {}, {});
219+
InferenceContext c(&def, op_def, {S({2, 10}), S({10})}, {}, {}, {}, {});
219220
TF_EXPECT_OK(BiasAddShape(&c));
220221
ShapeHandle output = c.output(0);
221222
EXPECT_EQ(2, c.Value(c.Dim(output, 0)));
@@ -224,15 +225,16 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
224225

225226
{
226227
// Unknown ranks.
227-
InferenceContext c(&def, op_def, {Unknown(), Unknown()}, {}, {});
228+
InferenceContext c(&def, op_def, {Unknown(), Unknown()}, {}, {}, {}, {});
228229
TF_EXPECT_OK(BiasAddShape(&c));
229230
ShapeHandle output = c.output(0);
230231
EXPECT_FALSE(c.RankKnown(output));
231232
}
232233

233234
{
234235
// Rank > 2
235-
InferenceContext c(&def, op_def, {S({4, 3, 4, 2, 15}), S({15})}, {}, {});
236+
InferenceContext c(&def, op_def, {S({4, 3, 4, 2, 15}), S({15})}, {}, {}, {},
237+
{});
236238
TF_EXPECT_OK(BiasAddShape(&c));
237239
ShapeHandle output = c.output(0);
238240
EXPECT_EQ("[4,3,4,2,15]", c.DebugString(output));
@@ -245,7 +247,7 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
245247
.Input("b", 0, DT_FLOAT)
246248
.Attr("data_format", "NCHW")
247249
.Finalize(&def));
248-
InferenceContext c(&def, op_def, {S({2, 3, 4, 5}), S({3})}, {}, {});
250+
InferenceContext c(&def, op_def, {S({2, 3, 4, 5}), S({3})}, {}, {}, {}, {});
249251
TF_EXPECT_OK(BiasAddShape(&c));
250252
ShapeHandle output = c.output(0);
251253
EXPECT_EQ("[2,3,4,5]", c.DebugString(output));
@@ -258,8 +260,8 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
258260
.Input("b", 0, DT_FLOAT)
259261
.Attr("data_format", "NCHW")
260262
.Finalize(&def));
261-
InferenceContext c(&def, op_def, {S({8, 6, 4, 2, 3, 4, 5}), S({3})}, {},
262-
{});
263+
InferenceContext c(&def, op_def, {S({8, 6, 4, 2, 3, 4, 5}), S({3})}, {}, {},
264+
{}, {});
263265
TF_EXPECT_OK(BiasAddShape(&c));
264266
ShapeHandle output = c.output(0);
265267
EXPECT_EQ("[8,6,4,2,3,4,5]", c.DebugString(output));
@@ -272,15 +274,16 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
272274
.Input("b", 0, DT_FLOAT)
273275
.Attr("data_format", "NCHW")
274276
.Finalize(&def));
275-
InferenceContext c(&def, op_def, {S({10, 11, 12}), S({10})}, {}, {});
277+
InferenceContext c(&def, op_def, {S({10, 11, 12}), S({10})}, {}, {}, {},
278+
{});
276279
TF_EXPECT_OK(BiasAddShape(&c));
277280
ShapeHandle output = c.output(0);
278281
EXPECT_EQ("[10,11,12]", c.DebugString(output));
279282
}
280283

281284
{
282285
// Input rank not high enough
283-
InferenceContext c(&def, op_def, {S({3}), S({3})}, {}, {});
286+
InferenceContext c(&def, op_def, {S({3}), S({3})}, {}, {}, {}, {});
284287
EXPECT_FALSE(BiasAddShape(&c).ok());
285288
}
286289

@@ -292,7 +295,7 @@ TEST(CommonShapeFnsTest, BiasAddShapeTest) {
292295
.Attr("data_format", "NCHW")
293296
.Finalize(&def));
294297
// NCHW format
295-
InferenceContext c(&def, op_def, {S({2, 3}), S({3})}, {}, {});
298+
InferenceContext c(&def, op_def, {S({2, 3}), S({3})}, {}, {}, {}, {});
296299
EXPECT_FALSE(BiasAddShape(&c).ok());
297300
}
298301
}
@@ -311,15 +314,15 @@ TEST(CommonShapeFnsTest, BiasAddGradShapeTest) {
311314
.Finalize(&def));
312315

313316
{
314-
InferenceContext c(&def, op_def, {S({2, 10})}, {}, {});
317+
InferenceContext c(&def, op_def, {S({2, 10})}, {}, {}, {}, {});
315318
TF_EXPECT_OK(BiasAddGradShape(&c));
316319
ShapeHandle output = c.output(0);
317320
EXPECT_EQ(10, c.Value(c.Dim(output, 0)));
318321
}
319322

320323
{
321324
// Rank > 2
322-
InferenceContext c(&def, op_def, {S({5, 7, 2, 10})}, {}, {});
325+
InferenceContext c(&def, op_def, {S({5, 7, 2, 10})}, {}, {}, {}, {});
323326
TF_EXPECT_OK(BiasAddGradShape(&c));
324327
ShapeHandle output = c.output(0);
325328
EXPECT_EQ(10, c.Value(c.Dim(output, 0)));
@@ -331,7 +334,7 @@ TEST(CommonShapeFnsTest, BiasAddGradShapeTest) {
331334
.Input("a", 0, DT_FLOAT)
332335
.Attr("data_format", "NCHW")
333336
.Finalize(&def));
334-
InferenceContext c(&def, op_def, {S({2, 3, 4, 5})}, {}, {});
337+
InferenceContext c(&def, op_def, {S({2, 3, 4, 5})}, {}, {}, {}, {});
335338
TF_EXPECT_OK(BiasAddGradShape(&c));
336339
ShapeHandle output = c.output(0);
337340
EXPECT_EQ(3, c.Value(c.Dim(output, 0)));
@@ -343,7 +346,8 @@ TEST(CommonShapeFnsTest, BiasAddGradShapeTest) {
343346
.Input("a", 0, DT_FLOAT)
344347
.Attr("data_format", "NCHW")
345348
.Finalize(&def));
346-
InferenceContext c(&def, op_def, {S({8, 6, 4, 2, 3, 4, 5})}, {}, {});
349+
InferenceContext c(&def, op_def, {S({8, 6, 4, 2, 3, 4, 5})}, {}, {}, {},
350+
{});
347351
TF_EXPECT_OK(BiasAddGradShape(&c));
348352
ShapeHandle output = c.output(0);
349353
EXPECT_EQ(3, c.Value(c.Dim(output, 0)));
@@ -355,15 +359,15 @@ TEST(CommonShapeFnsTest, BiasAddGradShapeTest) {
355359
.Input("a", 0, DT_FLOAT)
356360
.Attr("data_format", "NCHW")
357361
.Finalize(&def));
358-
InferenceContext c(&def, op_def, {S({10, 11, 12})}, {}, {});
362+
InferenceContext c(&def, op_def, {S({10, 11, 12})}, {}, {}, {}, {});
359363
TF_EXPECT_OK(BiasAddGradShape(&c));
360364
ShapeHandle output = c.output(0);
361365
EXPECT_EQ(10, c.Value(c.Dim(output, 0)));
362366
}
363367

364368
{
365369
// Input rank not high enough
366-
InferenceContext c(&def, op_def, {S({3})}, {}, {});
370+
InferenceContext c(&def, op_def, {S({3})}, {}, {}, {}, {});
367371
EXPECT_FALSE(BiasAddGradShape(&c).ok());
368372
}
369373

@@ -374,7 +378,7 @@ TEST(CommonShapeFnsTest, BiasAddGradShapeTest) {
374378
.Attr("data_format", "NCHW")
375379
.Finalize(&def));
376380
// NCHW format
377-
InferenceContext c(&def, op_def, {S({2, 3})}, {}, {});
381+
InferenceContext c(&def, op_def, {S({2, 3})}, {}, {}, {}, {});
378382
EXPECT_FALSE(BiasAddGradShape(&c).ok());
379383
}
380384
}

tensorflow/core/framework/node_def_util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ void AddNodeAttr(StringPiece name, std::initializer_list<T> value,
6666
AttrValueMap::value_type(name.ToString(), attr_value));
6767
}
6868

69+
// Adds an attr to an attr value map.
70+
template <class T>
71+
void AddAttr(StringPiece name, T&& value, AttrValueMap* map) {
72+
AttrValue attr_value;
73+
SetAttrValue(value, &attr_value);
74+
map->insert(AttrValueMap::value_type(name.ToString(), attr_value));
75+
}
76+
6977
class AttrSlice {
7078
public:
7179
AttrSlice(const NodeDef& node_def); // NOLINT(runtime/explicit)

tensorflow/core/framework/resource_mgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ limitations under the License.
2121
#include <typeinfo>
2222
#include <unordered_map>
2323

24+
#include "tensorflow/core/framework/common_shape_fns.h"
2425
#include "tensorflow/core/framework/graph.pb.h"
2526
#include "tensorflow/core/framework/op_kernel.h"
2627
#include "tensorflow/core/framework/tensor.h"

0 commit comments

Comments
 (0)