1# Description: 2# Utilities that perform useful transformations on graphs 3 4load( 5 "//tensorflow:tensorflow.bzl", 6 "if_not_windows", 7 "tf_cc_binary", 8 "tf_cc_test", 9 "tf_copts", 10 "tf_py_test", 11) 12load("//tensorflow:tensorflow.bzl", "get_compatible_with_cloud") 13 14package( 15 default_visibility = ["//visibility:public"], 16 licenses = ["notice"], 17) 18 19cc_library( 20 name = "transform_utils", 21 srcs = [ 22 "transform_utils.cc", 23 ], 24 hdrs = [ 25 "transform_utils.h", 26 ], 27 compatible_with = get_compatible_with_cloud(), 28 copts = tf_copts(), 29 visibility = ["//visibility:public"], 30 deps = [ 31 "//tensorflow/core:framework", 32 "//tensorflow/core:framework_internal", 33 "//tensorflow/core:lib", 34 "//tensorflow/core:lib_internal", 35 "//tensorflow/core:protos_all_cc", 36 ], 37) 38 39tf_cc_test( 40 name = "transform_utils_test", 41 size = "small", 42 srcs = ["transform_utils_test.cc"], 43 deps = [ 44 ":transform_utils", 45 "//tensorflow/cc:cc_ops", 46 "//tensorflow/core:core_cpu_base", 47 "//tensorflow/core:framework", 48 "//tensorflow/core:framework_internal", 49 "//tensorflow/core:lib", 50 "//tensorflow/core:protos_all_cc", 51 "//tensorflow/core:tensorflow", 52 "//tensorflow/core:test", 53 "//tensorflow/core:test_main", 54 "//tensorflow/core:testlib", 55 ], 56) 57 58cc_library( 59 name = "file_utils", 60 srcs = [ 61 "file_utils.cc", 62 ], 63 hdrs = [ 64 "file_utils.h", 65 ], 66 copts = tf_copts(), 67 visibility = ["//visibility:public"], 68 deps = [ 69 "//tensorflow/core:lib", 70 "//tensorflow/core:protos_all_cc", 71 ], 72) 73 74tf_cc_test( 75 name = "file_utils_test", 76 size = "small", 77 srcs = ["file_utils_test.cc"], 78 deps = [ 79 ":file_utils", 80 "//tensorflow/cc:cc_ops", 81 "//tensorflow/core:core_cpu", 82 "//tensorflow/core:framework_internal", 83 "//tensorflow/core:lib", 84 "//tensorflow/core:test", 85 "//tensorflow/core:test_main", 86 "//tensorflow/core:testlib", 87 ], 88) 89 90cc_library( 91 name = "transforms_lib", 92 srcs = [ 93 "add_default_attributes.cc", 94 "backports.cc", 95 "flatten_atrous.cc", 96 "fold_batch_norms.cc", 97 "fold_constants_lib.cc", 98 "fold_old_batch_norms.cc", 99 "freeze_requantization_ranges.cc", 100 "fuse_convolutions.cc", 101 "inline_partitionedcall.cc", 102 "insert_logging.cc", 103 "obfuscate_names.cc", 104 "quantize_nodes.cc", 105 "quantize_weights.cc", 106 "remove_attribute.cc", 107 "remove_control_dependencies.cc", 108 "remove_device.cc", 109 "remove_nodes.cc", 110 "rename_attribute.cc", 111 "rename_node.cc", 112 "rename_op.cc", 113 "round_weights.cc", 114 "set_device.cc", 115 "sort_by_execution_order.cc", 116 "sparsify_gather.cc", 117 "strip_unused_nodes.cc", 118 ], 119 hdrs = [ 120 "fold_constants_lib.h", 121 ], 122 copts = tf_copts(), 123 visibility = ["//visibility:public"], 124 deps = [ 125 ":transform_utils", 126 "@com_google_absl//absl/container:flat_hash_map", 127 "@com_google_absl//absl/strings", 128 "@com_google_absl//absl/algorithm:container", 129 "//tensorflow/c:checkpoint_reader", 130 "//tensorflow/core/util/tensor_bundle", 131 "//tensorflow/core:core_cpu", 132 "//tensorflow/core:core_cpu_internal", 133 "//tensorflow/core:framework", 134 "//tensorflow/core:framework_internal", 135 "//tensorflow/core:graph", 136 "//tensorflow/core:lib", 137 "//tensorflow/core:protos_all_cc", 138 "//tensorflow/core:tensorflow", 139 "//tensorflow/core/kernels:quantization_utils", 140 ] + if_not_windows([ 141 "//tensorflow/core:sparse_ops_op_lib", 142 "//tensorflow/core:parsing_ops_op_lib", 143 "//tensorflow/core:sendrecv_ops_op_lib", 144 "//tensorflow/core:io_ops_op_lib", 145 "//tensorflow/core:logging_ops_op_lib", 146 "//tensorflow/core:lookup_ops_op_lib", 147 "//tensorflow/core:data_flow_ops_op_lib", 148 "//tensorflow/core:no_op_op_lib", 149 "//tensorflow/core:state_ops_op_lib", 150 "//tensorflow/core:user_ops_op_lib", 151 "//tensorflow/core:training_ops_op_lib", 152 "//tensorflow/core:string_ops_op_lib", 153 "//tensorflow/core:random_ops_op_lib", 154 "//tensorflow/core:rnn_ops_op_lib", 155 "//tensorflow/core:nn_ops_op_lib", 156 "//tensorflow/core:math_ops_op_lib", 157 "//tensorflow/core:manip_ops_op_lib", 158 "//tensorflow/core:list_ops_op_lib", 159 "//tensorflow/core:functional_ops_op_lib", 160 "//tensorflow/core:control_flow_ops_op_lib", 161 "//tensorflow/core:candidate_sampling_ops_op_lib", 162 "//tensorflow/core:array_ops_op_lib", 163 ]), 164 alwayslink = 1, 165) 166 167tf_cc_test( 168 name = "transforms_test", 169 size = "small", 170 srcs = [ 171 "add_default_attributes_test.cc", 172 "backports_test.cc", 173 "flatten_atrous_test.cc", 174 "fold_batch_norms_test.cc", 175 "fold_constants_test.cc", 176 "fold_old_batch_norms_test.cc", 177 "freeze_requantization_ranges_test.cc", 178 "fuse_convolutions_test.cc", 179 "inline_partitionedcall_test.cc", 180 "insert_logging_test.cc", 181 "obfuscate_names_test.cc", 182 "quantize_nodes_test.cc", 183 "quantize_weights_test.cc", 184 "remove_attribute_test.cc", 185 "remove_device_test.cc", 186 "remove_nodes_test.cc", 187 "rename_attribute_test.cc", 188 "rename_node_test.cc", 189 "rename_op_test.cc", 190 "round_weights_test.cc", 191 "set_device_test.cc", 192 "sort_by_execution_order_test.cc", 193 "sparsify_gather_test.cc", 194 "strip_unused_nodes_test.cc", 195 ], 196 deps = [ 197 ":transform_utils", 198 ":transforms_lib", 199 "//tensorflow/cc:cc_ops", 200 "//tensorflow/cc:sendrecv_ops", 201 "//tensorflow/core:bitwise_ops_op_lib", 202 "//tensorflow/core:core_cpu", 203 "//tensorflow/core:lib", 204 "//tensorflow/core:protos_all_cc", 205 "//tensorflow/core:test", 206 "//tensorflow/core:test_main", 207 "//tensorflow/core:testlib", 208 "//tensorflow/core/kernels:quantization_utils", 209 "//tensorflow/core/kernels:quantized_ops", 210 "//tensorflow/core/util/tensor_bundle", 211 ], 212) 213 214filegroup( 215 name = "transform_graph_hdrs", 216 srcs = [ 217 "transform_graph.h", 218 "transform_utils.h", 219 ], 220 visibility = [ 221 "//tensorflow/core:__pkg__", 222 "//tensorflow/python:__pkg__", 223 "//tensorflow/python/util:__pkg__", 224 ], 225) 226 227cc_library( 228 name = "transform_graph_lib", 229 srcs = ["transform_graph.cc"], 230 hdrs = ["transform_graph.h"], 231 copts = tf_copts(), 232 visibility = ["//visibility:public"], 233 deps = [ 234 ":file_utils", 235 ":transform_utils", 236 ":transforms_lib", 237 "//tensorflow/core:framework_internal", 238 "//tensorflow/core:lib", 239 "//tensorflow/core:lib_internal", 240 "//tensorflow/core:protos_all_cc", 241 ], 242 alwayslink = 1, 243) 244 245# This library includes a main function, to make it easy to create other 246# versions of the tool linked against different operator libs. 247cc_library( 248 name = "transform_graph_main_lib", 249 srcs = ["transform_graph_main.cc"], 250 copts = tf_copts(), 251 visibility = ["//visibility:public"], 252 deps = [ 253 ":transform_graph_lib", 254 ":transforms_lib", 255 "//tensorflow/core:framework_internal", 256 "//tensorflow/core:lib", 257 ], 258) 259 260tf_cc_binary( 261 name = "transform_graph", 262 copts = tf_copts(), 263 linkstatic = 1, 264 visibility = ["//visibility:public"], 265 deps = [ 266 ":transform_graph_main_lib", 267 ], 268) 269 270tf_cc_test( 271 name = "transform_graph_test", 272 size = "medium", 273 srcs = ["transform_graph_test.cc"], 274 deps = [ 275 ":transform_graph_lib", 276 ":transform_utils", 277 "//tensorflow/cc:cc_ops", 278 "//tensorflow/cc:sendrecv_ops", 279 "//tensorflow/core:core_cpu", 280 "//tensorflow/core:framework", 281 "//tensorflow/core:lib", 282 "//tensorflow/core:protos_all_cc", 283 "//tensorflow/core:test", 284 "//tensorflow/core:test_main", 285 "//tensorflow/core:testlib", 286 ], 287) 288 289# This library includes a main function, to make it easy to create other 290# versions of the tool linked against different operator libs. 291cc_library( 292 name = "summarize_graph_main_lib", 293 srcs = ["summarize_graph_main.cc"], 294 copts = tf_copts(), 295 visibility = ["//visibility:public"], 296 deps = [ 297 ":file_utils", 298 ":transform_utils", 299 "//tensorflow/core:framework", 300 "//tensorflow/core:framework_internal", 301 "//tensorflow/core:lib", 302 "//tensorflow/core:protos_all_cc", 303 ], 304) 305 306tf_cc_binary( 307 name = "summarize_graph", 308 copts = tf_copts(), 309 linkstatic = 1, 310 visibility = ["//visibility:public"], 311 deps = [ 312 ":summarize_graph_main_lib", 313 ], 314) 315 316tf_cc_binary( 317 name = "compare_graphs", 318 srcs = ["compare_graphs.cc"], 319 copts = tf_copts(), 320 linkstatic = 1, 321 visibility = ["//visibility:public"], 322 deps = [ 323 ":file_utils", 324 ":transform_utils", 325 "//tensorflow/core:core_cpu_internal", 326 "//tensorflow/core:framework_internal", 327 "//tensorflow/core:lib", 328 ], 329) 330 331py_library( 332 name = "transform_graph_py", 333 srcs = ["__init__.py"], 334 srcs_version = "PY3", 335 deps = [ 336 "//tensorflow/core:protos_all_py", 337 "//tensorflow/python:errors", 338 "//tensorflow/python:util", 339 "//tensorflow/python/util:_pywrap_transform_graph", 340 ], 341) 342 343tf_py_test( 344 name = "transform_graph_py_test", 345 size = "small", 346 srcs = ["python/transform_graph_test.py"], 347 main = "python/transform_graph_test.py", 348 tags = ["v1only"], 349 deps = [ 350 ":transform_graph_py", 351 "//tensorflow/core:protos_all_py", 352 "//tensorflow/python:client_testlib", 353 "//tensorflow/python:framework_for_generated_wrappers", 354 "//tensorflow/python:math_ops", 355 "//tensorflow/python:variables", 356 ], 357) 358