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"], # Apache 2.0 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/kernels:remote_fused_graph_rewriter_transform", 142 "//tensorflow/core/kernels/hexagon:hexagon_rewriter_transform", 143 "//tensorflow/core:sparse_ops_op_lib", 144 "//tensorflow/core:parsing_ops_op_lib", 145 "//tensorflow/core:sendrecv_ops_op_lib", 146 "//tensorflow/core:io_ops_op_lib", 147 "//tensorflow/core:logging_ops_op_lib", 148 "//tensorflow/core:lookup_ops_op_lib", 149 "//tensorflow/core:data_flow_ops_op_lib", 150 "//tensorflow/core:no_op_op_lib", 151 "//tensorflow/core:state_ops_op_lib", 152 "//tensorflow/core:user_ops_op_lib", 153 "//tensorflow/core:training_ops_op_lib", 154 "//tensorflow/core:string_ops_op_lib", 155 "//tensorflow/core:remote_fused_graph_ops_op_lib", 156 "//tensorflow/core:random_ops_op_lib", 157 "//tensorflow/core:rnn_ops_op_lib", 158 "//tensorflow/core:nn_ops_op_lib", 159 "//tensorflow/core:math_ops_op_lib", 160 "//tensorflow/core:manip_ops_op_lib", 161 "//tensorflow/core:list_ops_op_lib", 162 "//tensorflow/core:functional_ops_op_lib", 163 "//tensorflow/core:control_flow_ops_op_lib", 164 "//tensorflow/core:candidate_sampling_ops_op_lib", 165 "//tensorflow/core:array_ops_op_lib", 166 ]), 167 alwayslink = 1, 168) 169 170tf_cc_test( 171 name = "transforms_test", 172 size = "small", 173 srcs = [ 174 "add_default_attributes_test.cc", 175 "backports_test.cc", 176 "flatten_atrous_test.cc", 177 "fold_batch_norms_test.cc", 178 "fold_constants_test.cc", 179 "fold_old_batch_norms_test.cc", 180 "freeze_requantization_ranges_test.cc", 181 "fuse_convolutions_test.cc", 182 "inline_partitionedcall_test.cc", 183 "insert_logging_test.cc", 184 "obfuscate_names_test.cc", 185 "quantize_nodes_test.cc", 186 "quantize_weights_test.cc", 187 "remove_attribute_test.cc", 188 "remove_device_test.cc", 189 "remove_nodes_test.cc", 190 "rename_attribute_test.cc", 191 "rename_node_test.cc", 192 "rename_op_test.cc", 193 "round_weights_test.cc", 194 "set_device_test.cc", 195 "sort_by_execution_order_test.cc", 196 "sparsify_gather_test.cc", 197 "strip_unused_nodes_test.cc", 198 ], 199 deps = [ 200 ":transform_utils", 201 ":transforms_lib", 202 "//tensorflow/cc:cc_ops", 203 "//tensorflow/cc:sendrecv_ops", 204 "//tensorflow/core:bitwise_ops_op_lib", 205 "//tensorflow/core:core_cpu", 206 "//tensorflow/core:lib", 207 "//tensorflow/core:protos_all_cc", 208 "//tensorflow/core:test", 209 "//tensorflow/core:test_main", 210 "//tensorflow/core:testlib", 211 "//tensorflow/core/kernels:quantization_utils", 212 "//tensorflow/core/kernels:quantized_ops", 213 "//tensorflow/core/util/tensor_bundle", 214 ], 215) 216 217filegroup( 218 name = "transform_graph_hdrs", 219 srcs = [ 220 "transform_graph.h", 221 "transform_utils.h", 222 ], 223 visibility = [ 224 "//tensorflow/core:__pkg__", 225 "//tensorflow/python:__pkg__", 226 "//tensorflow/python/util:__pkg__", 227 ], 228) 229 230cc_library( 231 name = "transform_graph_lib", 232 srcs = ["transform_graph.cc"], 233 hdrs = ["transform_graph.h"], 234 copts = tf_copts(), 235 visibility = ["//visibility:public"], 236 deps = [ 237 ":file_utils", 238 ":transform_utils", 239 ":transforms_lib", 240 "//tensorflow/core:framework_internal", 241 "//tensorflow/core:lib", 242 "//tensorflow/core:lib_internal", 243 "//tensorflow/core:protos_all_cc", 244 ], 245 alwayslink = 1, 246) 247 248# This library includes a main function, to make it easy to create other 249# versions of the tool linked against different operator libs. 250cc_library( 251 name = "transform_graph_main_lib", 252 srcs = ["transform_graph_main.cc"], 253 copts = tf_copts(), 254 visibility = ["//visibility:public"], 255 deps = [ 256 ":transform_graph_lib", 257 ":transforms_lib", 258 "//tensorflow/core:framework_internal", 259 "//tensorflow/core:lib", 260 ], 261) 262 263tf_cc_binary( 264 name = "transform_graph", 265 copts = tf_copts(), 266 linkstatic = 1, 267 visibility = ["//visibility:public"], 268 deps = [ 269 ":transform_graph_main_lib", 270 ], 271) 272 273tf_cc_test( 274 name = "transform_graph_test", 275 size = "medium", 276 srcs = ["transform_graph_test.cc"], 277 deps = [ 278 ":transform_graph_lib", 279 ":transform_utils", 280 "//tensorflow/cc:cc_ops", 281 "//tensorflow/cc:sendrecv_ops", 282 "//tensorflow/core:core_cpu", 283 "//tensorflow/core:framework", 284 "//tensorflow/core:lib", 285 "//tensorflow/core:protos_all_cc", 286 "//tensorflow/core:test", 287 "//tensorflow/core:test_main", 288 "//tensorflow/core:testlib", 289 ], 290) 291 292# This library includes a main function, to make it easy to create other 293# versions of the tool linked against different operator libs. 294cc_library( 295 name = "summarize_graph_main_lib", 296 srcs = ["summarize_graph_main.cc"], 297 copts = tf_copts(), 298 visibility = ["//visibility:public"], 299 deps = [ 300 ":file_utils", 301 ":transform_utils", 302 "//tensorflow/core:framework", 303 "//tensorflow/core:framework_internal", 304 "//tensorflow/core:lib", 305 "//tensorflow/core:protos_all_cc", 306 ], 307) 308 309tf_cc_binary( 310 name = "summarize_graph", 311 copts = tf_copts(), 312 linkstatic = 1, 313 visibility = ["//visibility:public"], 314 deps = [ 315 ":summarize_graph_main_lib", 316 ], 317) 318 319tf_cc_binary( 320 name = "compare_graphs", 321 srcs = ["compare_graphs.cc"], 322 copts = tf_copts(), 323 linkstatic = 1, 324 visibility = ["//visibility:public"], 325 deps = [ 326 ":file_utils", 327 ":transform_utils", 328 "//tensorflow/core:core_cpu_internal", 329 "//tensorflow/core:framework_internal", 330 "//tensorflow/core:lib", 331 ], 332) 333 334py_library( 335 name = "transform_graph_py", 336 srcs = ["__init__.py"], 337 srcs_version = "PY3", 338 deps = [ 339 "//tensorflow/core:protos_all_py", 340 "//tensorflow/python:errors", 341 "//tensorflow/python:util", 342 "//tensorflow/python/util:_pywrap_transform_graph", 343 ], 344) 345 346tf_py_test( 347 name = "transform_graph_py_test", 348 size = "small", 349 srcs = ["python/transform_graph_test.py"], 350 main = "python/transform_graph_test.py", 351 tags = ["v1only"], 352 deps = [ 353 ":transform_graph_py", 354 "//tensorflow/core:protos_all_py", 355 "//tensorflow/python:client_testlib", 356 "//tensorflow/python:framework_for_generated_wrappers", 357 "//tensorflow/python:math_ops", 358 "//tensorflow/python:variables", 359 ], 360) 361