How to use debug method in Cypress

Best JavaScript code snippet using cypress

BUILD

Source:BUILD Github

copy

Full Screen

1# Description:2# Python Client Code of the TensorFlow Debugger (tfdbg).3#4# Public target(s):5#6# ":debug_py": Public Python methods and classes of tfdbg.7# For API documentation, see https://www.tensorflow.org/api_docs/python/tfdbg8# For a user interface walkthrough, see https://www.tensorflow.org/guide/debugger9# ":grpc_debug_server": Server interface for grpc:// debug URLs.10load("//tensorflow:tensorflow.bzl", "cuda_py_test")11load("//tensorflow:tensorflow.bzl", "if_not_v2", "if_not_windows", "py_binary", "py_test")12package(13 default_visibility = ["//tensorflow:internal"],14 licenses = ["notice"], # Apache 2.015)16exports_files(["LICENSE"])17py_library(18 name = "debug_py",19 srcs = ["__init__.py"],20 srcs_version = "PY2AND3",21 visibility = ["//visibility:public"],22 deps = [23 ":check_numerics_callback",24 ":debug_data",25 ":debug_events_monitors",26 ":debug_events_reader",27 ":debug_events_writer",28 ":debug_gradients",29 ":debug_graphs",30 ":debug_utils",31 ":dumping_callback",32 ":dumping_callback_test_lib",33 ":grpc_debug_server",34 ":grpc_debug_test_server",35 ":hooks",36 ":local_cli_wrapper",37 "//tensorflow/python:debug_ops_gen",38 "//tensorflow/python:util",39 ],40)41# Transitive dependencies of this target will be included in the pip package.42py_library(43 name = "debug_pip",44 data = [":grpc_tensorflow_server"],45 deps = [46 ":cli_test_utils",47 ":debug_py",48 ":grpc_debug_test_server",49 ":grpc_tensorflow_server_lib",50 ":offline_analyzer_lib",51 ":session_debug_testlib",52 ":source_remote",53 ] + if_not_windows([54 ":debug_examples_v1",55 ":debug_examples_v2",56 ]),57)58py_library(59 name = "op_callbacks_common",60 srcs = ["lib/op_callbacks_common.py"],61 srcs_version = "PY2AND3",62)63py_library(64 name = "check_numerics_callback",65 srcs = ["lib/check_numerics_callback.py"],66 srcs_version = "PY2AND3",67 deps = [68 ":op_callbacks_common",69 ":source_utils",70 "//tensorflow/python:array_ops",71 "//tensorflow/python:debug_ops_gen",72 "//tensorflow/python:op_callbacks",73 "//third_party/py/numpy",74 ],75)76py_library(77 name = "dumping_callback",78 srcs = ["lib/dumping_callback.py"],79 srcs_version = "PY2AND3",80 deps = [81 ":debug_events_writer",82 ":op_callbacks_common",83 ":source_utils",84 "//tensorflow/python:array_ops",85 "//tensorflow/python:debug_ops_gen",86 "//tensorflow/python:op_callbacks",87 "//third_party/py/numpy",88 ],89)90py_library(91 name = "dumping_callback_test_lib",92 srcs = ["lib/dumping_callback_test_lib.py"],93 srcs_version = "PY2AND3",94 deps = [95 ":check_numerics_callback",96 ":debug_events_reader",97 ":dumping_callback",98 "//third_party/py/numpy",99 ],100)101py_library(102 name = "common",103 srcs = ["lib/common.py"],104 srcs_version = "PY2AND3",105)106py_library(107 name = "debug_events_reader",108 srcs = ["lib/debug_events_reader.py"],109 srcs_version = "PY2AND3",110 deps = [111 "//tensorflow/core:protos_all_py",112 "//tensorflow/python:framework",113 "//tensorflow/python:lib",114 "@six_archive//:six",115 ],116)117py_library(118 name = "debug_events_monitors",119 srcs = ["lib/debug_events_monitors.py"],120 srcs_version = "PY2AND3",121 deps = [122 "//tensorflow/core:protos_all_py",123 "//tensorflow/python:framework",124 "//tensorflow/python:lib",125 "//third_party/py/numpy",126 ],127)128py_library(129 name = "debug_events_writer",130 srcs = ["lib/debug_events_writer.py"],131 srcs_version = "PY2AND3",132 deps = [133 "//tensorflow/core:protos_all_py",134 "//tensorflow/python:framework",135 ],136)137py_library(138 name = "debug_graphs",139 srcs = ["lib/debug_graphs.py"],140 srcs_version = "PY2AND3",141 deps = [142 "//tensorflow/core:protos_all_py",143 "//tensorflow/python:framework",144 "//tensorflow/python:op_def_registry",145 "//tensorflow/python:platform",146 "//tensorflow/python:tensor_util",147 "@six_archive//:six",148 ],149)150py_library(151 name = "debug_data",152 srcs = ["lib/debug_data.py"],153 srcs_version = "PY2AND3",154 visibility = [155 "//tensorflow:internal",156 "//third_party/py/tf_slim:__subpackages__",157 ],158 deps = [159 ":debug_graphs",160 "//tensorflow/core:protos_all_py",161 "//tensorflow/python:framework",162 "//tensorflow/python:op_def_registry",163 "//tensorflow/python:platform",164 "//tensorflow/python:tensor_util",165 "//third_party/py/numpy",166 "@six_archive//:six",167 ],168)169py_library(170 name = "debug_gradients",171 srcs = ["lib/debug_gradients.py"],172 srcs_version = "PY2AND3",173 deps = [174 ":debug_data",175 ":debug_graphs",176 "//tensorflow/python:array_ops",177 "//tensorflow/python:framework",178 "//tensorflow/python:platform",179 "@six_archive//:six",180 ],181)182py_library(183 name = "debug_utils",184 srcs = ["lib/debug_utils.py"],185 srcs_version = "PY2AND3",186)187py_binary(188 name = "grpc_tensorflow_server",189 srcs = ["lib/grpc_tensorflow_server.py"],190 python_version = "PY3",191 srcs_version = "PY2AND3",192 deps = [":grpc_tensorflow_server_lib"],193)194py_library(195 name = "grpc_tensorflow_server_lib",196 srcs = [197 "lib/grpc_tensorflow_server.py",198 ],199 srcs_version = "PY2AND3",200 deps = [201 "//tensorflow/core:protos_all_py",202 "//tensorflow/python:platform",203 "//tensorflow/python:training",204 ],205)206py_library(207 name = "source_utils",208 srcs = ["lib/source_utils.py"],209 srcs_version = "PY2AND3",210 deps = [211 ":profiling",212 "//third_party/py/numpy",213 ],214)215py_library(216 name = "source_remote",217 srcs = ["lib/source_remote.py"],218 srcs_version = "PY2AND3",219 deps = [220 ":common",221 ":debug_service_pb2_grpc",222 "//tensorflow/core/debug:debug_service_proto_py",223 "//tensorflow/python/profiler:tfprof_logger",224 ],225)226py_library(227 name = "framework",228 srcs = ["wrappers/framework.py"],229 srcs_version = "PY2AND3",230 deps = [231 ":debug_utils",232 "//tensorflow/core:protos_all_py",233 "//tensorflow/python:client",234 "//tensorflow/python:errors",235 "//tensorflow/python:framework_ops",236 "//tensorflow/python:training",237 ],238)239py_library(240 name = "debugger_cli_common",241 srcs = ["cli/debugger_cli_common.py"],242 srcs_version = "PY2AND3",243 deps = [244 "//tensorflow/python:platform",245 "//tensorflow/python:pywrap_tf_session",246 "//third_party/py/numpy",247 "@six_archive//:six",248 ],249)250py_library(251 name = "cli_config",252 srcs = ["cli/cli_config.py"],253 srcs_version = "PY2AND3",254 deps = [":debugger_cli_common"],255)256py_library(257 name = "command_parser",258 srcs = ["cli/command_parser.py"],259 srcs_version = "PY2AND3",260)261py_library(262 name = "tensor_format",263 srcs = ["cli/tensor_format.py"],264 srcs_version = "PY2AND3",265 deps = [266 ":debug_data",267 ":debugger_cli_common",268 "//third_party/py/numpy",269 ],270)271py_library(272 name = "cli_shared",273 srcs = ["cli/cli_shared.py"],274 srcs_version = "PY2AND3",275 deps = [276 ":command_parser",277 ":common",278 ":debugger_cli_common",279 ":tensor_format",280 "//tensorflow/python:framework_for_generated_wrappers",281 "//tensorflow/python:platform",282 "//tensorflow/python:variables",283 "//third_party/py/numpy",284 "@six_archive//:six",285 ],286)287py_library(288 name = "evaluator",289 srcs = ["cli/evaluator.py"],290 srcs_version = "PY2AND3",291 deps = [292 ":debug_data",293 "//third_party/py/numpy",294 ],295)296py_library(297 name = "analyzer_cli",298 srcs = ["cli/analyzer_cli.py"],299 srcs_version = "PY2AND3",300 deps = [301 ":cli_config",302 ":cli_shared",303 ":command_parser",304 ":debug_graphs",305 ":debugger_cli_common",306 ":evaluator",307 ":source_utils",308 ":ui_factory",309 "@six_archive//:six",310 ],311)312py_library(313 name = "profiling",314 srcs = ["lib/profiling.py"],315 srcs_version = "PY2AND3",316)317py_library(318 name = "profile_analyzer_cli",319 srcs = ["cli/profile_analyzer_cli.py"],320 srcs_version = "PY2AND3",321 deps = [322 ":cli_shared",323 ":command_parser",324 ":debugger_cli_common",325 ":profiling",326 ":source_utils",327 ":ui_factory",328 "//third_party/py/numpy",329 ],330)331py_library(332 name = "base_ui",333 srcs = ["cli/base_ui.py"],334 srcs_version = "PY2AND3",335 deps = [336 ":cli_config",337 ":command_parser",338 ":debugger_cli_common",339 ],340)341py_library(342 name = "curses_widgets",343 srcs = ["cli/curses_widgets.py"],344 srcs_version = "PY2AND3",345 deps = [":debugger_cli_common"],346)347py_library(348 name = "curses_ui",349 srcs = ["cli/curses_ui.py"],350 srcs_version = "PY2AND3",351 deps = [352 ":base_ui",353 ":cli_shared",354 ":command_parser",355 ":curses_widgets",356 ":debugger_cli_common",357 ":tensor_format",358 "@six_archive//:six",359 ],360)361py_library(362 name = "readline_ui",363 srcs = ["cli/readline_ui.py"],364 srcs_version = "PY2AND3",365 deps = [366 ":base_ui",367 ":debugger_cli_common",368 ],369)370py_library(371 name = "ui_factory",372 srcs = ["cli/ui_factory.py"],373 srcs_version = "PY2AND3",374 deps = [375 ":curses_ui",376 ":readline_ui",377 ],378)379py_library(380 name = "dumping_wrapper",381 srcs = ["wrappers/dumping_wrapper.py"],382 srcs_version = "PY2AND3",383 visibility = [384 "//tensorflow:internal",385 "//third_party/py/tf_slim:__subpackages__",386 ],387 deps = [388 ":debug_data",389 ":framework",390 "//tensorflow/core:protos_all_py",391 "//tensorflow/python:platform",392 ],393)394py_library(395 name = "grpc_wrapper",396 srcs = ["wrappers/grpc_wrapper.py"],397 srcs_version = "PY2AND3",398 deps = [399 ":common",400 ":framework",401 ":source_remote",402 ],403)404py_library(405 name = "local_cli_wrapper",406 srcs = ["wrappers/local_cli_wrapper.py"],407 srcs_version = "PY2AND3",408 deps = [409 ":analyzer_cli",410 ":cli_shared",411 ":command_parser",412 ":common",413 ":debug_data",414 ":debugger_cli_common",415 ":framework",416 ":profile_analyzer_cli",417 ":tensor_format",418 ":ui_factory",419 ],420)421py_library(422 name = "hooks",423 srcs = ["wrappers/hooks.py"],424 srcs_version = "PY2AND3",425 visibility = [426 "//tensorflow:internal",427 "//third_party/py/tf_slim:__subpackages__",428 ],429 deps = [430 ":debug_utils",431 ":dumping_wrapper",432 ":framework",433 ":grpc_wrapper",434 ":local_cli_wrapper",435 "//tensorflow/core:protos_all_py",436 "//tensorflow/python:training",437 ],438)439py_binary(440 name = "offline_analyzer",441 srcs = ["cli/offline_analyzer.py"],442 python_version = "PY3",443 srcs_version = "PY2AND3",444 deps = [":offline_analyzer_lib"],445)446py_library(447 name = "offline_analyzer_lib",448 srcs = ["cli/offline_analyzer.py"],449 srcs_version = "PY2AND3",450 deps = [451 ":analyzer_cli",452 ":debug_data",453 "//tensorflow/python", # TODO(b/34059704): remove when fixed454 "//tensorflow/python:platform",455 ],456)457py_library(458 name = "debug_examples_v1",459 deps = [460 ":debug_errors_lib",461 ":debug_fibonacci_lib",462 ":debug_keras_lib",463 ] + if_not_v2([464 ":debug_mnist_lib",465 ":debug_tflearn_iris_lib",466 ]),467)468py_library(469 name = "debug_examples_v2",470 deps = [471 ":debug_fibonacci_lib",472 ":debug_mnist_lib",473 ],474)475py_binary(476 name = "debug_fibonacci",477 srcs = ["examples/v1/debug_fibonacci.py"],478 python_version = "PY3",479 srcs_version = "PY2AND3",480 deps = [":debug_fibonacci_lib"],481)482py_binary(483 name = "debug_fibonacci_v2",484 srcs = ["examples/v2/debug_fibonacci_v2.py"],485 python_version = "PY3",486 srcs_version = "PY2AND3",487 deps = [":debug_fibonacci_lib"],488)489py_library(490 name = "debug_fibonacci_lib",491 srcs = [492 "examples/v1/debug_fibonacci.py",493 "examples/v2/debug_fibonacci_v2.py",494 ],495 srcs_version = "PY2AND3",496 deps = [497 ":debug_py",498 "//tensorflow:tensorflow_py",499 "//third_party/py/numpy",500 "@six_archive//:six",501 ],502)503py_binary(504 name = "debug_errors",505 srcs = ["examples/v1/debug_errors.py"],506 python_version = "PY3",507 srcs_version = "PY2AND3",508 deps = [":debug_errors_lib"],509)510py_library(511 name = "debug_errors_lib",512 srcs = ["examples/v1/debug_errors.py"],513 srcs_version = "PY2AND3",514 deps = [515 ":debug_py",516 "//tensorflow:tensorflow_py",517 "//third_party/py/numpy",518 ],519)520py_binary(521 name = "debug_mnist",522 srcs = ["examples/debug_mnist.py"],523 python_version = "PY3",524 srcs_version = "PY2AND3",525 deps = [":debug_mnist_lib"],526)527py_binary(528 name = "debug_mnist_v1",529 srcs = ["examples/v1/debug_mnist_v1.py"],530 python_version = "PY3",531 srcs_version = "PY2AND3",532 deps = [":debug_mnist_lib"],533)534py_binary(535 name = "debug_mnist_v2",536 srcs = ["examples/v2/debug_mnist_v2.py"],537 python_version = "PY3",538 srcs_version = "PY2AND3",539 deps = [":debug_mnist_lib"],540)541py_library(542 name = "debug_mnist_lib",543 srcs = [544 "examples/debug_mnist.py",545 "examples/v1/debug_mnist_v1.py",546 "examples/v2/debug_mnist_v2.py",547 ],548 srcs_version = "PY2AND3",549 deps = [550 ":debug_py",551 "//tensorflow:tensorflow_py",552 ],553)554py_binary(555 name = "debug_tflearn_iris",556 srcs = ["examples/v1/debug_tflearn_iris.py"],557 python_version = "PY3",558 srcs_version = "PY2AND3",559 deps = [":debug_tflearn_iris_lib"],560)561py_library(562 name = "debug_tflearn_iris_lib",563 srcs = ["examples/v1/debug_tflearn_iris.py"],564 srcs_version = "PY2AND3",565 deps = [566 ":debug_py",567 "//tensorflow:tensorflow_py",568 "@six_archive//:six",569 ],570)571py_binary(572 name = "debug_keras",573 srcs = ["examples/v1/debug_keras.py"],574 python_version = "PY3",575 srcs_version = "PY2AND3",576 deps = [":debug_keras_lib"],577)578py_library(579 name = "debug_keras_lib",580 srcs = ["examples/v1/debug_keras.py"],581 srcs_version = "PY2AND3",582 deps = [583 ":debug_py",584 "//tensorflow:tensorflow_py",585 "//third_party/py/numpy",586 ],587)588py_test(589 name = "common_test",590 size = "small",591 srcs = ["lib/common_test.py"],592 python_version = "PY3",593 srcs_version = "PY2AND3",594 deps = [595 ":common",596 "//tensorflow/python:client",597 "//tensorflow/python:client_testlib",598 "//tensorflow/python:constant_op",599 "//tensorflow/python:platform_test",600 ],601)602py_test(603 name = "debug_events_monitors_test",604 size = "medium",605 srcs = ["lib/debug_events_monitors_test.py"],606 python_version = "PY3",607 srcs_version = "PY2AND3",608 tags = [609 "no_windows", # b/142475891610 ],611 deps = [612 ":debug_events_monitors",613 ":debug_events_reader",614 ":debug_events_writer",615 ":dumping_callback",616 ":dumping_callback_test_lib",617 "//tensorflow/core:protos_all_py",618 "//tensorflow/python:client_testlib",619 "//tensorflow/python:framework_test_lib",620 "//third_party/py/numpy",621 ],622)623py_test(624 name = "debug_events_writer_test",625 size = "medium",626 srcs = ["lib/debug_events_writer_test.py"],627 python_version = "PY3",628 srcs_version = "PY2AND3",629 tags = [630 "no_windows", # b/142475891631 ],632 deps = [633 ":debug_events_reader",634 ":debug_events_writer",635 ":dumping_callback_test_lib",636 "//tensorflow/core:protos_all_py",637 "//tensorflow/python:client_testlib",638 "//tensorflow/python:framework_test_lib",639 ],640)641py_test(642 name = "debug_graphs_test",643 size = "small",644 srcs = ["lib/debug_graphs_test.py"],645 python_version = "PY3",646 srcs_version = "PY2AND3",647 deps = [648 ":debug_graphs",649 "//tensorflow/python:client_testlib",650 "//tensorflow/python:framework_test_lib",651 ],652)653py_test(654 name = "debug_data_test",655 size = "small",656 srcs = ["lib/debug_data_test.py"],657 python_version = "PY3",658 srcs_version = "PY2AND3",659 deps = [660 ":debug_data",661 "//tensorflow/core:protos_all_py",662 "//tensorflow/python:client_testlib",663 "//tensorflow/python:framework_test_lib",664 "//tensorflow/python:platform",665 "//tensorflow/python:platform_test",666 "//third_party/py/numpy",667 ],668)669cuda_py_test(670 name = "check_numerics_callback_test",671 size = "medium",672 srcs = ["lib/check_numerics_callback_test.py"],673 python_version = "PY3",674 tags = ["no_windows"],675 deps = [676 ":check_numerics_callback",677 "//tensorflow/python:framework_test_lib",678 "//tensorflow/python:math_ops",679 "//tensorflow/python:platform_test",680 "//tensorflow/python:variables",681 "//third_party/py/numpy",682 ],683)684cuda_py_test(685 name = "distributed_callbacks_test",686 size = "medium",687 srcs = ["lib/distributed_callbacks_test.py"],688 python_version = "PY3",689 shard_count = 4,690 tags = [691 "guitar",692 "multi_and_single_gpu",693 "no_windows", # TODO(b/142475891): Enable this test on Windows.694 "no_windows_gpu", # TODO(b/130551176)695 ],696 xla_enable_strict_auto_jit = False, # Node names are different with autojit697 deps = [698 ":check_numerics_callback",699 ":debug_events_reader",700 ":debug_events_writer",701 ":dumping_callback",702 ":dumping_callback_test_lib",703 "//tensorflow/python:framework_test_lib",704 "//tensorflow/python:math_ops",705 "//tensorflow/python:platform_test",706 "//tensorflow/python:variables",707 "//tensorflow/python/distribute:combinations",708 "//tensorflow/python/distribute:mirrored_strategy",709 "//tensorflow/python/distribute:strategy_combinations",710 "//tensorflow/python/keras",711 "//third_party/py/numpy",712 ],713)714cuda_py_test(715 name = "dumping_callback_test",716 size = "medium",717 srcs = ["lib/dumping_callback_test.py"],718 python_version = "PY3",719 shard_count = 8,720 tags = [721 "no_windows", # TODO(b/142475891): Enable this test on Windows.722 ],723 xla_enable_strict_auto_jit = False, # Node names are different with autojit724 deps = [725 ":debug_events_reader",726 ":debug_events_writer",727 ":dumping_callback",728 ":dumping_callback_test_lib",729 "//tensorflow/python:framework_test_lib",730 "//tensorflow/python:math_ops",731 "//tensorflow/python:platform_test",732 "//tensorflow/python:variables",733 "//tensorflow/python/keras",734 "//third_party/py/numpy",735 ],736)737cuda_py_test(738 name = "debug_v2_ops_test",739 size = "medium",740 srcs = ["lib/debug_v2_ops_test.py"],741 python_version = "PY3",742 tags = [743 "no_windows", # b/142475891744 ],745 deps = [746 ":debug_events_reader",747 ":debug_events_writer",748 ":dumping_callback_test_lib",749 "//tensorflow/python:debug_ops_gen",750 "//tensorflow/python:framework_test_lib",751 "//tensorflow/python:gradients",752 "//tensorflow/python:math_ops",753 "//tensorflow/python:platform_test",754 "//tensorflow/python:training",755 "//tensorflow/python:variables",756 "//tensorflow/python/data/ops:dataset_ops",757 "//tensorflow/python/keras",758 "//third_party/py/numpy",759 ],760)761cuda_py_test(762 name = "debug_gradients_test",763 size = "small",764 srcs = ["lib/debug_gradients_test.py"],765 python_version = "PY3",766 xla_enable_strict_auto_jit = False, # Node names are different with autojit767 deps = [768 ":debug_data",769 ":debug_gradients",770 ":debug_utils",771 "//tensorflow/python:client",772 "//tensorflow/python:framework_test_lib",773 "//tensorflow/python:gradients",774 "//tensorflow/python:math_ops",775 "//tensorflow/python:platform_test",776 "//tensorflow/python:training",777 "//tensorflow/python:variables",778 ],779)780py_test(781 name = "debug_utils_test",782 size = "small",783 srcs = ["lib/debug_utils_test.py"],784 python_version = "PY3",785 srcs_version = "PY2AND3",786 deps = [787 ":debug_utils",788 "//tensorflow/core:protos_all_py",789 "//tensorflow/python:client",790 "//tensorflow/python:framework_for_generated_wrappers",791 "//tensorflow/python:framework_test_lib",792 "//tensorflow/python:math_ops",793 "//tensorflow/python:platform_test",794 "//tensorflow/python:resource_variable_ops",795 "//tensorflow/python:variables",796 "//third_party/py/numpy",797 ],798)799py_test(800 name = "source_utils_test",801 size = "small",802 srcs = ["lib/source_utils_test.py"],803 python_version = "PY3",804 srcs_version = "PY2AND3",805 tags = [806 "no_oss_py38", #TODO(b/151449908)807 "no_windows",808 ],809 deps = [810 ":debug_data",811 ":debug_utils",812 ":source_utils",813 "//tensorflow/core:protos_all_py",814 "//tensorflow/python:client",815 "//tensorflow/python:cond_v2",816 "//tensorflow/python:constant_op",817 "//tensorflow/python:control_flow_ops",818 "//tensorflow/python:framework_ops",819 "//tensorflow/python:framework_test_lib",820 "//tensorflow/python:math_ops",821 "//tensorflow/python:platform_test",822 "//tensorflow/python:resource_variable_ops",823 "//tensorflow/python:util",824 "//tensorflow/python:variables",825 "//tensorflow/python:while_v2",826 "//third_party/py/numpy",827 ],828)829py_test(830 name = "source_remote_test",831 size = "small",832 srcs = ["lib/source_remote_test.py"],833 python_version = "PY3",834 srcs_version = "PY2AND3",835 tags = [836 "no_windows",837 "oss_serial",838 ],839 deps = [840 ":grpc_debug_test_server",841 ":source_remote",842 ":source_utils",843 "//tensorflow/core:protos_all_py",844 "//tensorflow/python:client",845 "//tensorflow/python:client_testlib",846 "//tensorflow/python:framework_ops",847 "//tensorflow/python:framework_test_lib",848 "//tensorflow/python:math_ops",849 "//tensorflow/python:platform_test",850 "//tensorflow/python:resource_variable_ops",851 "//tensorflow/python:util",852 "//tensorflow/python:variables",853 ],854)855py_test(856 name = "framework_test",857 size = "medium",858 srcs = ["wrappers/framework_test.py"],859 python_version = "PY3",860 srcs_version = "PY2AND3",861 deps = [862 ":debug_data",863 ":framework",864 "//tensorflow/core:protos_all_py",865 "//tensorflow/python:array_ops",866 "//tensorflow/python:client",867 "//tensorflow/python:errors",868 "//tensorflow/python:framework_for_generated_wrappers",869 "//tensorflow/python:framework_test_lib",870 "//tensorflow/python:math_ops",871 "//tensorflow/python:platform_test",872 "//tensorflow/python:resource_variable_ops",873 "//tensorflow/python:training",874 "//tensorflow/python:util",875 "//tensorflow/python:variables",876 "//third_party/py/numpy",877 ],878)879py_test(880 name = "profiling_test",881 size = "small",882 srcs = ["lib/profiling_test.py"],883 python_version = "PY3",884 srcs_version = "PY2AND3",885 deps = [886 ":profiling",887 "//tensorflow/core:protos_all_py",888 "//tensorflow/python:framework_test_lib",889 "//tensorflow/python:platform_test",890 ],891)892py_test(893 name = "curses_ui_test",894 size = "small",895 srcs = ["cli/curses_ui_test.py"],896 python_version = "PY3",897 srcs_version = "PY2AND3",898 tags = [899 "no_windows",900 ],901 deps = [902 ":cli_test_utils",903 ":curses_ui",904 ":debugger_cli_common",905 ":tensor_format",906 "//tensorflow/python:framework_test_lib",907 "//tensorflow/python:platform",908 "//tensorflow/python:platform_test",909 "//third_party/py/numpy",910 ],911)912py_test(913 name = "readline_ui_test",914 size = "small",915 srcs = ["cli/readline_ui_test.py"],916 python_version = "PY3",917 srcs_version = "PY2AND3",918 deps = [919 ":cli_config",920 ":debugger_cli_common",921 ":readline_ui",922 ":ui_factory",923 "//tensorflow/python:framework_test_lib",924 "//tensorflow/python:platform",925 "//tensorflow/python:platform_test",926 ],927)928py_library(929 name = "session_debug_testlib",930 srcs = ["lib/session_debug_testlib.py"],931 srcs_version = "PY2AND3",932 deps = [933 ":debug_data",934 ":debug_graphs",935 ":debug_utils",936 "//tensorflow/core:protos_all_py",937 "//tensorflow/python:array_ops",938 "//tensorflow/python:client",939 "//tensorflow/python:client_testlib",940 "//tensorflow/python:control_flow_ops",941 "//tensorflow/python:data_flow_ops",942 "//tensorflow/python:errors",943 "//tensorflow/python:framework_for_generated_wrappers",944 "//tensorflow/python:framework_test_lib",945 "//tensorflow/python:math_ops",946 "//tensorflow/python:parsing_ops",947 "//tensorflow/python:platform_test",948 "//tensorflow/python:rnn",949 "//tensorflow/python:rnn_cell",950 "//tensorflow/python:state_ops",951 "//tensorflow/python:tensor_array_grad",952 "//tensorflow/python:training",953 "//tensorflow/python:variables",954 "//third_party/py/numpy",955 "@six_archive//:six",956 ],957)958py_library(959 name = "debug_service_pb2_grpc",960 srcs = ["lib/debug_service_pb2_grpc.py"],961 srcs_version = "PY2AND3",962 deps = [963 "//tensorflow/core/debug:debug_service_proto_py",964 ],965)966py_library(967 name = "grpc_debug_server",968 srcs = ["lib/grpc_debug_server.py"],969 srcs_version = "PY2AND3",970 visibility = ["//visibility:public"],971 deps = [972 ":debug_graphs",973 ":debug_service_pb2_grpc",974 "//tensorflow/core/debug:debug_service_proto_py",975 "@six_archive//:six",976 ],977)978py_library(979 name = "grpc_debug_test_server",980 srcs = ["lib/grpc_debug_test_server.py"],981 srcs_version = "PY2AND3",982 deps = [983 ":debug_data",984 ":debug_utils",985 ":grpc_debug_server",986 "//tensorflow/core:protos_all_py",987 "//tensorflow/python:client",988 "//tensorflow/python:constant_op",989 "//tensorflow/python:errors",990 "//tensorflow/python:variables",991 ],992)993cuda_py_test(994 name = "debug_grappler_test",995 size = "small",996 srcs = ["lib/debug_grappler_test.py"],997 python_version = "PY3",998 xla_enable_strict_auto_jit = False, # Tests TF:Classic implementation.999 deps = [1000 ":debug_data",1001 ":debug_utils",1002 "//tensorflow/python:client",1003 "//tensorflow/python:framework_for_generated_wrappers",1004 "//tensorflow/python:math_ops",1005 "//tensorflow/python:platform_test",1006 "//tensorflow/python:variables",1007 ],1008)1009cuda_py_test(1010 name = "session_debug_file_test",1011 size = "small",1012 srcs = ["lib/session_debug_file_test.py"],1013 python_version = "PY3",1014 tags = ["notsan"],1015 xla_enable_strict_auto_jit = False, # Node names are different with autojit1016 deps = [1017 ":debug_data",1018 ":debug_utils",1019 ":session_debug_testlib",1020 "//tensorflow/python:client",1021 "//tensorflow/python:framework_for_generated_wrappers",1022 "//tensorflow/python:math_ops",1023 "//tensorflow/python:platform_test",1024 "//tensorflow/python:variables",1025 ],1026)1027cuda_py_test(1028 name = "debug_graph_reconstruction_test",1029 size = "small",1030 srcs = ["lib/debug_graph_reconstruction_test.py"],1031 python_version = "PY3",1032 xla_enable_strict_auto_jit = False, # Node names are different with autojit1033 deps = [1034 ":debug_data",1035 ":debug_utils",1036 "//tensorflow/python:client",1037 "//tensorflow/python:client_testlib",1038 "//tensorflow/python:control_flow_ops",1039 "//tensorflow/python:framework_test_lib",1040 "//tensorflow/python:math_ops",1041 "//tensorflow/python:training",1042 "//tensorflow/python:variables",1043 ],1044)1045cuda_py_test(1046 name = "session_debug_multi_gpu_test",1047 size = "small",1048 srcs = ["lib/session_debug_multi_gpu_test.py"],1049 python_version = "PY3",1050 tags = ["no_windows_gpu"],1051 xla_enable_strict_auto_jit = False, # Node names are different with autojit1052 deps = [1053 ":debug_data",1054 ":debug_utils",1055 "//tensorflow/python:client",1056 "//tensorflow/python:framework_for_generated_wrappers",1057 "//tensorflow/python:framework_test_lib",1058 "//tensorflow/python:math_ops",1059 "//tensorflow/python:platform_test",1060 "//tensorflow/python:variables",1061 ],1062)1063py_test(1064 name = "debugger_cli_common_test",1065 size = "small",1066 srcs = ["cli/debugger_cli_common_test.py"],1067 python_version = "PY3",1068 srcs_version = "PY2AND3",1069 deps = [1070 ":debugger_cli_common",1071 "//tensorflow/python:framework_test_lib",1072 "//tensorflow/python:platform",1073 "//tensorflow/python:platform_test",1074 "//tensorflow/python:pywrap_tf_session",1075 "//third_party/py/numpy",1076 ],1077)1078py_test(1079 name = "cli_config_test",1080 size = "small",1081 srcs = ["cli/cli_config_test.py"],1082 python_version = "PY3",1083 srcs_version = "PY2AND3",1084 deps = [1085 ":cli_config",1086 "//tensorflow/python:framework_test_lib",1087 "//tensorflow/python:platform",1088 "//tensorflow/python:platform_test",1089 ],1090)1091py_test(1092 name = "command_parser_test",1093 size = "small",1094 srcs = ["cli/command_parser_test.py"],1095 python_version = "PY3",1096 srcs_version = "PY2AND3",1097 deps = [1098 ":command_parser",1099 "//tensorflow/python:framework_test_lib",1100 "//tensorflow/python:platform_test",1101 ],1102)1103py_test(1104 name = "tensor_format_test",1105 size = "small",1106 srcs = ["cli/tensor_format_test.py"],1107 python_version = "PY3",1108 srcs_version = "PY2AND3",1109 deps = [1110 ":cli_test_utils",1111 ":debug_data",1112 ":tensor_format",1113 "//tensorflow/core:protos_all_py",1114 "//tensorflow/python:framework_test_lib",1115 "//tensorflow/python:platform_test",1116 "//third_party/py/numpy",1117 "@six_archive//:six",1118 ],1119)1120py_test(1121 name = "cli_shared_test",1122 size = "small",1123 srcs = ["cli/cli_shared_test.py"],1124 python_version = "PY3",1125 srcs_version = "PY2AND3",1126 deps = [1127 ":cli_shared",1128 ":debugger_cli_common",1129 "//tensorflow/python:errors",1130 "//tensorflow/python:framework_for_generated_wrappers",1131 "//tensorflow/python:framework_test_lib",1132 "//tensorflow/python:platform_test",1133 "//tensorflow/python:sparse_tensor",1134 "//tensorflow/python:variables",1135 ],1136)1137py_test(1138 name = "evaluator_test",1139 size = "small",1140 srcs = [1141 "cli/evaluator_test.py",1142 ],1143 python_version = "PY3",1144 srcs_version = "PY2AND3",1145 deps = [1146 ":debug_data",1147 ":evaluator",1148 "//tensorflow/python:client_testlib",1149 "//tensorflow/python:framework_test_lib",1150 "//third_party/py/numpy",1151 ],1152)1153py_library(1154 name = "cli_test_utils",1155 srcs = ["cli/cli_test_utils.py"],1156 srcs_version = "PY2AND3",1157)1158cuda_py_test(1159 name = "analyzer_cli_test",1160 size = "small",1161 srcs = ["cli/analyzer_cli_test.py"],1162 python_version = "PY3",1163 tags = ["no_windows"], # TODO: needs investigation on Windows1164 xla_enable_strict_auto_jit = False, # Node names are different with autojit1165 deps = [1166 ":analyzer_cli",1167 ":cli_config",1168 ":cli_test_utils",1169 ":command_parser",1170 ":debug_data",1171 ":debug_utils",1172 ":debugger_cli_common",1173 ":source_utils",1174 "//tensorflow:tensorflow_py",1175 "//tensorflow/python:array_ops",1176 "//tensorflow/python:client",1177 "//tensorflow/python:client_testlib",1178 "//tensorflow/python:control_flow_ops",1179 "//tensorflow/python:framework_for_generated_wrappers",1180 "//tensorflow/python:framework_test_lib",1181 "//tensorflow/python:math_ops",1182 "//tensorflow/python:platform_test",1183 "//tensorflow/python:util",1184 "//tensorflow/python:variables",1185 "//third_party/py/numpy",1186 "@six_archive//:six",1187 ],1188)1189py_test(1190 name = "profile_analyzer_cli_test",1191 size = "small",1192 srcs = ["cli/profile_analyzer_cli_test.py"],1193 python_version = "PY3",1194 srcs_version = "PY2AND3",1195 deps = [1196 ":debugger_cli_common",1197 ":profile_analyzer_cli",1198 "//tensorflow/core:protos_all_py",1199 "//tensorflow/python:client_testlib",1200 "//tensorflow/python:control_flow_ops",1201 "//tensorflow/python:framework_for_generated_wrappers",1202 "//tensorflow/python:framework_test_lib",1203 "//tensorflow/python:math_ops",1204 "//tensorflow/python:platform_test",1205 "//tensorflow/python:session",1206 "//tensorflow/python:util",1207 ],1208)1209cuda_py_test(1210 name = "session_debug_grpc_test",1211 size = "medium",1212 srcs = ["lib/session_debug_grpc_test.py"],1213 python_version = "PY3",1214 tags = [1215 "no_oss", # Test flaky due to port collisions.1216 "no_windows",1217 "notsan",1218 "oss_serial",1219 ],1220 xla_enable_strict_auto_jit = False, # Node names are different with autojit1221 deps = [1222 ":debug_data",1223 ":debug_utils",1224 ":dumping_wrapper",1225 ":grpc_debug_test_server",1226 ":grpc_wrapper",1227 ":hooks",1228 ":session_debug_testlib",1229 "//tensorflow/python:client",1230 "//tensorflow/python:client_testlib",1231 "//tensorflow/python:framework_for_generated_wrappers",1232 "//tensorflow/python:math_ops",1233 "//tensorflow/python:platform_test",1234 "//tensorflow/python:variables",1235 ],1236)1237cuda_py_test(1238 name = "grpc_large_data_test",1239 size = "medium",1240 srcs = ["lib/grpc_large_data_test.py"],1241 python_version = "PY3",1242 tags = [1243 "no_oss", # Test flaky due to port collisions.1244 "no_windows",1245 "noasan", # Times out due to size of test (b/73731462).1246 "optonly", # Test flaky (b/80130873)1247 "oss_serial",1248 ],1249 xla_enable_strict_auto_jit = False, # Node names are different with autojit1250 deps = [1251 ":dumping_wrapper",1252 ":grpc_debug_test_server",1253 ":grpc_wrapper",1254 ":session_debug_testlib",1255 "//tensorflow/python:client",1256 "//tensorflow/python:client_testlib",1257 "//tensorflow/python:framework_for_generated_wrappers",1258 "//tensorflow/python:platform_test",1259 "//tensorflow/python:variables",1260 "//third_party/py/numpy",1261 ],1262)1263# TODO(cais): Run the test in OSS, perhaps through a sh_test.1264cuda_py_test(1265 name = "dist_session_debug_grpc_test",1266 size = "medium",1267 srcs = ["lib/dist_session_debug_grpc_test.py"],1268 grpc_enabled = True,1269 python_version = "PY3",1270 tags = [1271 "no_oss", # Incompatible with bazel_pip.1272 "no_windows",1273 "notsan",1274 ],1275 xla_enable_strict_auto_jit = False, # Node names are different with autojit1276 deps = [1277 ":debug_data",1278 ":debug_utils",1279 ":dumping_wrapper",1280 ":grpc_debug_test_server",1281 ":grpc_wrapper",1282 ":hooks",1283 "//tensorflow/python:client",1284 "//tensorflow/python:client_testlib",1285 "//tensorflow/python:framework_for_generated_wrappers",1286 "//tensorflow/python:math_ops",1287 "//tensorflow/python:platform_test",1288 "//tensorflow/python:variables",1289 ],1290)1291py_test(1292 name = "dumping_wrapper_test",1293 size = "small",1294 srcs = ["wrappers/dumping_wrapper_test.py"],1295 python_version = "PY3",1296 srcs_version = "PY2AND3",1297 deps = [1298 ":debug_data",1299 ":dumping_wrapper",1300 ":framework",1301 ":hooks",1302 "//tensorflow/python:array_ops",1303 "//tensorflow/python:client",1304 "//tensorflow/python:framework_for_generated_wrappers",1305 "//tensorflow/python:framework_test_lib",1306 "//tensorflow/python:platform",1307 "//tensorflow/python:platform_test",1308 "//tensorflow/python:state_ops",1309 "//tensorflow/python:training",1310 "//tensorflow/python:variables",1311 ],1312)1313py_test(1314 name = "local_cli_wrapper_test",1315 size = "small",1316 srcs = ["wrappers/local_cli_wrapper_test.py"],1317 python_version = "PY3",1318 srcs_version = "PY2AND3",1319 deps = [1320 ":cli_shared",1321 ":debugger_cli_common",1322 ":local_cli_wrapper",1323 ":ui_factory",1324 "//tensorflow/core:protos_all_py",1325 "//tensorflow/python:array_ops",1326 "//tensorflow/python:client",1327 "//tensorflow/python:control_flow_ops",1328 "//tensorflow/python:errors",1329 "//tensorflow/python:framework_for_generated_wrappers",1330 "//tensorflow/python:framework_test_lib",1331 "//tensorflow/python:math_ops",1332 "//tensorflow/python:platform_test",1333 "//tensorflow/python:resource_variable_ops",1334 "//tensorflow/python:state_ops",1335 "//tensorflow/python:training",1336 "//tensorflow/python:variables",1337 "//tensorflow/python/keras",1338 "//third_party/py/numpy",1339 ],1340)1341py_test(1342 name = "disk_usage_test",1343 size = "small",1344 srcs = ["wrappers/disk_usage_test.py"],1345 python_version = "PY3",1346 srcs_version = "PY2AND3",1347 deps = [1348 ":dumping_wrapper",1349 ":hooks",1350 "//tensorflow/python:client",1351 "//tensorflow/python:errors",1352 "//tensorflow/python:framework_test_lib",1353 "//tensorflow/python:platform_test",1354 "//tensorflow/python:training",1355 "//tensorflow/python:variables",1356 ],1357)1358sh_test(1359 name = "examples_v1_test",1360 size = "medium",1361 srcs = ["examples/v1/examples_v1_test.sh"],1362 data = [1363 ":debug_errors",1364 ":debug_fibonacci",1365 ":debug_keras",1366 ":debug_mnist",1367 ":debug_tflearn_iris",1368 ":offline_analyzer",1369 ],1370 tags = [1371 "no_windows",1372 "noasan", # TODO(b/143150907)1373 "nomsan", # TODO(b/143150907)1374 "v1only",1375 ],1376)1377sh_test(1378 name = "examples_v2_test",1379 size = "medium",1380 srcs = ["examples/v2/examples_v2_test.sh"],1381 data = [1382 ":debug_fibonacci_v2",1383 ":debug_mnist_v2",1384 ],1385 tags = [1386 "no_windows",1387 ],...

