def testUIFactoryRaisesExceptionOnInvalidUITypeGivenAvailable(self): with self.assertRaisesRegexp(ValueError, "Invalid ui_type: 'readline'"): ui_factory.get_ui("readline", available_ui_types=["curses"], config=cli_config.CLIConfig( config_file_path=self._tmp_config_path))
def _launch_cli(self): if self._is_run_start: self.observers["run_start_cli_run_numbers"].append( self._run_call_count) else: self.observers["run_end_cli_run_numbers"].append( self._run_call_count) readline_cli = ui_factory.get_ui("readline") self._register_this_run_info(readline_cli) while True: command = self._command_sequence[self._command_pointer] self._command_pointer += 1 try: if command[0] == "run": self._run_handler(command[1:]) elif command[0] == "print_feed": self.observers["print_feed_responses"].append( self._print_feed_handler(command[1:])) else: raise ValueError("Unrecognized command prefix: %s" % command[0]) except debugger_cli_common.CommandLineExit as e: return e.exit_token
def _launch_cli(self): if self._is_run_start: self.observers["run_start_cli_run_numbers"].append(self._run_call_count) else: self.observers["run_end_cli_run_numbers"].append(self._run_call_count) readline_cli = ui_factory.get_ui( "readline", config=cli_config.CLIConfig( config_file_path=os.path.join(tempfile.mkdtemp(), ".tfdbg_config"))) self._register_this_run_info(readline_cli) while self._command_pointer < len(self._command_sequence): command = self._command_sequence[self._command_pointer] self._command_pointer += 1 try: if command[0] == "run": self._run_handler(command[1:]) elif command[0] == "print_feed": self.observers["print_feed_responses"].append( self._print_feed_handler(command[1:])) else: raise ValueError("Unrecognized command prefix: %s" % command[0]) except debugger_cli_common.CommandLineExit as e: return e.exit_token
def create_profiler_ui(graph, run_metadata, ui_type="curses", on_ui_exit=None): """Create an instance of CursesUI based on a `tf.Graph` and `RunMetadata`. Args: graph: Python `Graph` object. run_metadata: A `RunMetadata` protobuf object. ui_type: (str) requested UI type, e.g., "curses", "readline". on_ui_exit: (`Callable`) the callback to be called when the UI exits. Returns: (base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer commands and tab-completions registered. """ analyzer = ProfileAnalyzer(graph, run_metadata) cli = ui_factory.get_ui(ui_type, on_ui_exit=on_ui_exit) cli.register_command_handler( "list_profile", analyzer.list_profile, analyzer.get_help("list_profile"), prefix_aliases=["lp"]) cli.register_command_handler( "print_source", analyzer.print_source, analyzer.get_help("print_source"), prefix_aliases=["ps"]) return cli
def create_profiler_ui(graph, run_metadata, ui_type="curses", on_ui_exit=None, config=None): """Create an instance of CursesUI based on a `tf.Graph` and `RunMetadata`. Args: graph: Python `Graph` object. run_metadata: A `RunMetadata` protobuf object. ui_type: (str) requested UI type, e.g., "curses", "readline". on_ui_exit: (`Callable`) the callback to be called when the UI exits. config: An instance of `cli_config.CLIConfig`. Returns: (base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer commands and tab-completions registered. """ del config # Currently unused. analyzer = ProfileAnalyzer(graph, run_metadata) cli = ui_factory.get_ui(ui_type, on_ui_exit=on_ui_exit) cli.register_command_handler( "list_profile", analyzer.list_profile, analyzer.get_help("list_profile"), prefix_aliases=["lp"]) cli.register_command_handler( "print_source", analyzer.print_source, analyzer.get_help("print_source"), prefix_aliases=["ps"]) return cli
def create_analyzer_ui(debug_dump, tensor_filters=None, ui_type="curses"): """Create an instance of CursesUI based on a DebugDumpDir object. Args: debug_dump: (debug_data.DebugDumpDir) The debug dump to use. tensor_filters: (dict) A dict mapping tensor filter name (str) to tensor filter (Callable). ui_type: (str) requested UI type, e.g., "curses", "readline". Returns: (base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer commands and tab-completions registered. """ analyzer = DebugAnalyzer(debug_dump) if tensor_filters: for tensor_filter_name in tensor_filters: analyzer.add_tensor_filter( tensor_filter_name, tensor_filters[tensor_filter_name]) cli = ui_factory.get_ui(ui_type) cli.register_command_handler( "list_tensors", analyzer.list_tensors, analyzer.get_help("list_tensors"), prefix_aliases=["lt"]) cli.register_command_handler( "node_info", analyzer.node_info, analyzer.get_help("node_info"), prefix_aliases=["ni"]) cli.register_command_handler( "list_inputs", analyzer.list_inputs, analyzer.get_help("list_inputs"), prefix_aliases=["li"]) cli.register_command_handler( "list_outputs", analyzer.list_outputs, analyzer.get_help("list_outputs"), prefix_aliases=["lo"]) cli.register_command_handler( "print_tensor", analyzer.print_tensor, analyzer.get_help("print_tensor"), prefix_aliases=["pt"]) cli.register_command_handler( "print_source", analyzer.print_source, analyzer.get_help("print_source"), prefix_aliases=["ps"]) dumped_tensor_names = [] for datum in debug_dump.dumped_tensor_data: dumped_tensor_names.append("%s:%d" % (datum.node_name, datum.output_slot)) # Tab completions for command "print_tensors". cli.register_tab_comp_context(["print_tensor", "pt"], dumped_tensor_names) return cli
def _prep_cli_for_run_start(self): """Prepare (but not launch) the CLI for run-start.""" self._run_cli = ui_factory.get_ui(self._ui_type) help_intro = debugger_cli_common.RichTextLines([]) if self._run_call_count == 1: # Show logo at the onset of the first run. help_intro.extend(cli_shared.get_tfdbg_logo()) help_intro.extend(debugger_cli_common.RichTextLines("Upcoming run:")) help_intro.extend(self._run_info) self._run_cli.set_help_intro(help_intro) # Create initial screen output detailing the run. self._title = "run-start: " + self._run_description self._init_command = "run_info" self._title_color = "blue_on_white"
def _launch_cli(self): if self._is_run_start: self.observers["run_start_cli_run_numbers"].append(self._run_call_count) else: self.observers["run_end_cli_run_numbers"].append(self._run_call_count) readline_cli = ui_factory.get_ui("readline") self._register_this_run_info(readline_cli) while True: command = self._command_sequence[self._command_pointer] self._command_pointer += 1 try: if command[0] == "run": self._run_handler(command[1:]) elif command[0] == "print_feed": self.observers["print_feed_responses"].append( self._print_feed_handler(command[1:])) else: raise ValueError("Unrecognized command prefix: %s" % command[0]) except debugger_cli_common.CommandLineExit as e: return e.exit_token
def testUIFactoryCreatesReadlineUI(self): ui = ui_factory.get_ui("readline") self.assertIsInstance(ui, readline_ui.ReadlineUI)
def invoke_node_stepper(self, node_stepper, restore_variable_values_on_exit=True): """Overrides method in base class to implement interactive node stepper. Args: node_stepper: (`stepper.NodeStepper`) The underlying NodeStepper API object. restore_variable_values_on_exit: (`bool`) Whether any variables whose values have been altered during this node-stepper invocation should be restored to their old values when this invocation ends. Returns: The same return values as the `Session.run()` call on the same fetches as the NodeStepper. """ stepper = stepper_cli.NodeStepperCLI(node_stepper) # On exiting the node-stepper CLI, the finalize method of the node_stepper # object will be called, ensuring that the state of the graph will be the # same as if the stepping did not happen. # TODO(cais): Perhaps some users will want the effect of the interactive # stepping and value injection to persist. When that happens, make the call # to finalize optional. stepper_ui = ui_factory.get_ui( self._ui_type, on_ui_exit=(node_stepper.restore_variable_values if restore_variable_values_on_exit else None)) stepper_ui.register_command_handler( "list_sorted_nodes", stepper.list_sorted_nodes, stepper.arg_parsers["list_sorted_nodes"].format_help(), prefix_aliases=["lt", "lsn"]) stepper_ui.register_command_handler( "cont", stepper.cont, stepper.arg_parsers["cont"].format_help(), prefix_aliases=["ct", "c"]) stepper_ui.register_command_handler( "step", stepper.step, stepper.arg_parsers["step"].format_help(), prefix_aliases=["st", "s"]) stepper_ui.register_command_handler( "print_tensor", stepper.print_tensor, stepper.arg_parsers["print_tensor"].format_help(), prefix_aliases=["pt"]) stepper_ui.register_command_handler( "inject_value", stepper.inject_value, stepper.arg_parsers["inject_value"].format_help(), prefix_aliases=["inject", "override_value", "override"]) # Register tab completion candidates. stepper_ui.register_tab_comp_context([ "cont", "ct", "c", "pt", "inject_value", "inject", "override_value", "override" ], [str(elem) for elem in node_stepper.sorted_nodes()]) # TODO(cais): Tie up register_tab_comp_context to a single alias to shorten # calls like this. return stepper_ui.run_ui(init_command="lt", title="Node Stepper: " + self._run_description, title_color="blue_on_white")
def testUIFactoryRaisesExceptionOnInvalidUIType(self): with self.assertRaisesRegex(ValueError, "Invalid ui_type: 'foobar'"): ui_factory.get_ui( "foobar", config=cli_config.CLIConfig(config_file_path=self._tmp_config_path))
def testUIFactoryCreatesReadlineUI(self): ui = ui_factory.get_ui( "readline", config=cli_config.CLIConfig(config_file_path=self._tmp_config_path)) self.assertIsInstance(ui, readline_ui.ReadlineUI)
def testUIFactoryRaisesExceptionOnInvalidUITypeGivenAvailable(self): with self.assertRaisesRegexp(ValueError, "Invalid ui_type: 'readline'"): ui_factory.get_ui("readline", available_ui_types=["curses"])
def testUIFactoryRaisesExceptionOnInvalidUIType(self): with self.assertRaisesRegexp(ValueError, "Invalid ui_type: 'foobar'"): ui_factory.get_ui("foobar")
def invoke_node_stepper(self, node_stepper, restore_variable_values_on_exit=True): """Overrides method in base class to implement interactive node stepper. Args: node_stepper: (`stepper.NodeStepper`) The underlying NodeStepper API object. restore_variable_values_on_exit: (`bool`) Whether any variables whose values have been altered during this node-stepper invocation should be restored to their old values when this invocation ends. Returns: The same return values as the `Session.run()` call on the same fetches as the NodeStepper. """ stepper = stepper_cli.NodeStepperCLI(node_stepper) # On exiting the node-stepper CLI, the finalize method of the node_stepper # object will be called, ensuring that the state of the graph will be the # same as if the stepping did not happen. # TODO(cais): Perhaps some users will want the effect of the interactive # stepping and value injection to persist. When that happens, make the call # to finalize optional. stepper_ui = ui_factory.get_ui( self._ui_type, on_ui_exit=(node_stepper.restore_variable_values if restore_variable_values_on_exit else None)) stepper_ui.register_command_handler( "list_sorted_nodes", stepper.list_sorted_nodes, stepper.arg_parsers["list_sorted_nodes"].format_help(), prefix_aliases=["lt", "lsn"]) stepper_ui.register_command_handler( "cont", stepper.cont, stepper.arg_parsers["cont"].format_help(), prefix_aliases=["ct", "c"]) stepper_ui.register_command_handler( "step", stepper.step, stepper.arg_parsers["step"].format_help(), prefix_aliases=["st", "s"]) stepper_ui.register_command_handler( "print_tensor", stepper.print_tensor, stepper.arg_parsers["print_tensor"].format_help(), prefix_aliases=["pt"]) stepper_ui.register_command_handler( "inject_value", stepper.inject_value, stepper.arg_parsers["inject_value"].format_help(), prefix_aliases=["inject", "override_value", "override"]) # Register tab completion candidates. stepper_ui.register_tab_comp_context([ "cont", "ct", "c", "pt", "inject_value", "inject", "override_value", "override" ], [str(elem) for elem in node_stepper.sorted_nodes()]) # TODO(cais): Tie up register_tab_comp_context to a single alias to shorten # calls like this. return stepper_ui.run_ui( init_command="lt", title="Node Stepper: " + self._run_description, title_color="blue_on_white")