Full Screen

Full Screen

session_debug_grpc_test.py

Source:session_debug_grpc_test.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Tests for debugger functionalities in tf.compat.v1.Session with grpc:// URLs.16This test file focuses on the grpc:// debugging of local (non-distributed)17tf.Sessions.18"""19from __future__ import absolute_import20from __future__ import division21from __future__ import print_function22import os23from six.moves import xrange # pylint: disable=redefined-builtin24from tensorflow.core.protobuf import config_pb225from tensorflow.python.client import session26from tensorflow.python.debug.lib import debug_data27from tensorflow.python.debug.lib import debug_utils28from tensorflow.python.debug.lib import grpc_debug_test_server29from tensorflow.python.debug.lib import session_debug_testlib30from tensorflow.python.debug.wrappers import framework31from tensorflow.python.debug.wrappers import grpc_wrapper32from tensorflow.python.debug.wrappers import hooks33from tensorflow.python.framework import constant_op34from tensorflow.python.framework import ops35from tensorflow.python.framework import test_util36from tensorflow.python.lib.io import file_io37from tensorflow.python.ops import math_ops38from tensorflow.python.ops import state_ops39from tensorflow.python.ops import variables40from tensorflow.python.platform import googletest41from tensorflow.python.training import monitored_session42class GrpcDebugServerTest(test_util.TensorFlowTestCase):43 def testRepeatedRunServerRaisesException(self):44 (_, _, _, server_thread,45 server) = grpc_debug_test_server.start_server_on_separate_thread(46 poll_server=True)47 # The server is started asynchronously. It needs to be polled till its state48 # has become started.49 with self.assertRaisesRegexp(50 ValueError, "Server has already started running"):51 server.run_server()52 server.stop_server().wait()53 server_thread.join()54 def testRepeatedStopServerRaisesException(self):55 (_, _, _, server_thread,56 server) = grpc_debug_test_server.start_server_on_separate_thread(57 poll_server=True)58 server.stop_server().wait()59 server_thread.join()60 with self.assertRaisesRegexp(ValueError, "Server has already stopped"):61 server.stop_server().wait()62 def testRunServerAfterStopRaisesException(self):63 (_, _, _, server_thread,64 server) = grpc_debug_test_server.start_server_on_separate_thread(65 poll_server=True)66 server.stop_server().wait()67 server_thread.join()68 with self.assertRaisesRegexp(ValueError, "Server has already stopped"):69 server.run_server()70 def testStartServerWithoutBlocking(self):71 (_, _, _, server_thread,72 server) = grpc_debug_test_server.start_server_on_separate_thread(73 poll_server=True, blocking=False)74 # The thread that starts the server shouldn't block, so we should be able to75 # join it before stopping the server.76 server_thread.join()77 server.stop_server().wait()78@test_util.run_v1_only("b/120545219")79class SessionDebugGrpcTest(session_debug_testlib.SessionDebugTestBase):80 @classmethod81 def setUpClass(cls):82 session_debug_testlib.SessionDebugTestBase.setUpClass()83 (cls._server_port, cls._debug_server_url, cls._server_dump_dir,84 cls._server_thread,85 cls._server) = grpc_debug_test_server.start_server_on_separate_thread()86 @classmethod87 def tearDownClass(cls):88 # Stop the test server and join the thread.89 cls._server.stop_server().wait()90 cls._server_thread.join()91 session_debug_testlib.SessionDebugTestBase.tearDownClass()92 def setUp(self):93 # Override the dump root as the test server's dump directory.94 self._dump_root = self._server_dump_dir95 def tearDown(self):96 if os.path.isdir(self._server_dump_dir):97 file_io.delete_recursively(self._server_dump_dir)98 session_debug_testlib.SessionDebugTestBase.tearDown(self)99 def _debug_urls(self, run_number=None):100 return ["grpc://localhost:%d" % self._server_port]101 def _debug_dump_dir(self, run_number=None):102 if run_number is None:103 return self._dump_root104 else:105 return os.path.join(self._dump_root, "run_%d" % run_number)106 def testConstructGrpcDebugWrapperSessionWithInvalidTypeRaisesException(self):107 sess = session.Session(108 config=session_debug_testlib.no_rewrite_session_config())109 with self.assertRaisesRegexp(110 TypeError, "Expected type str or list in grpc_debug_server_addresses"):111 grpc_wrapper.GrpcDebugWrapperSession(sess, 1337)112 def testConstructGrpcDebugWrapperSessionWithInvalidTypeRaisesException2(self):113 sess = session.Session(114 config=session_debug_testlib.no_rewrite_session_config())115 with self.assertRaisesRegexp(116 TypeError, "Expected type str in list grpc_debug_server_addresses"):117 grpc_wrapper.GrpcDebugWrapperSession(sess, ["localhost:1337", 1338])118 def testUseInvalidWatchFnTypeWithGrpcDebugWrapperSessionRaisesException(self):119 sess = session.Session(120 config=session_debug_testlib.no_rewrite_session_config())121 with self.assertRaises(TypeError):122 grpc_wrapper.GrpcDebugWrapperSession(123 sess, "localhost:%d" % self._server_port, watch_fn="foo")124 def testGrpcDebugWrapperSessionWithoutWatchFnWorks(self):125 u = variables.VariableV1(2.1, name="u")126 v = variables.VariableV1(20.0, name="v")127 w = math_ops.multiply(u, v, name="w")128 sess = session.Session(129 config=session_debug_testlib.no_rewrite_session_config())130 sess.run(u.initializer)131 sess.run(v.initializer)132 sess = grpc_wrapper.GrpcDebugWrapperSession(133 sess, "localhost:%d" % self._server_port)134 w_result = sess.run(w)135 self.assertAllClose(42.0, w_result)136 dump = debug_data.DebugDumpDir(self._dump_root)137 self.assertLessEqual(5, dump.size)138 self.assertAllClose([2.1], dump.get_tensors("u", 0, "DebugIdentity"))139 self.assertAllClose([2.1], dump.get_tensors("u/read", 0, "DebugIdentity"))140 self.assertAllClose([20.0], dump.get_tensors("v", 0, "DebugIdentity"))141 self.assertAllClose([20.0], dump.get_tensors("v/read", 0, "DebugIdentity"))142 self.assertAllClose([42.0], dump.get_tensors("w", 0, "DebugIdentity"))143 def testGrpcDebugWrapperSessionWithWatchFnWorks(self):144 def watch_fn(feeds, fetch_keys):145 del feeds, fetch_keys146 return ["DebugIdentity", "DebugNumericSummary"], r".*/read", None147 u = variables.VariableV1(2.1, name="u")148 v = variables.VariableV1(20.0, name="v")149 w = math_ops.multiply(u, v, name="w")150 sess = session.Session(151 config=session_debug_testlib.no_rewrite_session_config())152 sess.run(u.initializer)153 sess.run(v.initializer)154 sess = grpc_wrapper.GrpcDebugWrapperSession(155 sess, "localhost:%d" % self._server_port, watch_fn=watch_fn)156 w_result = sess.run(w)157 self.assertAllClose(42.0, w_result)158 dump = debug_data.DebugDumpDir(self._dump_root)159 self.assertEqual(4, dump.size)160 self.assertAllClose([2.1], dump.get_tensors("u/read", 0, "DebugIdentity"))161 self.assertEqual(162 14, len(dump.get_tensors("u/read", 0, "DebugNumericSummary")[0]))163 self.assertAllClose([20.0], dump.get_tensors("v/read", 0, "DebugIdentity"))164 self.assertEqual(165 14, len(dump.get_tensors("v/read", 0, "DebugNumericSummary")[0]))166 def testGrpcDebugHookWithStatelessWatchFnWorks(self):167 # Perform some set up. Specifically, construct a simple TensorFlow graph and168 # create a watch function for certain ops.169 def watch_fn(feeds, fetch_keys):170 del feeds, fetch_keys171 return framework.WatchOptions(172 debug_ops=["DebugIdentity", "DebugNumericSummary"],173 node_name_regex_whitelist=r".*/read",174 op_type_regex_whitelist=None,175 tolerate_debug_op_creation_failures=True)176 u = variables.VariableV1(2.1, name="u")177 v = variables.VariableV1(20.0, name="v")178 w = math_ops.multiply(u, v, name="w")179 sess = session.Session(180 config=session_debug_testlib.no_rewrite_session_config())181 sess.run(u.initializer)182 sess.run(v.initializer)183 # Create a hook. One could use this hook with say a tflearn Estimator.184 # However, we use a HookedSession in this test to avoid depending on the185 # internal implementation of Estimators.186 grpc_debug_hook = hooks.GrpcDebugHook(187 ["localhost:%d" % self._server_port], watch_fn=watch_fn)188 sess = monitored_session._HookedSession(sess, [grpc_debug_hook])189 # Run the hooked session. This should stream tensor data to the GRPC190 # endpoints.191 w_result = sess.run(w)192 # Verify that the hook monitored the correct tensors.193 self.assertAllClose(42.0, w_result)194 dump = debug_data.DebugDumpDir(self._dump_root)195 self.assertEqual(4, dump.size)196 self.assertAllClose([2.1], dump.get_tensors("u/read", 0, "DebugIdentity"))197 self.assertEqual(198 14, len(dump.get_tensors("u/read", 0, "DebugNumericSummary")[0]))199 self.assertAllClose([20.0], dump.get_tensors("v/read", 0, "DebugIdentity"))200 self.assertEqual(201 14, len(dump.get_tensors("v/read", 0, "DebugNumericSummary")[0]))202 def testTensorBoardDebugHookWorks(self):203 u = variables.VariableV1(2.1, name="u")204 v = variables.VariableV1(20.0, name="v")205 w = math_ops.multiply(u, v, name="w")206 sess = session.Session(207 config=session_debug_testlib.no_rewrite_session_config())208 sess.run(u.initializer)209 sess.run(v.initializer)210 grpc_debug_hook = hooks.TensorBoardDebugHook(211 ["localhost:%d" % self._server_port])212 sess = monitored_session._HookedSession(sess, [grpc_debug_hook])213 # Activate watch point on a tensor before calling sess.run().214 self._server.request_watch("u/read", 0, "DebugIdentity")215 self.assertAllClose(42.0, sess.run(w))216 # self.assertAllClose(42.0, sess.run(w))217 dump = debug_data.DebugDumpDir(self._dump_root)218 self.assertAllClose([2.1], dump.get_tensors("u/read", 0, "DebugIdentity"))219 # Check that the server has received the stack trace.220 self.assertTrue(self._server.query_op_traceback("u"))221 self.assertTrue(self._server.query_op_traceback("u/read"))222 self.assertTrue(self._server.query_op_traceback("v"))223 self.assertTrue(self._server.query_op_traceback("v/read"))224 self.assertTrue(self._server.query_op_traceback("w"))225 # Check that the server has received the python file content.226 # Query an arbitrary line to make sure that is the case.227 with open(__file__, "rt") as this_source_file:228 first_line = this_source_file.readline().strip()229 self.assertEqual(230 first_line, self._server.query_source_file_line(__file__, 1))231 self._server.clear_data()232 # Call sess.run() again, and verify that this time the traceback and source233 # code is not sent, because the graph version is not newer.234 self.assertAllClose(42.0, sess.run(w))235 with self.assertRaises(ValueError):236 self._server.query_op_traceback("delta_1")237 with self.assertRaises(ValueError):238 self._server.query_source_file_line(__file__, 1)239 def testTensorBoardDebugHookDisablingTracebackSourceCodeSendingWorks(self):240 u = variables.VariableV1(2.1, name="u")241 v = variables.VariableV1(20.0, name="v")242 w = math_ops.multiply(u, v, name="w")243 sess = session.Session(244 config=session_debug_testlib.no_rewrite_session_config())245 sess.run(variables.global_variables_initializer())246 grpc_debug_hook = hooks.TensorBoardDebugHook(247 ["localhost:%d" % self._server_port],248 send_traceback_and_source_code=False)249 sess = monitored_session._HookedSession(sess, [grpc_debug_hook])250 # Activate watch point on a tensor before calling sess.run().251 self._server.request_watch("u/read", 0, "DebugIdentity")252 self.assertAllClose(42.0, sess.run(w))253 # Check that the server has _not_ received any tracebacks, as a result of254 # the disabling above.255 with self.assertRaisesRegexp(256 ValueError, r"Op .*u/read.* does not exist"):257 self.assertTrue(self._server.query_op_traceback("u/read"))258 with self.assertRaisesRegexp(259 ValueError, r".* has not received any source file"):260 self._server.query_source_file_line(__file__, 1)261 def testConstructGrpcDebugHookWithOrWithouGrpcInUrlWorks(self):262 hooks.GrpcDebugHook(["grpc://foo:42424"])263 hooks.GrpcDebugHook(["foo:42424"])264class SessionDebugConcurrentTest(265 session_debug_testlib.DebugConcurrentRunCallsTest):266 @classmethod267 def setUpClass(cls):268 session_debug_testlib.SessionDebugTestBase.setUpClass()269 (cls._server_port, cls._debug_server_url, cls._server_dump_dir,270 cls._server_thread,271 cls._server) = grpc_debug_test_server.start_server_on_separate_thread()272 @classmethod273 def tearDownClass(cls):274 # Stop the test server and join the thread.275 cls._server.stop_server().wait()276 cls._server_thread.join()277 session_debug_testlib.SessionDebugTestBase.tearDownClass()278 def setUp(self):279 self._num_concurrent_runs = 3280 self._dump_roots = []281 for i in range(self._num_concurrent_runs):282 self._dump_roots.append(283 os.path.join(self._server_dump_dir, "thread%d" % i))284 def tearDown(self):285 ops.reset_default_graph()286 if os.path.isdir(self._server_dump_dir):287 file_io.delete_recursively(self._server_dump_dir)288 def _get_concurrent_debug_urls(self):289 urls = []290 for i in range(self._num_concurrent_runs):291 urls.append(self._debug_server_url + "/thread%d" % i)292 return urls293@test_util.run_v1_only("b/120545219")294class SessionDebugGrpcGatingTest(test_util.TensorFlowTestCase):295 """Test server gating of debug ops."""296 @classmethod297 def setUpClass(cls):298 (cls._server_port_1, cls._debug_server_url_1, _, cls._server_thread_1,299 cls._server_1) = grpc_debug_test_server.start_server_on_separate_thread(300 dump_to_filesystem=False)301 (cls._server_port_2, cls._debug_server_url_2, _, cls._server_thread_2,302 cls._server_2) = grpc_debug_test_server.start_server_on_separate_thread(303 dump_to_filesystem=False)304 cls._servers_and_threads = [(cls._server_1, cls._server_thread_1),305 (cls._server_2, cls._server_thread_2)]306 @classmethod307 def tearDownClass(cls):308 for server, thread in cls._servers_and_threads:309 server.stop_server().wait()310 thread.join()311 def tearDown(self):312 ops.reset_default_graph()313 self._server_1.clear_data()314 self._server_2.clear_data()315 def testToggleEnableTwoDebugWatchesNoCrosstalkBetweenDebugNodes(self):316 with session.Session(317 config=session_debug_testlib.no_rewrite_session_config()) as sess:318 v_1 = variables.VariableV1(50.0, name="v_1")319 v_2 = variables.VariableV1(-50.0, name="v_1")320 delta_1 = constant_op.constant(5.0, name="delta_1")321 delta_2 = constant_op.constant(-5.0, name="delta_2")322 inc_v_1 = state_ops.assign_add(v_1, delta_1, name="inc_v_1")323 inc_v_2 = state_ops.assign_add(v_2, delta_2, name="inc_v_2")324 sess.run([v_1.initializer, v_2.initializer])325 run_metadata = config_pb2.RunMetadata()326 run_options = config_pb2.RunOptions(output_partition_graphs=True)327 debug_utils.watch_graph(328 run_options,329 sess.graph,330 debug_ops=["DebugIdentity(gated_grpc=true)",331 "DebugNumericSummary(gated_grpc=true)"],332 debug_urls=[self._debug_server_url_1])333 for i in xrange(4):334 self._server_1.clear_data()335 if i % 2 == 0:336 self._server_1.request_watch("delta_1", 0, "DebugIdentity")337 self._server_1.request_watch("delta_2", 0, "DebugIdentity")338 self._server_1.request_unwatch("delta_1", 0, "DebugNumericSummary")339 self._server_1.request_unwatch("delta_2", 0, "DebugNumericSummary")340 else:341 self._server_1.request_unwatch("delta_1", 0, "DebugIdentity")342 self._server_1.request_unwatch("delta_2", 0, "DebugIdentity")343 self._server_1.request_watch("delta_1", 0, "DebugNumericSummary")344 self._server_1.request_watch("delta_2", 0, "DebugNumericSummary")345 sess.run([inc_v_1, inc_v_2],346 options=run_options, run_metadata=run_metadata)347 # Watched debug tensors are:348 # Run 0: delta_[1,2]:0:DebugIdentity349 # Run 1: delta_[1,2]:0:DebugNumericSummary350 # Run 2: delta_[1,2]:0:DebugIdentity351 # Run 3: delta_[1,2]:0:DebugNumericSummary352 self.assertEqual(2, len(self._server_1.debug_tensor_values))353 if i % 2 == 0:354 self.assertAllClose(355 [5.0],356 self._server_1.debug_tensor_values["delta_1:0:DebugIdentity"])357 self.assertAllClose(358 [-5.0],359 self._server_1.debug_tensor_values["delta_2:0:DebugIdentity"])360 else:361 self.assertAllClose(362 [[1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 5.0, 5.0, 5.0,363 0.0, 1.0, 0.0]],364 self._server_1.debug_tensor_values[365 "delta_1:0:DebugNumericSummary"])366 self.assertAllClose(367 [[1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -5.0, -5.0, -5.0,368 0.0, 1.0, 0.0]],369 self._server_1.debug_tensor_values[370 "delta_2:0:DebugNumericSummary"])371 def testToggleWatchesOnCoreMetadata(self):372 (_, debug_server_url, _, server_thread,373 server) = grpc_debug_test_server.start_server_on_separate_thread(374 dump_to_filesystem=False,375 toggle_watch_on_core_metadata=[("toggled_1", 0, "DebugIdentity"),376 ("toggled_2", 0, "DebugIdentity")])377 self._servers_and_threads.append((server, server_thread))378 with session.Session(379 config=session_debug_testlib.no_rewrite_session_config()) as sess:380 v_1 = variables.VariableV1(50.0, name="v_1")381 v_2 = variables.VariableV1(-50.0, name="v_1")382 # These two nodes have names that match those in the383 # toggle_watch_on_core_metadata argument used when calling384 # start_server_on_separate_thread().385 toggled_1 = constant_op.constant(5.0, name="toggled_1")386 toggled_2 = constant_op.constant(-5.0, name="toggled_2")387 inc_v_1 = state_ops.assign_add(v_1, toggled_1, name="inc_v_1")388 inc_v_2 = state_ops.assign_add(v_2, toggled_2, name="inc_v_2")389 sess.run([v_1.initializer, v_2.initializer])390 run_metadata = config_pb2.RunMetadata()391 run_options = config_pb2.RunOptions(output_partition_graphs=True)392 debug_utils.watch_graph(393 run_options,394 sess.graph,395 debug_ops=["DebugIdentity(gated_grpc=true)"],396 debug_urls=[debug_server_url])397 for i in xrange(4):398 server.clear_data()399 sess.run([inc_v_1, inc_v_2],400 options=run_options, run_metadata=run_metadata)401 if i % 2 == 0:402 self.assertEqual(2, len(server.debug_tensor_values))403 self.assertAllClose(404 [5.0],405 server.debug_tensor_values["toggled_1:0:DebugIdentity"])406 self.assertAllClose(407 [-5.0],408 server.debug_tensor_values["toggled_2:0:DebugIdentity"])409 else:410 self.assertEqual(0, len(server.debug_tensor_values))411 def testToggleEnableTwoDebugWatchesNoCrosstalkBetweenServers(self):412 with session.Session(413 config=session_debug_testlib.no_rewrite_session_config()) as sess:414 v = variables.VariableV1(50.0, name="v")415 delta = constant_op.constant(5.0, name="delta")416 inc_v = state_ops.assign_add(v, delta, name="inc_v")417 sess.run(v.initializer)418 run_metadata = config_pb2.RunMetadata()419 run_options = config_pb2.RunOptions(output_partition_graphs=True)420 debug_utils.watch_graph(421 run_options,422 sess.graph,423 debug_ops=["DebugIdentity(gated_grpc=true)"],424 debug_urls=[self._debug_server_url_1, self._debug_server_url_2])425 for i in xrange(4):426 self._server_1.clear_data()427 self._server_2.clear_data()428 if i % 2 == 0:429 self._server_1.request_watch("delta", 0, "DebugIdentity")430 self._server_2.request_watch("v", 0, "DebugIdentity")431 else:432 self._server_1.request_unwatch("delta", 0, "DebugIdentity")433 self._server_2.request_unwatch("v", 0, "DebugIdentity")434 sess.run(inc_v, options=run_options, run_metadata=run_metadata)435 if i % 2 == 0:436 self.assertEqual(1, len(self._server_1.debug_tensor_values))437 self.assertEqual(1, len(self._server_2.debug_tensor_values))438 self.assertAllClose(439 [5.0],440 self._server_1.debug_tensor_values["delta:0:DebugIdentity"])441 self.assertAllClose(442 [50 + 5.0 * i],443 self._server_2.debug_tensor_values["v:0:DebugIdentity"])444 else:445 self.assertEqual(0, len(self._server_1.debug_tensor_values))446 self.assertEqual(0, len(self._server_2.debug_tensor_values))447 def testToggleBreakpointsWorks(self):448 with session.Session(449 config=session_debug_testlib.no_rewrite_session_config()) as sess:450 v_1 = variables.VariableV1(50.0, name="v_1")451 v_2 = variables.VariableV1(-50.0, name="v_2")452 delta_1 = constant_op.constant(5.0, name="delta_1")453 delta_2 = constant_op.constant(-5.0, name="delta_2")454 inc_v_1 = state_ops.assign_add(v_1, delta_1, name="inc_v_1")455 inc_v_2 = state_ops.assign_add(v_2, delta_2, name="inc_v_2")456 sess.run([v_1.initializer, v_2.initializer])457 run_metadata = config_pb2.RunMetadata()458 run_options = config_pb2.RunOptions(output_partition_graphs=True)459 debug_utils.watch_graph(460 run_options,461 sess.graph,462 debug_ops=["DebugIdentity(gated_grpc=true)"],463 debug_urls=[self._debug_server_url_1])464 for i in xrange(4):465 self._server_1.clear_data()466 if i in (0, 2):467 # Enable breakpoint at delta_[1,2]:0:DebugIdentity in runs 0 and 2.468 self._server_1.request_watch(469 "delta_1", 0, "DebugIdentity", breakpoint=True)470 self._server_1.request_watch(471 "delta_2", 0, "DebugIdentity", breakpoint=True)472 else:473 # Disable the breakpoint in runs 1 and 3.474 self._server_1.request_unwatch("delta_1", 0, "DebugIdentity")475 self._server_1.request_unwatch("delta_2", 0, "DebugIdentity")476 output = sess.run([inc_v_1, inc_v_2],477 options=run_options, run_metadata=run_metadata)478 self.assertAllClose([50.0 + 5.0 * (i + 1), -50 - 5.0 * (i + 1)], output)479 if i in (0, 2):480 # During runs 0 and 2, the server should have received the published481 # debug tensor delta:0:DebugIdentity. The breakpoint should have been482 # unblocked by EventReply responses from the server.483 self.assertAllClose(484 [5.0],485 self._server_1.debug_tensor_values["delta_1:0:DebugIdentity"])486 self.assertAllClose(487 [-5.0],488 self._server_1.debug_tensor_values["delta_2:0:DebugIdentity"])489 # After the runs, the server should have properly registered the490 # breakpoints due to the request_unwatch calls.491 self.assertSetEqual({("delta_1", 0, "DebugIdentity"),492 ("delta_2", 0, "DebugIdentity")},493 self._server_1.breakpoints)494 else:495 # After the end of runs 1 and 3, the server has received the requests496 # to disable the breakpoint at delta:0:DebugIdentity.497 self.assertSetEqual(set(), self._server_1.breakpoints)498 def testTensorBoardDebuggerWrapperToggleBreakpointsWorks(self):499 with session.Session(500 config=session_debug_testlib.no_rewrite_session_config()) as sess:501 v_1 = variables.VariableV1(50.0, name="v_1")502 v_2 = variables.VariableV1(-50.0, name="v_2")503 delta_1 = constant_op.constant(5.0, name="delta_1")504 delta_2 = constant_op.constant(-5.0, name="delta_2")505 inc_v_1 = state_ops.assign_add(v_1, delta_1, name="inc_v_1")506 inc_v_2 = state_ops.assign_add(v_2, delta_2, name="inc_v_2")507 sess.run([v_1.initializer, v_2.initializer])508 # The TensorBoardDebugWrapperSession should add a DebugIdentity debug op509 # with attribute gated_grpc=True for every tensor in the graph.510 sess = grpc_wrapper.TensorBoardDebugWrapperSession(511 sess, self._debug_server_url_1)512 for i in xrange(4):513 self._server_1.clear_data()514 if i in (0, 2):515 # Enable breakpoint at delta_[1,2]:0:DebugIdentity in runs 0 and 2.516 self._server_1.request_watch(517 "delta_1", 0, "DebugIdentity", breakpoint=True)518 self._server_1.request_watch(519 "delta_2", 0, "DebugIdentity", breakpoint=True)520 else:521 # Disable the breakpoint in runs 1 and 3.522 self._server_1.request_unwatch("delta_1", 0, "DebugIdentity")523 self._server_1.request_unwatch("delta_2", 0, "DebugIdentity")524 output = sess.run([inc_v_1, inc_v_2])525 self.assertAllClose([50.0 + 5.0 * (i + 1), -50 - 5.0 * (i + 1)], output)526 if i in (0, 2):527 # During runs 0 and 2, the server should have received the published528 # debug tensor delta:0:DebugIdentity. The breakpoint should have been529 # unblocked by EventReply responses from the server.530 self.assertAllClose(531 [5.0],532 self._server_1.debug_tensor_values["delta_1:0:DebugIdentity"])533 self.assertAllClose(534 [-5.0],535 self._server_1.debug_tensor_values["delta_2:0:DebugIdentity"])536 # After the runs, the server should have properly registered the537 # breakpoints.538 else:539 # After the end of runs 1 and 3, the server has received the requests540 # to disable the breakpoint at delta:0:DebugIdentity.541 self.assertSetEqual(set(), self._server_1.breakpoints)542 if i == 0:543 # Check that the server has received the stack trace.544 self.assertTrue(self._server_1.query_op_traceback("delta_1"))545 self.assertTrue(self._server_1.query_op_traceback("delta_2"))546 self.assertTrue(self._server_1.query_op_traceback("inc_v_1"))547 self.assertTrue(self._server_1.query_op_traceback("inc_v_2"))548 # Check that the server has received the python file content.549 # Query an arbitrary line to make sure that is the case.550 with open(__file__, "rt") as this_source_file:551 first_line = this_source_file.readline().strip()552 self.assertEqual(553 first_line, self._server_1.query_source_file_line(__file__, 1))554 else:555 # In later Session.run() calls, the traceback shouldn't have been sent556 # because it is already sent in the 1st call. So calling557 # query_op_traceback() should lead to an exception, because the test558 # debug server clears the data at the beginning of every iteration.559 with self.assertRaises(ValueError):560 self._server_1.query_op_traceback("delta_1")561 with self.assertRaises(ValueError):562 self._server_1.query_source_file_line(__file__, 1)563 def testTensorBoardDebuggerWrapperDisablingTracebackSourceSendingWorks(self):564 with session.Session(565 config=session_debug_testlib.no_rewrite_session_config()) as sess:566 v_1 = variables.VariableV1(50.0, name="v_1")567 v_2 = variables.VariableV1(-50.0, name="v_2")568 delta_1 = constant_op.constant(5.0, name="delta_1")569 delta_2 = constant_op.constant(-5.0, name="delta_2")570 inc_v_1 = state_ops.assign_add(v_1, delta_1, name="inc_v_1")571 inc_v_2 = state_ops.assign_add(v_2, delta_2, name="inc_v_2")572 sess.run(variables.global_variables_initializer())573 # Disable the sending of traceback and source code.574 sess = grpc_wrapper.TensorBoardDebugWrapperSession(575 sess, self._debug_server_url_1, send_traceback_and_source_code=False)576 for i in xrange(4):577 self._server_1.clear_data()578 if i == 0:579 self._server_1.request_watch(580 "delta_1", 0, "DebugIdentity", breakpoint=True)581 output = sess.run([inc_v_1, inc_v_2])582 self.assertAllClose([50.0 + 5.0 * (i + 1), -50 - 5.0 * (i + 1)], output)583 # No op traceback or source code should have been received by the debug584 # server due to the disabling above.585 with self.assertRaisesRegexp(586 ValueError, r"Op .*delta_1.* does not exist"):587 self.assertTrue(self._server_1.query_op_traceback("delta_1"))588 with self.assertRaisesRegexp(589 ValueError, r".* has not received any source file"):590 self._server_1.query_source_file_line(__file__, 1)591 def testGetGrpcDebugWatchesReturnsCorrectAnswer(self):592 with session.Session() as sess:593 v = variables.VariableV1(50.0, name="v")594 delta = constant_op.constant(5.0, name="delta")595 inc_v = state_ops.assign_add(v, delta, name="inc_v")596 sess.run(v.initializer)597 # Before any debugged runs, the server should be aware of no debug598 # watches.599 self.assertEqual([], self._server_1.gated_grpc_debug_watches())600 run_metadata = config_pb2.RunMetadata()601 run_options = config_pb2.RunOptions(output_partition_graphs=True)602 debug_utils.add_debug_tensor_watch(603 run_options, "delta", output_slot=0,604 debug_ops=["DebugNumericSummary(gated_grpc=true)"],605 debug_urls=[self._debug_server_url_1])606 debug_utils.add_debug_tensor_watch(607 run_options, "v", output_slot=0,608 debug_ops=["DebugIdentity"],609 debug_urls=[self._debug_server_url_1])610 sess.run(inc_v, options=run_options, run_metadata=run_metadata)611 # After the first run, the server should have noted the debug watches612 # for which gated_grpc == True, but not the ones with gated_grpc == False.613 self.assertEqual(1, len(self._server_1.gated_grpc_debug_watches()))614 debug_watch = self._server_1.gated_grpc_debug_watches()[0]615 self.assertEqual("delta", debug_watch.node_name)616 self.assertEqual(0, debug_watch.output_slot)617 self.assertEqual("DebugNumericSummary", debug_watch.debug_op)618@test_util.run_v1_only("b/120545219")619class DelayedDebugServerTest(test_util.TensorFlowTestCase):620 def testDebuggedSessionRunWorksWithDelayedDebugServerStartup(self):621 """Test debugged Session.run() tolerates delayed debug server startup."""622 ops.reset_default_graph()623 # Start a debug server asynchronously, with a certain amount of delay.624 (debug_server_port, _, _, server_thread,625 debug_server) = grpc_debug_test_server.start_server_on_separate_thread(626 server_start_delay_sec=2.0, dump_to_filesystem=False)627 with self.cached_session() as sess:628 a_init = constant_op.constant(42.0, name="a_init")629 a = variables.VariableV1(a_init, name="a")630 def watch_fn(fetches, feeds):631 del fetches, feeds632 return framework.WatchOptions(debug_ops=["DebugIdentity"])633 sess = grpc_wrapper.GrpcDebugWrapperSession(634 sess, "localhost:%d" % debug_server_port, watch_fn=watch_fn)635 sess.run(a.initializer)636 self.assertAllClose(637 [42.0], debug_server.debug_tensor_values["a_init:0:DebugIdentity"])638 debug_server.stop_server().wait()639 server_thread.join()640if __name__ == "__main__":...

Full Screen

Full Screen

debug_v2_ops_test.py

Source:debug_v2_ops_test.py Github

copy

Full Screen

1# Copyright 2019 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Test for the internal ops used by tfdbg v2."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19import os20import numpy as np21from tensorflow.core.protobuf import debug_event_pb222from tensorflow.python.debug.lib import debug_events_reader23from tensorflow.python.debug.lib import debug_events_writer24from tensorflow.python.debug.lib import dumping_callback_test_lib25from tensorflow.python.eager import def_function26from tensorflow.python.framework import constant_op27from tensorflow.python.framework import dtypes28from tensorflow.python.framework import errors29from tensorflow.python.framework import ops30from tensorflow.python.framework import tensor_util31from tensorflow.python.framework import test_util32from tensorflow.python.ops import gen_debug_ops33from tensorflow.python.ops import math_ops34from tensorflow.python.platform import googletest35class DebugIdentityV2OpTest(dumping_callback_test_lib.DumpingCallbackTestBase):36 def setUp(self):37 super(DebugIdentityV2OpTest, self).setUp()38 # Testing using a small circular-buffer size.39 self.circular_buffer_size = 440 self.writer = debug_events_writer.DebugEventsWriter(41 self.dump_root, self.circular_buffer_size)42 def tearDown(self):43 self.writer.Close()44 super(DebugIdentityV2OpTest, self).tearDown()45 @test_util.run_in_graph_and_eager_modes46 def testSingleTensorFullTensorDebugModeWithCircularBufferBehavior(self):47 @def_function.function48 def write_debug_trace(x):49 # DebugIdentityV2 is a stateful op. It ought to be included by auto50 # control dependency.51 square = math_ops.square(x)52 gen_debug_ops.debug_identity_v2(53 square,54 tfdbg_context_id="deadbeaf",55 op_name="Square",56 output_slot=0,57 tensor_debug_mode=debug_event_pb2.TensorDebugMode.FULL_TENSOR,58 debug_urls=["file://%s" % self.dump_root])59 sqrt = math_ops.sqrt(x)60 gen_debug_ops.debug_identity_v2(61 sqrt,62 tfdbg_context_id="beafdead",63 op_name="Sqrt",64 output_slot=0,65 tensor_debug_mode=debug_event_pb2.TensorDebugMode.FULL_TENSOR,66 debug_urls=["file://%s" % self.dump_root])67 return square + sqrt68 x = np.array([3.0, 4.0])69 # Only the graph-execution trace of the last iteration should be written70 # to self.dump_root.71 for _ in range(self.circular_buffer_size // 2 + 1):72 self.assertAllClose(73 write_debug_trace(x), [9.0 + np.sqrt(3.0), 16.0 + 2.0])74 with debug_events_reader.DebugEventsReader(self.dump_root) as reader:75 metadata_iter = reader.metadata_iterator()76 # Check that the .metadata DebugEvents data file has been created, even77 # before FlushExecutionFiles() is called.78 debug_event = next(metadata_iter).debug_event79 self.assertGreater(debug_event.wall_time, 0)80 self.assertTrue(debug_event.debug_metadata.tensorflow_version)81 self.assertTrue(82 debug_event.debug_metadata.file_version.startswith("debug.Event:"))83 graph_trace_iter = reader.graph_execution_traces_iterator()84 # Before FlushExecutionFiles() is called, the .graph_execution_traces file85 # ought to be empty.86 with self.assertRaises(StopIteration):87 next(graph_trace_iter)88 # Flush the circular buffer.89 self.writer.FlushExecutionFiles()90 graph_trace_iter = reader.graph_execution_traces_iterator()91 # The circular buffer has a size of 4. So only the data from the92 # last two iterations should have been written to self.dump_root.93 for _ in range(2):94 debug_event = next(graph_trace_iter).debug_event95 self.assertGreater(debug_event.wall_time, 0)96 trace = debug_event.graph_execution_trace97 self.assertEqual(trace.tfdbg_context_id, "deadbeaf")98 self.assertEqual(trace.op_name, "Square")99 self.assertEqual(trace.output_slot, 0)100 self.assertEqual(trace.tensor_debug_mode,101 debug_event_pb2.TensorDebugMode.FULL_TENSOR)102 tensor_value = tensor_util.MakeNdarray(trace.tensor_proto)103 self.assertAllClose(tensor_value, [9.0, 16.0])104 debug_event = next(graph_trace_iter).debug_event105 self.assertGreater(debug_event.wall_time, 0)106 trace = debug_event.graph_execution_trace107 self.assertEqual(trace.tfdbg_context_id, "beafdead")108 self.assertEqual(trace.op_name, "Sqrt")109 self.assertEqual(trace.output_slot, 0)110 self.assertEqual(trace.tensor_debug_mode,111 debug_event_pb2.TensorDebugMode.FULL_TENSOR)112 tensor_value = tensor_util.MakeNdarray(trace.tensor_proto)113 self.assertAllClose(tensor_value, [np.sqrt(3.0), 2.0])114 # Only the graph-execution trace of the last iteration should be written115 # to self.dump_root.116 with self.assertRaises(StopIteration):117 next(graph_trace_iter)118 @test_util.run_in_graph_and_eager_modes119 def testControlFlow(self):120 @def_function.function121 def collatz(x):122 counter = constant_op.constant(0, dtype=dtypes.int32)123 while math_ops.greater(x, 1):124 counter = counter + 1125 gen_debug_ops.debug_identity_v2(126 x,127 tfdbg_context_id="deadbeaf",128 op_name="x",129 output_slot=0,130 tensor_debug_mode=debug_event_pb2.TensorDebugMode.FULL_TENSOR,131 debug_urls=["file://%s" % self.dump_root])132 if math_ops.equal(x % 2, 0):133 x = math_ops.div(x, 2)134 else:135 x = x * 3 + 1136 return counter137 x = constant_op.constant(10, dtype=dtypes.int32)138 self.evaluate(collatz(x))139 self.writer.FlushExecutionFiles()140 with debug_events_reader.DebugEventsReader(self.dump_root) as reader:141 graph_trace_iter = reader.graph_execution_traces_iterator()142 try:143 x_values = []144 timestamp = 0145 while True:146 debug_event = next(graph_trace_iter).debug_event147 self.assertGreater(debug_event.wall_time, timestamp)148 timestamp = debug_event.wall_time149 trace = debug_event.graph_execution_trace150 self.assertEqual(trace.tfdbg_context_id, "deadbeaf")151 self.assertEqual(trace.op_name, "x")152 self.assertEqual(trace.output_slot, 0)153 self.assertEqual(trace.tensor_debug_mode,154 debug_event_pb2.TensorDebugMode.FULL_TENSOR)155 x_values.append(int(tensor_util.MakeNdarray(trace.tensor_proto)))156 except StopIteration:157 pass158 # Due to the circular buffer, only the last 4 iterations of159 # [10, 5, 16, 8, 4, 2] should have been written.160 self.assertAllEqual(x_values, [16, 8, 4, 2])161 @test_util.run_in_graph_and_eager_modes162 def testTwoDumpRoots(self):163 another_dump_root = os.path.join(self.dump_root, "another")164 another_debug_url = "file://%s" % another_dump_root165 another_writer = debug_events_writer.DebugEventsWriter(another_dump_root)166 @def_function.function167 def write_debug_trace(x):168 # DebugIdentityV2 is a stateful op. It ought to be included by auto169 # control dependency.170 square = math_ops.square(x)171 gen_debug_ops.debug_identity_v2(172 square,173 tfdbg_context_id="deadbeaf",174 tensor_debug_mode=debug_event_pb2.TensorDebugMode.FULL_TENSOR,175 debug_urls=["file://%s" % self.dump_root, another_debug_url])176 return square + 1.0177 x = np.array([3.0, 4.0])178 self.assertAllClose(write_debug_trace(x), np.array([10.0, 17.0]))179 self.writer.FlushExecutionFiles()180 another_writer.FlushExecutionFiles()181 another_writer.Close()182 for debug_root in (self.dump_root, another_dump_root):183 with debug_events_reader.DebugEventsReader(debug_root) as reader:184 graph_trace_iter = reader.graph_execution_traces_iterator()185 debug_event = next(graph_trace_iter).debug_event186 trace = debug_event.graph_execution_trace187 self.assertEqual(trace.tfdbg_context_id, "deadbeaf")188 self.assertEqual(trace.op_name, "")189 self.assertEqual(trace.tensor_debug_mode,190 debug_event_pb2.TensorDebugMode.FULL_TENSOR)191 tensor_value = tensor_util.MakeNdarray(trace.tensor_proto)192 self.assertAllClose(tensor_value, [9.0, 16.0])193 with self.assertRaises(StopIteration):194 next(graph_trace_iter)195 @test_util.run_in_graph_and_eager_modes196 def testDebugNumericSummaryV2OpReduceInfNanThreeSlots(self):197 def debug_summary(x):198 return self.evaluate(gen_debug_ops.debug_numeric_summary_v2(199 x, tensor_debug_mode=(200 debug_event_pb2.TensorDebugMode.REDUCE_INF_NAN_THREE_SLOTS)))201 self.assertAllEqual(202 debug_summary(constant_op.constant([])), [0.0, 0.0, 0.0])203 self.assertAllEqual(204 debug_summary(constant_op.constant(42.0)), [0.0, 0.0, 0.0])205 self.assertAllEqual(206 debug_summary(constant_op.constant([3.0, 4.0])), [0.0, 0.0, 0.0])207 self.assertAllEqual(208 debug_summary(constant_op.constant(np.array([3.0, -np.inf]))),209 [-np.inf, 0.0, 0.0])210 self.assertAllEqual(211 debug_summary(constant_op.constant(np.array([[0, 0], [np.nan, 0]]))),212 [0.0, 0.0, np.nan])213 self.assertAllEqual(214 debug_summary(215 constant_op.constant(np.array([[0, 0], [np.nan, np.inf]]))),216 [0.0, np.inf, np.nan])217 self.assertAllEqual(218 debug_summary(219 constant_op.constant(np.array([[0, np.inf], [np.nan, -np.inf]]))),220 [-np.inf, np.inf, np.nan])221 x = np.zeros([100, 100], dtype=np.float16)222 x[32, 47] = np.nan223 self.assertAllEqual(224 debug_summary(constant_op.constant(x)), [0.0, 0.0, np.nan])225 x = np.zeros([97, 97], dtype=np.float32)226 x[50, 83] = -np.inf227 self.assertAllEqual(228 debug_summary(constant_op.constant(x)), [-np.inf, 0.0, 0.0])229 x[1, 41] = np.nan230 self.assertAllEqual(231 debug_summary(constant_op.constant(x)), [-np.inf, 0.0, np.nan])232 x = np.zeros([9701], dtype=np.float64)233 x[9700] = np.nan234 self.assertAllEqual(235 debug_summary(constant_op.constant(x)), [0.0, 0.0, np.nan])236 @test_util.run_in_graph_and_eager_modes237 def testDebugNumericSummaryV2OpLargeTensorIDError(self):238 modes = [239 debug_event_pb2.TensorDebugMode.CURT_HEALTH,240 debug_event_pb2.TensorDebugMode.CONCISE_HEALTH,241 debug_event_pb2.TensorDebugMode.SHAPE,242 ]243 # Maximum allowed tensor_id244 tensor_id = np.power(2, 53)245 for mode in modes:246 self.evaluate(247 gen_debug_ops.debug_numeric_summary_v2(248 constant_op.constant(42.0),249 tensor_debug_mode=mode,250 tensor_id=tensor_id,251 output_dtype=dtypes.float64))252 # Incrementing by one should error253 tensor_id += 1254 for mode in modes:255 with self.assertRaises(errors.InvalidArgumentError):256 self.evaluate(257 gen_debug_ops.debug_numeric_summary_v2(258 constant_op.constant(42.0),259 tensor_debug_mode=mode,260 tensor_id=tensor_id,261 output_dtype=dtypes.float64))262 @test_util.run_in_graph_and_eager_modes263 def testDebugNumericSummaryV2OpCurtHealthValuesSmall(self):264 def debug_summary(x):265 return self.evaluate(266 gen_debug_ops.debug_numeric_summary_v2(267 x,268 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.CURT_HEALTH),269 tensor_id=x._id,270 output_dtype=dtypes.float64)), x._id271 tensor, tensor_id = debug_summary(constant_op.constant([]))272 self.assertAllEqual(tensor, [tensor_id, 0.0])273 tensor, tensor_id = debug_summary(constant_op.constant(42.0))274 self.assertAllEqual(tensor, [tensor_id, 0.0])275 tensor, tensor_id = debug_summary(constant_op.constant([3.0, 4.0]))276 self.assertAllEqual(tensor, [tensor_id, 0.0])277 tensor, tensor_id = debug_summary(278 constant_op.constant(np.array([3.0, -np.inf])))279 self.assertAllEqual(tensor, [tensor_id, 1.0])280 tensor, tensor_id = debug_summary(281 constant_op.constant(np.array([[0, 0], [np.nan, 0]])))282 self.assertAllEqual(tensor, [tensor_id, 1.0])283 tensor, tensor_id = debug_summary(284 constant_op.constant(np.array([[0, 0], [np.nan, np.inf]])))285 self.assertAllEqual(tensor, [tensor_id, 1.0])286 tensor, tensor_id = debug_summary(287 constant_op.constant(np.array([[0, np.inf], [np.nan, -np.inf]])))288 self.assertAllEqual(tensor, [tensor_id, 1.0])289 @test_util.run_in_graph_and_eager_modes290 def testDebugNumericSummaryV2OpCurtHealthValuesLarge(self):291 def debug_summary(x):292 return self.evaluate(293 gen_debug_ops.debug_numeric_summary_v2(294 x,295 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.CURT_HEALTH),296 tensor_id=x._id,297 output_dtype=dtypes.float64)), x._id298 x = np.zeros([100, 100], dtype=np.float16)299 x[32, 47] = np.nan300 tensor, tensor_id = debug_summary(constant_op.constant(x))301 self.assertAllEqual(tensor, [tensor_id, 1.0])302 x = np.zeros([97, 97], dtype=np.float32)303 x[50, 83] = -np.inf304 tensor, tensor_id = debug_summary(constant_op.constant(x))305 self.assertAllEqual(tensor, [tensor_id, 1.0])306 x[1, 41] = np.nan307 tensor, tensor_id = debug_summary(constant_op.constant(x))308 self.assertAllEqual(tensor, [tensor_id, 1.0])309 x = np.zeros([9701], dtype=np.float64)310 x[9700] = np.nan311 tensor, tensor_id = debug_summary(constant_op.constant(x))312 self.assertAllEqual(tensor, [tensor_id, 1.0])313 @test_util.run_in_graph_and_eager_modes314 def testDebugNumericSummaryV2OpCurtHealthConsistency(self):315 def debug_summary(x):316 return self.evaluate(317 gen_debug_ops.debug_numeric_summary_v2(318 x,319 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.CURT_HEALTH),320 tensor_id=x._id,321 output_dtype=dtypes.float64)), x._id322 x = np.zeros([100, 100], dtype=np.float16)323 x[43, 99] = np.nan324 c = constant_op.constant(x)325 tensor_1, tensor_id_1 = debug_summary(c)326 tensor_2, tensor_id_2 = debug_summary(c)327 self.assertAllEqual(tensor_1, tensor_2)328 self.assertEqual(tensor_id_1, tensor_id_2)329 x = np.zeros([100, 100, 50], dtype=np.float64)330 x[0, 0, 1] = np.inf331 c = constant_op.constant(x)332 tensor_1, tensor_id_1 = debug_summary(c)333 tensor_2, tensor_id_2 = debug_summary(c)334 self.assertAllEqual(tensor_1, tensor_2)335 self.assertEqual(tensor_id_1, tensor_id_2)336 c = constant_op.constant(np.ones((100, 200), np.double))337 tensor_1, tensor_id_1 = debug_summary(c)338 tensor_2, tensor_id_2 = debug_summary(c)339 self.assertAllEqual(tensor_1, tensor_2)340 self.assertEqual(tensor_id_1, tensor_id_2)341 @test_util.run_in_graph_and_eager_modes342 def testDebugNumericSummaryV2OpConciseHealthSmall(self):343 def debug_summary(x):344 return self.evaluate(345 gen_debug_ops.debug_numeric_summary_v2(346 x,347 tensor_debug_mode=(348 debug_event_pb2.TensorDebugMode.CONCISE_HEALTH),349 tensor_id=x._id,350 output_dtype=dtypes.float64)), x._id351 tensor, tensor_id = debug_summary(constant_op.constant([]))352 self.assertAllEqual(tensor, [tensor_id, 0.0, 0.0, 0.0, 0.0])353 tensor, tensor_id = debug_summary(constant_op.constant(42.0))354 self.assertAllEqual(tensor, [tensor_id, 1.0, 0.0, 0.0, 0.0])355 tensor, tensor_id = debug_summary(constant_op.constant([3.0, 4.0]))356 self.assertAllEqual(tensor, [tensor_id, 2.0, 0.0, 0.0, 0.0])357 tensor, tensor_id = debug_summary(358 constant_op.constant(np.array([3.0, -np.inf])))359 self.assertAllEqual(tensor, [tensor_id, 2.0, 1.0, 0.0, 0.0])360 tensor, tensor_id = debug_summary(361 constant_op.constant(np.array([[0, 0], [np.nan, 0]])))362 self.assertAllEqual(tensor, [tensor_id, 4.0, 0.0, 0.0, 1.0])363 tensor, tensor_id = debug_summary(364 constant_op.constant(np.array([[0, 0], [np.nan, np.inf]])))365 self.assertAllEqual(tensor, [tensor_id, 4.0, 0.0, 1.0, 1.0])366 tensor, tensor_id = debug_summary(367 constant_op.constant(np.array([[0, np.inf], [np.nan, -np.inf]])))368 self.assertAllEqual(tensor, [tensor_id, 4.0, 1.0, 1.0, 1.0])369 @test_util.run_in_graph_and_eager_modes370 def testDebugNumericSummaryV2OpConciseHealthLarge(self):371 def debug_summary(x):372 return self.evaluate(373 gen_debug_ops.debug_numeric_summary_v2(374 x,375 tensor_debug_mode=(376 debug_event_pb2.TensorDebugMode.CONCISE_HEALTH),377 tensor_id=x._id,378 output_dtype=dtypes.float64)), x._id379 x = np.zeros([100, 100], dtype=np.float16)380 x[32, :] = np.nan381 tensor, tensor_id = debug_summary(constant_op.constant(x))382 self.assertAllEqual(tensor, [tensor_id, 10000.0, 0.0, 0.0, 100.0])383 x = np.zeros([97, 97], dtype=np.float32)384 x[50, 83:85] = -np.inf385 tensor, tensor_id = debug_summary(constant_op.constant(x))386 self.assertAllEqual(tensor, [tensor_id, 97 * 97, 2.0, 0.0, 0.0])387 x[1:9, 41] = np.nan388 tensor, tensor_id = debug_summary(constant_op.constant(x))389 self.assertAllEqual(tensor, [tensor_id, 97 * 97, 2.0, 0.0, 8.0])390 x = np.zeros([9701], dtype=np.float64)391 x[9700] = np.nan392 tensor, tensor_id = debug_summary(constant_op.constant(x))393 self.assertAllEqual(tensor, [tensor_id, 9701, 0.0, 0.0, 1.0])394 @test_util.run_in_graph_and_eager_modes395 def testDebugNumericSummaryV2OpConciseHealthConsistency(self):396 def debug_summary(x):397 return self.evaluate(398 gen_debug_ops.debug_numeric_summary_v2(399 x,400 tensor_debug_mode=(401 debug_event_pb2.TensorDebugMode.CONCISE_HEALTH),402 tensor_id=x._id,403 output_dtype=dtypes.float64)), x._id404 # Assert the same op is returns a consistent value405 x = np.zeros([100, 100], dtype=np.float16)406 x[3, 4] = -np.inf407 c = constant_op.constant(x)408 tensor_1, tensor_id_1 = debug_summary(c)409 tensor_2, tensor_id_2 = debug_summary(c)410 self.assertAllEqual(tensor_1, tensor_2)411 self.assertEqual(tensor_id_1, tensor_id_2)412 c = constant_op.constant(np.ones((100, 200), np.double))413 tensor_1, tensor_id_1 = debug_summary(c)414 tensor_2, tensor_id_2 = debug_summary(c)415 self.assertAllEqual(tensor_1, tensor_2)416 self.assertEqual(tensor_id_1, tensor_id_2)417 @test_util.run_in_graph_and_eager_modes418 def testDebugNumericSummaryV2OpShapeEmpty(self):419 def debug_summary(x):420 return self.evaluate(421 gen_debug_ops.debug_numeric_summary_v2(422 x,423 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.SHAPE),424 tensor_id=x._id,425 output_dtype=dtypes.float64)), x._id426 tensor, tensor_id = debug_summary(constant_op.constant(0.0))427 self.assertAllEqual(428 tensor, [tensor_id, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])429 @test_util.run_in_graph_and_eager_modes430 def testDebugNumericSummaryV2OpShapeSmall(self):431 def debug_summary(x):432 return self.evaluate(433 gen_debug_ops.debug_numeric_summary_v2(434 x,435 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.SHAPE),436 tensor_id=x._id,437 output_dtype=dtypes.float64)), x._id438 x = np.zeros([3, 4], dtype=np.float32)439 tensor, tensor_id = debug_summary(constant_op.constant(x))440 self.assertAllEqual(441 tensor, [tensor_id, 1.0, 2.0, 12.0, 3.0, 4.0, 0.0, 0.0, 0.0, 0.0])442 x = np.ones([1, 2, 3, 4, 5, 6], dtype=np.float16)443 x[0, 1, 2, 2, 2, 2] = np.nan444 tensor, tensor_id = debug_summary(constant_op.constant(x))445 self.assertAllEqual(446 tensor,447 [tensor_id, 19, 6.0, 2 * 3 * 4 * 5 * 6, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])448 x = np.zeros([2], dtype=np.float32)449 tensor, tensor_id = debug_summary(constant_op.constant(x))450 self.assertAllEqual(451 tensor, [tensor_id, 1.0, 1.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0])452 tensor, tensor_id = debug_summary(constant_op.constant([]))453 self.assertAllEqual(454 tensor, [tensor_id, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])455 @test_util.run_in_graph_and_eager_modes456 def testDebugNumericSummaryV2OpShapeLarge(self):457 def debug_summary(x):458 return self.evaluate(459 gen_debug_ops.debug_numeric_summary_v2(460 x,461 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.SHAPE),462 tensor_id=x._id,463 output_dtype=dtypes.float64)), x._id464 x = np.ones([1, 2, 3, 4, 5, 6, 7], dtype=np.double)465 tensor, tensor_id = debug_summary(constant_op.constant(x))466 self.assertAllEqual(tensor, [467 tensor_id, 2.0, 7.0, 2 * 3 * 4 * 5 * 6 * 7, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0468 ])469 @test_util.run_in_graph_and_eager_modes470 def testDebugNumericSummaryV2OpFullHealthSmall(self):471 def debug_summary(x):472 return self.evaluate(473 gen_debug_ops.debug_numeric_summary_v2(474 x,475 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.FULL_HEALTH),476 tensor_id=x._id,477 output_dtype=dtypes.float64)), x._id478 tensor, tensor_id = debug_summary(constant_op.constant([]))479 expected = [tensor_id, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0]480 self.assertAllEqual(tensor, expected)481 tensor, tensor_id = debug_summary(constant_op.constant(42.0))482 expected = [tensor_id, -1, 1, 0, 1, 0, 0, 0, 0, 0, 1]483 self.assertAllEqual(tensor, expected)484 tensor, tensor_id = debug_summary(constant_op.constant([3.0, 4.0]))485 expected = [tensor_id, -1, 1, 1, 2, 0, 0, 0, 0, 0, 2]486 self.assertAllEqual(tensor, expected)487 tensor, tensor_id = debug_summary(488 constant_op.constant(np.array([3, -np.inf], dtype=np.float32)))489 expected = [tensor_id, -1, 1, 1, 2, 1, 0, 0, 0, 0, 1]490 self.assertAllEqual(tensor, expected)491 tensor, tensor_id = debug_summary(492 constant_op.constant(np.array([[0, 0], [np.nan, 0]], dtype=np.float64)))493 expected = [tensor_id, -1, 2, 2, 4, 0, 0, 1, 0, 3, 0]494 self.assertAllEqual(tensor, expected)495 tensor, tensor_id = debug_summary(496 constant_op.constant(497 np.array([[0, 0], [np.nan, np.inf]], dtype=np.float16)))498 expected = [tensor_id, -1, 19, 2, 4, 0, 1, 1, 0, 2, 0]499 self.assertAllEqual(tensor, expected)500 tensor, tensor_id = debug_summary(501 constant_op.constant(502 np.array([[0, np.inf], [np.nan, -np.inf]], dtype=np.float32)))503 expected = [tensor_id, -1, 1, 2, 4, 1, 1, 1, 0, 1, 0]504 self.assertAllEqual(tensor, expected)505 @test_util.run_in_graph_and_eager_modes506 def testDebugNumericSummaryV2OpFullHealthLarge(self):507 def debug_summary(x):508 return self.evaluate(509 gen_debug_ops.debug_numeric_summary_v2(510 x,511 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.FULL_HEALTH),512 tensor_id=x._id,513 output_dtype=dtypes.float64)), x._id514 def tensor_counts(arr):515 counts = [len(np.shape(arr)), np.size(arr), 0, 0, 0, 0, 0, 0]516 for n in np.ravel(arr):517 if np.isneginf(n):518 counts[2] += 1519 elif np.isposinf(n):520 counts[3] += 1521 elif np.isnan(n):522 counts[4] += 1523 elif n < 0.:524 counts[5] += 1525 elif n == 0.:526 counts[6] += 1527 else:528 counts[7] += 1529 return counts530 x = np.zeros([50, 50], dtype=np.float16)531 x[32, 47] = np.nan532 x[0:4, 3] = np.inf533 x[40:50, 40:50] = 10534 x[3, 20] = -10535 tensor, tensor_id = debug_summary(constant_op.constant(x))536 expected = [tensor_id, -1, 19] + tensor_counts(x)537 self.assertAllEqual(tensor, expected)538 x = np.ones([25, 25, 50], dtype=np.float32) * np.inf539 x[:, :, 1] = np.nan540 x[:, :, 2] = -np.inf541 x[:, :, 3] = -1542 x[:, :, 4] = 0543 x[:, :, 5] = 1544 tensor, tensor_id = debug_summary(constant_op.constant(x))545 expected = [tensor_id, -1, 1] + tensor_counts(x)546 self.assertAllEqual(tensor, expected)547 x[0, 0, 0] = np.nan548 tensor, tensor_id = debug_summary(constant_op.constant(x))549 expected = [tensor_id, -1, 1,] + tensor_counts(x)550 self.assertAllEqual(tensor, expected)551 x = np.zeros([9701], dtype=np.float64)552 x[9700] = np.nan553 tensor, tensor_id = debug_summary(constant_op.constant(x))554 expected = [tensor_id, -1, 2] + tensor_counts(x)555 self.assertAllEqual(tensor, expected)556 @test_util.run_in_graph_and_eager_modes557 def testDebugNumericSummaryV2OpFullHealthConsistency(self):558 def debug_summary(x):559 return self.evaluate(560 gen_debug_ops.debug_numeric_summary_v2(561 x,562 tensor_debug_mode=(debug_event_pb2.TensorDebugMode.FULL_HEALTH),563 tensor_id=x._id,564 output_dtype=dtypes.float64)), x._id565 # Assert the same op is returns a consistent value566 x = np.zeros([100, 100], dtype=np.float16)567 x[32, 47] = np.nan568 x[0:4, 3] = np.inf569 x[90:100, 90:100] = 10570 x[3, 20] = -10571 c = constant_op.constant(x)572 tensor_1, tensor_id_1 = debug_summary(c)573 tensor_2, tensor_id_2 = debug_summary(c)574 self.assertAllEqual(tensor_1, tensor_2)575 self.assertEqual(tensor_id_1, tensor_id_2)576 x = np.ones((100, 200, 3, 10), np.double)577 x[1, 30, 2] = 10578 x[5, :, 0, 1] = np.nan579 x[90:100, 150, :, :] = np.inf580 c = constant_op.constant(x)581 tensor_1, tensor_id_1 = debug_summary(c)582 tensor_2, tensor_id_2 = debug_summary(c)583 self.assertAllEqual(tensor_1, tensor_2)584 self.assertEqual(tensor_id_1, tensor_id_2)585if __name__ == "__main__":586 ops.enable_eager_execution()...

Full Screen

Full Screen

debug_utils_test.py

Source:debug_utils_test.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Tests for TensorFlow Debugger (tfdbg) Utilities."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19import numpy as np20from tensorflow.core.protobuf import config_pb221from tensorflow.python.client import session22from tensorflow.python.debug.lib import debug_utils23from tensorflow.python.framework import constant_op24from tensorflow.python.framework import test_util25from tensorflow.python.ops import math_ops26# Import resource_variable_ops for the variables-to-tensor implicit conversion.27from tensorflow.python.ops import resource_variable_ops # pylint: disable=unused-import28from tensorflow.python.ops import variables29from tensorflow.python.platform import googletest30class DebugUtilsTest(test_util.TensorFlowTestCase):31 @classmethod32 def setUpClass(cls):33 cls._sess = session.Session()34 with cls._sess:35 cls._a_init_val = np.array([[5.0, 3.0], [-1.0, 0.0]])36 cls._b_init_val = np.array([[2.0], [-1.0]])37 cls._c_val = np.array([[-4.0], [np.nan]])38 cls._a_init = constant_op.constant(39 cls._a_init_val, shape=[2, 2], name="a1_init")40 cls._b_init = constant_op.constant(41 cls._b_init_val, shape=[2, 1], name="b_init")42 cls._a = variables.VariableV1(cls._a_init, name="a1")43 cls._b = variables.VariableV1(cls._b_init, name="b")44 cls._c = constant_op.constant(cls._c_val, shape=[2, 1], name="c")45 # Matrix product of a and b.46 cls._p = math_ops.matmul(cls._a, cls._b, name="p1")47 # Sum of two vectors.48 cls._s = math_ops.add(cls._p, cls._c, name="s")49 cls._graph = cls._sess.graph50 # These are all the expected nodes in the graph:51 # - Two variables (a, b), each with four nodes (Variable, init, Assign,52 # read).53 # - One constant (c).54 # - One add operation and one matmul operation.55 # - One wildcard node name ("*") that covers nodes created internally56 # by TensorFlow itself (e.g., Grappler).57 cls._expected_num_nodes = 4 * 2 + 1 + 1 + 1 + 158 def setUp(self):59 self._run_options = config_pb2.RunOptions()60 def _verify_watches(self, watch_opts, expected_output_slot,61 expected_debug_ops, expected_debug_urls):62 """Verify a list of debug tensor watches.63 This requires all watches in the watch list have exactly the same64 output_slot, debug_ops and debug_urls.65 Args:66 watch_opts: Repeated protobuf field of DebugTensorWatch.67 expected_output_slot: Expected output slot index, as an integer.68 expected_debug_ops: Expected debug ops, as a list of strings.69 expected_debug_urls: Expected debug URLs, as a list of strings.70 Returns:71 List of node names from the list of debug tensor watches.72 """73 node_names = []74 for watch in watch_opts:75 node_names.append(watch.node_name)76 if watch.node_name == "*":77 self.assertEqual(-1, watch.output_slot)78 self.assertEqual(expected_debug_ops, watch.debug_ops)79 self.assertEqual(expected_debug_urls, watch.debug_urls)80 else:81 self.assertEqual(expected_output_slot, watch.output_slot)82 self.assertEqual(expected_debug_ops, watch.debug_ops)83 self.assertEqual(expected_debug_urls, watch.debug_urls)84 return node_names85 def testAddDebugTensorWatches_defaultDebugOp(self):86 debug_utils.add_debug_tensor_watch(87 self._run_options, "foo/node_a", 1, debug_urls="file:///tmp/tfdbg_1")88 debug_utils.add_debug_tensor_watch(89 self._run_options, "foo/node_b", 0, debug_urls="file:///tmp/tfdbg_2")90 debug_watch_opts = self._run_options.debug_options.debug_tensor_watch_opts91 self.assertEqual(2, len(debug_watch_opts))92 watch_0 = debug_watch_opts[0]93 watch_1 = debug_watch_opts[1]94 self.assertEqual("foo/node_a", watch_0.node_name)95 self.assertEqual(1, watch_0.output_slot)96 self.assertEqual("foo/node_b", watch_1.node_name)97 self.assertEqual(0, watch_1.output_slot)98 # Verify default debug op name.99 self.assertEqual(["DebugIdentity"], watch_0.debug_ops)100 self.assertEqual(["DebugIdentity"], watch_1.debug_ops)101 # Verify debug URLs.102 self.assertEqual(["file:///tmp/tfdbg_1"], watch_0.debug_urls)103 self.assertEqual(["file:///tmp/tfdbg_2"], watch_1.debug_urls)104 def testAddDebugTensorWatches_explicitDebugOp(self):105 debug_utils.add_debug_tensor_watch(106 self._run_options,107 "foo/node_a",108 0,109 debug_ops="DebugNanCount",110 debug_urls="file:///tmp/tfdbg_1")111 debug_watch_opts = self._run_options.debug_options.debug_tensor_watch_opts112 self.assertEqual(1, len(debug_watch_opts))113 watch_0 = debug_watch_opts[0]114 self.assertEqual("foo/node_a", watch_0.node_name)115 self.assertEqual(0, watch_0.output_slot)116 # Verify default debug op name.117 self.assertEqual(["DebugNanCount"], watch_0.debug_ops)118 # Verify debug URLs.119 self.assertEqual(["file:///tmp/tfdbg_1"], watch_0.debug_urls)120 def testAddDebugTensorWatches_multipleDebugOps(self):121 debug_utils.add_debug_tensor_watch(122 self._run_options,123 "foo/node_a",124 0,125 debug_ops=["DebugNanCount", "DebugIdentity"],126 debug_urls="file:///tmp/tfdbg_1")127 debug_watch_opts = self._run_options.debug_options.debug_tensor_watch_opts128 self.assertEqual(1, len(debug_watch_opts))129 watch_0 = debug_watch_opts[0]130 self.assertEqual("foo/node_a", watch_0.node_name)131 self.assertEqual(0, watch_0.output_slot)132 # Verify default debug op name.133 self.assertEqual(["DebugNanCount", "DebugIdentity"], watch_0.debug_ops)134 # Verify debug URLs.135 self.assertEqual(["file:///tmp/tfdbg_1"], watch_0.debug_urls)136 def testAddDebugTensorWatches_multipleURLs(self):137 debug_utils.add_debug_tensor_watch(138 self._run_options,139 "foo/node_a",140 0,141 debug_ops="DebugNanCount",142 debug_urls=["file:///tmp/tfdbg_1", "file:///tmp/tfdbg_2"])143 debug_watch_opts = self._run_options.debug_options.debug_tensor_watch_opts144 self.assertEqual(1, len(debug_watch_opts))145 watch_0 = debug_watch_opts[0]146 self.assertEqual("foo/node_a", watch_0.node_name)147 self.assertEqual(0, watch_0.output_slot)148 # Verify default debug op name.149 self.assertEqual(["DebugNanCount"], watch_0.debug_ops)150 # Verify debug URLs.151 self.assertEqual(["file:///tmp/tfdbg_1", "file:///tmp/tfdbg_2"],152 watch_0.debug_urls)153 @test_util.run_v1_only("b/120545219")154 def testWatchGraph_allNodes(self):155 debug_utils.watch_graph(156 self._run_options,157 self._graph,158 debug_ops=["DebugIdentity", "DebugNanCount"],159 debug_urls="file:///tmp/tfdbg_1")160 debug_watch_opts = self._run_options.debug_options.debug_tensor_watch_opts161 self.assertEqual(self._expected_num_nodes, len(debug_watch_opts))162 # Verify that each of the nodes in the graph with output tensors in the163 # graph have debug tensor watch.164 node_names = self._verify_watches(debug_watch_opts, 0,165 ["DebugIdentity", "DebugNanCount"],166 ["file:///tmp/tfdbg_1"])167 # Verify the node names.168 self.assertIn("a1_init", node_names)169 self.assertIn("a1", node_names)170 self.assertIn("a1/Assign", node_names)171 self.assertIn("a1/read", node_names)172 self.assertIn("b_init", node_names)173 self.assertIn("b", node_names)174 self.assertIn("b/Assign", node_names)175 self.assertIn("b/read", node_names)176 self.assertIn("c", node_names)177 self.assertIn("p1", node_names)178 self.assertIn("s", node_names)179 # Assert that the wildcard node name has been created.180 self.assertIn("*", node_names)181 @test_util.run_v1_only("b/120545219")182 def testWatchGraph_nodeNameWhitelist(self):183 debug_utils.watch_graph(184 self._run_options,185 self._graph,186 debug_urls="file:///tmp/tfdbg_1",187 node_name_regex_whitelist="(a1$|a1_init$|a1/.*|p1$)")188 node_names = self._verify_watches(189 self._run_options.debug_options.debug_tensor_watch_opts, 0,190 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])191 self.assertEqual(192 sorted(["a1_init", "a1", "a1/Assign", "a1/read", "p1"]),193 sorted(node_names))194 @test_util.run_v1_only("b/120545219")195 def testWatchGraph_opTypeWhitelist(self):196 debug_utils.watch_graph(197 self._run_options,198 self._graph,199 debug_urls="file:///tmp/tfdbg_1",200 op_type_regex_whitelist="(Variable|MatMul)")201 node_names = self._verify_watches(202 self._run_options.debug_options.debug_tensor_watch_opts, 0,203 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])204 self.assertEqual(sorted(["a1", "b", "p1"]), sorted(node_names))205 def testWatchGraph_nodeNameAndOpTypeWhitelists(self):206 debug_utils.watch_graph(207 self._run_options,208 self._graph,209 debug_urls="file:///tmp/tfdbg_1",210 node_name_regex_whitelist="([a-z]+1$)",211 op_type_regex_whitelist="(MatMul)")212 node_names = self._verify_watches(213 self._run_options.debug_options.debug_tensor_watch_opts, 0,214 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])215 self.assertEqual(["p1"], node_names)216 @test_util.run_v1_only("b/120545219")217 def testWatchGraph_tensorDTypeWhitelist(self):218 debug_utils.watch_graph(219 self._run_options,220 self._graph,221 debug_urls="file:///tmp/tfdbg_1",222 tensor_dtype_regex_whitelist=".*_ref")223 node_names = self._verify_watches(224 self._run_options.debug_options.debug_tensor_watch_opts, 0,225 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])226 self.assertItemsEqual(["a1", "a1/Assign", "b", "b/Assign"], node_names)227 @test_util.run_v1_only("b/120545219")228 def testWatchGraph_nodeNameAndTensorDTypeWhitelists(self):229 debug_utils.watch_graph(230 self._run_options,231 self._graph,232 debug_urls="file:///tmp/tfdbg_1",233 node_name_regex_whitelist="^a.*",234 tensor_dtype_regex_whitelist=".*_ref")235 node_names = self._verify_watches(236 self._run_options.debug_options.debug_tensor_watch_opts, 0,237 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])238 self.assertItemsEqual(["a1", "a1/Assign"], node_names)239 @test_util.run_v1_only("b/120545219")240 def testWatchGraph_nodeNameBlacklist(self):241 debug_utils.watch_graph_with_blacklists(242 self._run_options,243 self._graph,244 debug_urls="file:///tmp/tfdbg_1",245 node_name_regex_blacklist="(a1$|a1_init$|a1/.*|p1$)")246 node_names = self._verify_watches(247 self._run_options.debug_options.debug_tensor_watch_opts, 0,248 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])249 self.assertEqual(250 sorted(["b_init", "b", "b/Assign", "b/read", "c", "s"]),251 sorted(node_names))252 @test_util.run_v1_only("b/120545219")253 def testWatchGraph_opTypeBlacklist(self):254 debug_utils.watch_graph_with_blacklists(255 self._run_options,256 self._graph,257 debug_urls="file:///tmp/tfdbg_1",258 op_type_regex_blacklist="(Variable|Identity|Assign|Const)")259 node_names = self._verify_watches(260 self._run_options.debug_options.debug_tensor_watch_opts, 0,261 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])262 self.assertEqual(sorted(["p1", "s"]), sorted(node_names))263 @test_util.run_v1_only("b/120545219")264 def testWatchGraph_nodeNameAndOpTypeBlacklists(self):265 debug_utils.watch_graph_with_blacklists(266 self._run_options,267 self._graph,268 debug_urls="file:///tmp/tfdbg_1",269 node_name_regex_blacklist="p1$",270 op_type_regex_blacklist="(Variable|Identity|Assign|Const)")271 node_names = self._verify_watches(272 self._run_options.debug_options.debug_tensor_watch_opts, 0,273 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])274 self.assertEqual(["s"], node_names)275 @test_util.run_v1_only("b/120545219")276 def testWatchGraph_tensorDTypeBlacklists(self):277 debug_utils.watch_graph_with_blacklists(278 self._run_options,279 self._graph,280 debug_urls="file:///tmp/tfdbg_1",281 tensor_dtype_regex_blacklist=".*_ref")282 node_names = self._verify_watches(283 self._run_options.debug_options.debug_tensor_watch_opts, 0,284 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])285 self.assertNotIn("a1", node_names)286 self.assertNotIn("a1/Assign", node_names)287 self.assertNotIn("b", node_names)288 self.assertNotIn("b/Assign", node_names)289 self.assertIn("s", node_names)290 @test_util.run_v1_only("b/120545219")291 def testWatchGraph_nodeNameAndTensorDTypeBlacklists(self):292 debug_utils.watch_graph_with_blacklists(293 self._run_options,294 self._graph,295 debug_urls="file:///tmp/tfdbg_1",296 node_name_regex_blacklist="^s$",297 tensor_dtype_regex_blacklist=".*_ref")298 node_names = self._verify_watches(299 self._run_options.debug_options.debug_tensor_watch_opts, 0,300 ["DebugIdentity"], ["file:///tmp/tfdbg_1"])301 self.assertNotIn("a1", node_names)302 self.assertNotIn("a1/Assign", node_names)303 self.assertNotIn("b", node_names)304 self.assertNotIn("b/Assign", node_names)305 self.assertNotIn("s", node_names)306if __name__ == "__main__":...

Full Screen

Full Screen

debug_utils.py

Source:debug_utils.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""TensorFlow Debugger (tfdbg) Utilities."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19import re20from six.moves import xrange # pylint: disable=redefined-builtin21def add_debug_tensor_watch(run_options,22 node_name,23 output_slot=0,24 debug_ops="DebugIdentity",25 debug_urls=None,26 tolerate_debug_op_creation_failures=False,27 global_step=-1):28 """Add watch on a `Tensor` to `RunOptions`.29 N.B.:30 1. Under certain circumstances, the `Tensor` may not get actually watched31 (e.g., if the node of the `Tensor` is constant-folded during runtime).32 2. For debugging purposes, the `parallel_iteration` attribute of all33 `tf.while_loop`s in the graph are set to 1 to prevent any node from34 being executed multiple times concurrently. This change does not affect35 subsequent non-debugged runs of the same `tf.while_loop`s.36 Args:37 run_options: An instance of `config_pb2.RunOptions` to be modified.38 node_name: (`str`) name of the node to watch.39 output_slot: (`int`) output slot index of the tensor from the watched node.40 debug_ops: (`str` or `list` of `str`) name(s) of the debug op(s). Can be a41 `list` of `str` or a single `str`. The latter case is equivalent to a42 `list` of `str` with only one element.43 For debug op types with customizable attributes, each debug op string can44 optionally contain a list of attribute names, in the syntax of:45 debug_op_name(attr_name_1=attr_value_1;attr_name_2=attr_value_2;...)46 debug_urls: (`str` or `list` of `str`) URL(s) to send debug values to,47 e.g., `file:///tmp/tfdbg_dump_1`, `grpc://localhost:12345`.48 tolerate_debug_op_creation_failures: (`bool`) Whether to tolerate debug op49 creation failures by not throwing exceptions.50 global_step: (`int`) Optional global_step count for this debug tensor51 watch.52 """53 watch_opts = run_options.debug_options.debug_tensor_watch_opts54 run_options.debug_options.global_step = global_step55 watch = watch_opts.add()56 watch.tolerate_debug_op_creation_failures = (57 tolerate_debug_op_creation_failures)58 watch.node_name = node_name59 watch.output_slot = output_slot60 if isinstance(debug_ops, str):61 debug_ops = [debug_ops]62 watch.debug_ops.extend(debug_ops)63 if debug_urls:64 if isinstance(debug_urls, str):65 debug_urls = [debug_urls]66 watch.debug_urls.extend(debug_urls)67def watch_graph(run_options,68 graph,69 debug_ops="DebugIdentity",70 debug_urls=None,71 node_name_regex_whitelist=None,72 op_type_regex_whitelist=None,73 tensor_dtype_regex_whitelist=None,74 tolerate_debug_op_creation_failures=False,75 global_step=-1,76 reset_disk_byte_usage=False):77 """Add debug watches to `RunOptions` for a TensorFlow graph.78 To watch all `Tensor`s on the graph, let both `node_name_regex_whitelist`79 and `op_type_regex_whitelist` be the default (`None`).80 N.B.:81 1. Under certain circumstances, the `Tensor` may not get actually watched82 (e.g., if the node of the `Tensor` is constant-folded during runtime).83 2. For debugging purposes, the `parallel_iteration` attribute of all84 `tf.while_loop`s in the graph are set to 1 to prevent any node from85 being executed multiple times concurrently. This change does not affect86 subsequent non-debugged runs of the same `tf.while_loop`s.87 Args:88 run_options: An instance of `config_pb2.RunOptions` to be modified.89 graph: An instance of `ops.Graph`.90 debug_ops: (`str` or `list` of `str`) name(s) of the debug op(s) to use.91 debug_urls: URLs to send debug values to. Can be a list of strings,92 a single string, or None. The case of a single string is equivalent to93 a list consisting of a single string, e.g., `file:///tmp/tfdbg_dump_1`,94 `grpc://localhost:12345`.95 For debug op types with customizable attributes, each debug op name string96 can optionally contain a list of attribute names, in the syntax of:97 debug_op_name(attr_name_1=attr_value_1;attr_name_2=attr_value_2;...)98 node_name_regex_whitelist: Regular-expression whitelist for node_name,99 e.g., `"(weight_[0-9]+|bias_.*)"`100 op_type_regex_whitelist: Regular-expression whitelist for the op type of101 nodes, e.g., `"(Variable|Add)"`.102 If both `node_name_regex_whitelist` and `op_type_regex_whitelist`103 are set, the two filtering operations will occur in a logical `AND`104 relation. In other words, a node will be included if and only if it105 hits both whitelists.106 tensor_dtype_regex_whitelist: Regular-expression whitelist for Tensor107 data type, e.g., `"^int.*"`.108 This whitelist operates in logical `AND` relations to the two whitelists109 above.110 tolerate_debug_op_creation_failures: (`bool`) whether debug op creation111 failures (e.g., due to dtype incompatibility) are to be tolerated by not112 throwing exceptions.113 global_step: (`int`) Optional global_step count for this debug tensor114 watch.115 reset_disk_byte_usage: (`bool`) whether to reset the tracked disk byte116 usage to zero (default: `False`).117 """118 if not debug_ops:119 raise ValueError("debug_ops must not be empty or None.")120 if not debug_urls:121 raise ValueError("debug_urls must not be empty or None.")122 if isinstance(debug_ops, str):123 debug_ops = [debug_ops]124 node_name_pattern = (re.compile(node_name_regex_whitelist)125 if node_name_regex_whitelist else None)126 op_type_pattern = (re.compile(op_type_regex_whitelist)127 if op_type_regex_whitelist else None)128 tensor_dtype_pattern = (re.compile(tensor_dtype_regex_whitelist)129 if tensor_dtype_regex_whitelist else None)130 ops = graph.get_operations()131 for op in ops:132 # Skip nodes without any output tensors.133 if not op.outputs:134 continue135 node_name = op.name136 op_type = op.type137 if node_name_pattern and not node_name_pattern.match(node_name):138 continue139 if op_type_pattern and not op_type_pattern.match(op_type):140 continue141 for slot in xrange(len(op.outputs)):142 if (tensor_dtype_pattern and143 not tensor_dtype_pattern.match(op.outputs[slot].dtype.name)):144 continue145 add_debug_tensor_watch(146 run_options,147 node_name,148 output_slot=slot,149 debug_ops=debug_ops,150 debug_urls=debug_urls,151 tolerate_debug_op_creation_failures=(152 tolerate_debug_op_creation_failures),153 global_step=global_step)154 # If no filter for node or tensor is used, will add a wildcard node name, so155 # that all nodes, including the ones created internally by TensorFlow itself156 # (e.g., by Grappler), can be watched during debugging.157 use_node_name_wildcard = (not node_name_pattern and158 not op_type_pattern and159 not tensor_dtype_pattern)160 if use_node_name_wildcard:161 add_debug_tensor_watch(162 run_options,163 "*",164 output_slot=-1,165 debug_ops=debug_ops,166 debug_urls=debug_urls,167 tolerate_debug_op_creation_failures=tolerate_debug_op_creation_failures,168 global_step=global_step)169 run_options.debug_options.reset_disk_byte_usage = reset_disk_byte_usage170def watch_graph_with_blacklists(run_options,171 graph,172 debug_ops="DebugIdentity",173 debug_urls=None,174 node_name_regex_blacklist=None,175 op_type_regex_blacklist=None,176 tensor_dtype_regex_blacklist=None,177 tolerate_debug_op_creation_failures=False,178 global_step=-1,179 reset_disk_byte_usage=False):180 """Add debug tensor watches, blacklisting nodes and op types.181 This is similar to `watch_graph()`, but the node names and op types are182 blacklisted, instead of whitelisted.183 N.B.:184 1. Under certain circumstances, the `Tensor` may not get actually watched185 (e.g., if the node of the `Tensor` is constant-folded during runtime).186 2. For debugging purposes, the `parallel_iteration` attribute of all187 `tf.while_loop`s in the graph are set to 1 to prevent any node from188 being executed multiple times concurrently. This change does not affect189 subsequent non-debugged runs of the same `tf.while_loop`s.190 Args:191 run_options: An instance of `config_pb2.RunOptions` to be modified.192 graph: An instance of `ops.Graph`.193 debug_ops: (`str` or `list` of `str`) name(s) of the debug op(s) to use.194 See the documentation of `watch_graph` for more details.195 debug_urls: URL(s) to send debug values to, e.g.,196 `file:///tmp/tfdbg_dump_1`, `grpc://localhost:12345`.197 node_name_regex_blacklist: Regular-expression blacklist for node_name.198 This should be a string, e.g., `"(weight_[0-9]+|bias_.*)"`.199 op_type_regex_blacklist: Regular-expression blacklist for the op type of200 nodes, e.g., `"(Variable|Add)"`.201 If both node_name_regex_blacklist and op_type_regex_blacklist202 are set, the two filtering operations will occur in a logical `OR`203 relation. In other words, a node will be excluded if it hits either of204 the two blacklists; a node will be included if and only if it hits205 neither of the blacklists.206 tensor_dtype_regex_blacklist: Regular-expression blacklist for Tensor207 data type, e.g., `"^int.*"`.208 This blacklist operates in logical `OR` relations to the two whitelists209 above.210 tolerate_debug_op_creation_failures: (`bool`) whether debug op creation211 failures (e.g., due to dtype incompatibility) are to be tolerated by not212 throwing exceptions.213 global_step: (`int`) Optional global_step count for this debug tensor214 watch.215 reset_disk_byte_usage: (`bool`) whether to reset the tracked disk byte216 usage to zero (default: `False`).217 """218 if isinstance(debug_ops, str):219 debug_ops = [debug_ops]220 node_name_pattern = (re.compile(node_name_regex_blacklist) if221 node_name_regex_blacklist else None)222 op_type_pattern = (re.compile(op_type_regex_blacklist) if223 op_type_regex_blacklist else None)224 tensor_dtype_pattern = (re.compile(tensor_dtype_regex_blacklist) if225 tensor_dtype_regex_blacklist else None)226 ops = graph.get_operations()227 for op in ops:228 # Skip nodes without any output tensors.229 if not op.outputs:230 continue231 node_name = op.name232 op_type = op.type233 if node_name_pattern and node_name_pattern.match(node_name):234 continue235 if op_type_pattern and op_type_pattern.match(op_type):236 continue237 for slot in xrange(len(op.outputs)):238 if (tensor_dtype_pattern and239 tensor_dtype_pattern.match(op.outputs[slot].dtype.name)):240 continue241 add_debug_tensor_watch(242 run_options,243 node_name,244 output_slot=slot,245 debug_ops=debug_ops,246 debug_urls=debug_urls,247 tolerate_debug_op_creation_failures=(248 tolerate_debug_op_creation_failures),249 global_step=global_step)...

Full Screen

Full Screen

dist_session_debug_grpc_test.py

Source:dist_session_debug_grpc_test.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Tests for debugger functionalities in tf.compat.v1.Session with grpc:// URLs.16This test focus on grpc:// debugging of distributed (gRPC) sessions.17"""18from __future__ import absolute_import19from __future__ import division20from __future__ import print_function21import json22import subprocess23import sys24import time25import portpicker26from six.moves import xrange # pylint: disable=redefined-builtin27from tensorflow.core.protobuf import config_pb228from tensorflow.python.client import session29from tensorflow.python.debug.lib import debug_utils30from tensorflow.python.debug.lib import grpc_debug_test_server31from tensorflow.python.debug.wrappers import framework32from tensorflow.python.debug.wrappers import grpc_wrapper33from tensorflow.python.framework import ops34from tensorflow.python.framework import test_util35from tensorflow.python.ops import math_ops36from tensorflow.python.ops import state_ops37from tensorflow.python.ops import variables38from tensorflow.python.platform import googletest39from tensorflow.python.platform import test40from tensorflow.python.platform import tf_logging41@test_util.run_v1_only("b/120545219")42class DistributedSessionDebugTest(test_util.TensorFlowTestCase):43 """Test the debugging of distributed sessions."""44 PER_PROC_GPU_MEMORY_FRACTION = 0.145 POLLING_INTERVAL_SEC = 0.02546 @classmethod47 def setUpClass(cls):48 gpu_memory_fraction_opt = (49 "--gpu_memory_fraction=%f" % cls.PER_PROC_GPU_MEMORY_FRACTION)50 worker_port = portpicker.pick_unused_port()51 cluster_spec = "worker|localhost:%d" % worker_port52 tf_logging.info("cluster_spec: %s", cluster_spec)53 server_bin = test.test_src_dir_path(54 "python/debug/grpc_tensorflow_server.par")55 cls.server_target = "grpc://localhost:%d" % worker_port56 cls.server_procs = {}57 cls.server_procs["worker"] = subprocess.Popen(58 [59 server_bin,60 "--logtostderr",61 "--cluster_spec=%s" % cluster_spec,62 "--job_name=worker",63 "--task_id=0",64 gpu_memory_fraction_opt,65 ],66 stdout=sys.stdout,67 stderr=sys.stderr)68 # Start debug server in-process, on separate thread.69 (cls.debug_server_port, cls.debug_server_url, _, cls.debug_server_thread,70 cls.debug_server71 ) = grpc_debug_test_server.start_server_on_separate_thread(72 dump_to_filesystem=False)73 tf_logging.info("debug server url: %s", cls.debug_server_url)74 cls.session_config = config_pb2.ConfigProto(75 gpu_options=config_pb2.GPUOptions(76 per_process_gpu_memory_fraction=cls.PER_PROC_GPU_MEMORY_FRACTION))77 @classmethod78 def tearDownClass(cls):79 for key in cls.server_procs:80 cls.server_procs[key].terminate()81 try:82 cls.debug_server.stop_server().wait()83 except ValueError:84 pass85 cls.debug_server_thread.join()86 def setUp(self):87 pass88 def tearDown(self):89 self.debug_server.clear_data()90 def _pollingAssertDebugTensorValuesAllClose(self, expected_values,91 debug_tensor_name):92 """Poll debug_server till tensor appears and matches expected values."""93 while (debug_tensor_name not in self.debug_server.debug_tensor_values or94 len(self.debug_server.debug_tensor_values) < len(expected_values)):95 time.sleep(self.POLLING_INTERVAL_SEC)96 self.assertAllClose(97 expected_values,98 self.debug_server.debug_tensor_values[debug_tensor_name])99 def _createGraph(self):100 """Create graph for testing.101 Returns:102 Python Graph object.103 """104 with ops.Graph().as_default() as graph:105 with ops.device("/job:worker/task:0/cpu:0"):106 self.a = variables.VariableV1(10.0, name="a")107 self.b = variables.VariableV1(100.0, name="b")108 self.inc_a = state_ops.assign_add(self.a, 2.0, name="inc_a")109 self.dec_b = state_ops.assign_add(self.b, -5.0, name="dec_b")110 self.p = math_ops.multiply(self.inc_a, self.dec_b, name="p")111 self.q = math_ops.negative(self.p, name="q")112 return graph113 def testDistributedRunWithGatedGrpcCommunicatesWithDebugServerCorrectly(self):114 graph = self._createGraph()115 with session.Session(116 config=self.session_config, graph=graph,117 target=self.server_target) as sess:118 sess.run(self.a.initializer)119 sess.run(self.b.initializer)120 run_options = config_pb2.RunOptions()121 debug_utils.watch_graph(122 run_options,123 sess.graph,124 node_name_regex_whitelist=r"a",125 debug_ops=["DebugIdentity"],126 debug_urls=[self.debug_server_url])127 # Test gated_grpc for an op located on the worker, i.e., on the same128 # host as where MasterSession is.129 # TODO(cais): gRPC gating of debug ops does not work on partition graphs130 # not located on MasterSession hosts (e.g., parameter servers) yet. Make131 # it work.132 debug_utils.watch_graph(133 run_options,134 sess.graph,135 node_name_regex_whitelist=r"p",136 debug_ops=["DebugIdentity(gated_grpc=True)"],137 debug_urls=[self.debug_server_url])138 for i in xrange(4):139 if i % 2 == 0:140 self.debug_server.request_watch("p", 0, "DebugIdentity")141 else:142 self.debug_server.request_unwatch("p", 0, "DebugIdentity")143 expected_p = (10.0 + 2.0 * (i + 1)) * (100.0 - 5.0 * (i + 1))144 self.assertAllClose(-expected_p, sess.run(self.q, options=run_options))145 self.assertEqual(1, len(self.debug_server.core_metadata_json_strings))146 core_metadata = json.loads(147 self.debug_server.core_metadata_json_strings[0])148 self.assertEqual([], core_metadata["input_names"])149 self.assertEqual(["q:0"], core_metadata["output_names"])150 self.assertEqual(i, core_metadata["executor_step_index"])151 if i == 0:152 self.assertEqual(1, len(self.debug_server.partition_graph_defs))153 # Tensor "a" is from a PS. It may take longer to arrive due to the fact154 # that the stream connection between the PS and the debug server is155 # persistent and not torn down at the end of each Session.run()156 self._pollingAssertDebugTensorValuesAllClose([10.0 + 2.0 * i],157 "a:0:DebugIdentity")158 # Due to the gRPC gating of the debug op for "p", the debug tensor159 # should be available on odd-indexed runs.160 if i % 2 == 0:161 self.assertAllClose(162 [expected_p],163 self.debug_server.debug_tensor_values["p:0:DebugIdentity"])164 else:165 self.assertNotIn("p:0:DebugIdentity",166 self.debug_server.debug_tensor_values)167 self.assertNotIn("b:0:DebugIdentity",168 self.debug_server.debug_tensor_values)169 self.debug_server.clear_data()170 def testDistributedRunWithGrpcDebugWrapperWorks(self):171 graph = self._createGraph()172 with session.Session(173 config=self.session_config, graph=graph,174 target=self.server_target) as sess:175 sess.run(self.a.initializer)176 sess.run(self.b.initializer)177 def watch_fn(feeds, fetch_keys):178 del feeds, fetch_keys179 return framework.WatchOptions(180 debug_ops=["DebugIdentity"],181 node_name_regex_whitelist=r"p")182 sess = grpc_wrapper.GrpcDebugWrapperSession(183 sess, "localhost:%d" % self.debug_server_port, watch_fn=watch_fn)184 for i in xrange(4):185 expected_p = (10.0 + 2.0 * (i + 1)) * (100.0 - 5.0 * (i + 1))186 self.assertAllClose(-expected_p, sess.run(self.q))187 if i == 0:188 self.assertEqual(1, len(self.debug_server.partition_graph_defs))189 self.assertAllClose(190 [expected_p],191 self.debug_server.debug_tensor_values["p:0:DebugIdentity"])192 self.assertNotIn("b:0:DebugIdentity",193 self.debug_server.debug_tensor_values)194 self.debug_server.clear_data()195if __name__ == "__main__":...

Full Screen

Full Screen

debug_graphs_test.py

Source:debug_graphs_test.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Tests for tfdbg module debug_data."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19from tensorflow.python.debug.lib import debug_graphs20from tensorflow.python.framework import test_util21from tensorflow.python.platform import test22class ParseNodeOrTensorNameTest(test_util.TensorFlowTestCase):23 def testParseNodeName(self):24 node_name, slot = debug_graphs.parse_node_or_tensor_name(25 "namespace1/node_1")26 self.assertEqual("namespace1/node_1", node_name)27 self.assertIsNone(slot)28 def testParseTensorName(self):29 node_name, slot = debug_graphs.parse_node_or_tensor_name(30 "namespace1/node_2:3")31 self.assertEqual("namespace1/node_2", node_name)32 self.assertEqual(3, slot)33class GetNodeNameAndOutputSlotTest(test_util.TensorFlowTestCase):34 def testParseTensorNameInputWorks(self):35 self.assertEqual("a", debug_graphs.get_node_name("a:0"))36 self.assertEqual(0, debug_graphs.get_output_slot("a:0"))37 self.assertEqual("_b", debug_graphs.get_node_name("_b:1"))38 self.assertEqual(1, debug_graphs.get_output_slot("_b:1"))39 def testParseNodeNameInputWorks(self):40 self.assertEqual("a", debug_graphs.get_node_name("a"))41 self.assertEqual(0, debug_graphs.get_output_slot("a"))42class NodeNameChecksTest(test_util.TensorFlowTestCase):43 def testIsCopyNode(self):44 self.assertTrue(debug_graphs.is_copy_node("__copy_ns1/ns2/node3_0"))45 self.assertFalse(debug_graphs.is_copy_node("copy_ns1/ns2/node3_0"))46 self.assertFalse(debug_graphs.is_copy_node("_copy_ns1/ns2/node3_0"))47 self.assertFalse(debug_graphs.is_copy_node("_copyns1/ns2/node3_0"))48 self.assertFalse(debug_graphs.is_copy_node("__dbg_ns1/ns2/node3_0"))49 def testIsDebugNode(self):50 self.assertTrue(51 debug_graphs.is_debug_node("__dbg_ns1/ns2/node3:0_0_DebugIdentity"))52 self.assertFalse(53 debug_graphs.is_debug_node("dbg_ns1/ns2/node3:0_0_DebugIdentity"))54 self.assertFalse(55 debug_graphs.is_debug_node("_dbg_ns1/ns2/node3:0_0_DebugIdentity"))56 self.assertFalse(57 debug_graphs.is_debug_node("_dbgns1/ns2/node3:0_0_DebugIdentity"))58 self.assertFalse(debug_graphs.is_debug_node("__copy_ns1/ns2/node3_0"))59class ParseDebugNodeNameTest(test_util.TensorFlowTestCase):60 def testParseDebugNodeName_valid(self):61 debug_node_name_1 = "__dbg_ns_a/ns_b/node_c:1_0_DebugIdentity"62 (watched_node, watched_output_slot, debug_op_index,63 debug_op) = debug_graphs.parse_debug_node_name(debug_node_name_1)64 self.assertEqual("ns_a/ns_b/node_c", watched_node)65 self.assertEqual(1, watched_output_slot)66 self.assertEqual(0, debug_op_index)67 self.assertEqual("DebugIdentity", debug_op)68 def testParseDebugNodeName_invalidPrefix(self):69 invalid_debug_node_name_1 = "__copy_ns_a/ns_b/node_c:1_0_DebugIdentity"70 with self.assertRaisesRegexp(ValueError, "Invalid prefix"):71 debug_graphs.parse_debug_node_name(invalid_debug_node_name_1)72 def testParseDebugNodeName_missingDebugOpIndex(self):73 invalid_debug_node_name_1 = "__dbg_node1:0_DebugIdentity"74 with self.assertRaisesRegexp(ValueError, "Invalid debug node name"):75 debug_graphs.parse_debug_node_name(invalid_debug_node_name_1)76 def testParseDebugNodeName_invalidWatchedTensorName(self):77 invalid_debug_node_name_1 = "__dbg_node1_0_DebugIdentity"78 with self.assertRaisesRegexp(ValueError,79 "Invalid tensor name in debug node name"):80 debug_graphs.parse_debug_node_name(invalid_debug_node_name_1)81if __name__ == "__main__":...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Public Python API of TensorFlow Debugger (tfdbg).16See the [TFDBG](https://www.tensorflow.org/guide/debugger) guide.17@@add_debug_tensor_watch18@@watch_graph19@@watch_graph_with_blacklists20@@DebugTensorDatum21@@DebugDumpDir22@@load_tensor_from_event23@@load_tensor_from_event_file24@@has_inf_or_nan25@@DumpingDebugHook26@@DumpingDebugWrapperSession27@@GrpcDebugHook28@@GrpcDebugWrapperSession29@@LocalCLIDebugHook30@@LocalCLIDebugWrapperSession31@@TensorBoardDebugHook32@@TensorBoardDebugWrapperSession33@@WatchOptions34@@reconstruct_non_debug_graph_def35@@GradientsDebugger36@@clear_gradient_debuggers37"""38from __future__ import absolute_import39from __future__ import division40from __future__ import print_function41# pylint: disable=unused-imports42from tensorflow.python.debug.lib.debug_data import DebugDumpDir43from tensorflow.python.debug.lib.debug_data import DebugTensorDatum44from tensorflow.python.debug.lib.debug_data import has_inf_or_nan45from tensorflow.python.debug.lib.debug_data import load_tensor_from_event46from tensorflow.python.debug.lib.debug_data import load_tensor_from_event_file47from tensorflow.python.debug.lib.debug_gradients import GradientsDebugger48from tensorflow.python.debug.lib.debug_graphs import reconstruct_non_debug_graph_def49from tensorflow.python.debug.lib.debug_utils import add_debug_tensor_watch50from tensorflow.python.debug.lib.debug_utils import watch_graph51from tensorflow.python.debug.lib.debug_utils import watch_graph_with_blacklists52from tensorflow.python.debug.wrappers.dumping_wrapper import DumpingDebugWrapperSession53from tensorflow.python.debug.wrappers.framework import WatchOptions54from tensorflow.python.debug.wrappers.grpc_wrapper import GrpcDebugWrapperSession55from tensorflow.python.debug.wrappers.grpc_wrapper import TensorBoardDebugWrapperSession56from tensorflow.python.debug.wrappers.hooks import DumpingDebugHook57from tensorflow.python.debug.wrappers.hooks import GrpcDebugHook58from tensorflow.python.debug.wrappers.hooks import LocalCLIDebugHook59from tensorflow.python.debug.wrappers.hooks import TensorBoardDebugHook60from tensorflow.python.debug.wrappers.local_cli_wrapper import LocalCLIDebugWrapperSession61from tensorflow.python.util import all_util as _all_util...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.pause()4 cy.contains('type').click()5 cy.url().should('include', '/commands/actions')6 cy.get('.action-email')7 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("My First Test Suite", function () {2 it("My FirstTest case", function () {3 cy.get(".search-keyword").type("ca");4 cy.wait(2000);5 cy.get(".product:visible").should("have.length", 4);6 cy.get(".products").as("productLocator");7 cy.get("@productLocator")8 .find(".product")9 .should("have.length", 4);10 cy.get(":nth-child(3) > .product-action > button").click();11 cy.get("@productLocator")12 .find(".product")13 .eq(2)14 .contains("ADD TO CART")15 .click()16 .then(function () {17 console.log("sf");18 });19 cy.get("@productLocator")20 .find(".product")21 .each(($el, index, $list) => {22 const textVeg = $el.find("h4.product-name").text();23 if (textVeg.includes("Cashews")) {24 $el.find("button").click();25 }26 });27 cy.get(".brand").should("have.text", "GREENKART");28 cy.get(".brand").then(function (logoelement) {29 cy.log(logoelement.text());30 });31 });32});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5})6describe('My First Test', () => {7 it('Does not do much!', () => {8 expect(true).to.equal(true)9 })10})11describe('My First Test', () => {12 it('Does not do much!', () => {13 expect(true).to.equal(true)14 })15})16describe('My First Test', () => {17 it('Does not do much!', () => {18 expect(true).to.equal(true)19 })20})21describe('My First Test', () => {22 it('Does not do much!', () => {23 expect(true).to.equal(true)24 })25})26describe('My First Test', () => {27 it('Does not do much!', () => {28 expect(true).to.equal(true)29 })30})31describe('My First Test', () => {32 it('Does not do much!', () => {33 expect(true).to.equal(true)34 })35})36describe('My First Test', () => {37 it('Does not do much!', () => {38 expect(true).to.equal(true)39 })40})41describe('My First Test', () => {42 it('Does not do much!', () => {43 expect(true).to.equal(true)44 })45})46describe('My First Test', () => {47 it('Does not do much!', () => {48 expect(true).to.equal(true)49 })50})51describe('My First Test', () => {52 it('Does not do much!', () => {53 expect(true).to.equal(true)54 })55})56describe('My First Test', () => {57 it('Does not do much!', () => {58 expect(true).to.equal(true)59 })60})

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.log({2 consoleProps: () => {3 return {4 }5 }6})7Cypress.log({8 consoleProps: () => {9 return {10 }11 }12})13Cypress.log({14 consoleProps: () => {15 return {16 }17 }18})19Cypress.log({20 consoleProps: () => {21 return {22 }23 }24})25Cypress.log({26 consoleProps: () => {27 return {28 }29 }30})31Cypress.log({32 consoleProps: () => {33 return {34 }35 }36})37Cypress.log({38 consoleProps: () => {39 return {40 }41 }42})43Cypress.log({44 consoleProps: () => {45 return {46 }47 }48})49Cypress.log({

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful