Ejemplo n.º 1
0
    def on_run_start(self, request):
        debug_urls = self._bad_debug_urls or []

        if self._bad_run_start_action:
            return framework.OnRunStartResponse(self._bad_run_start_action,
                                                debug_urls)
        else:
            return framework.OnRunStartResponse(
                framework.OnRunStartAction.DEBUG_RUN, debug_urls)
Ejemplo n.º 2
0
    def _on_run_start_run_handler(self, args, screen_info=None):
        """Command handler for "run" command during on-run-start."""

        _ = screen_info  # Currently unused.

        parsed = self._on_run_start_parsers["run"].parse_args(args)

        if parsed.till_filter_pass:
            # For the run-till-bad-numerical-value-appears mode, use the DEBUG_RUN
            # option to access the intermediate tensors, and set the corresponding
            # state flag of the class itself to True.
            if parsed.till_filter_pass in self._tensor_filters:
                action = framework.OnRunStartAction.DEBUG_RUN
                self._run_till_filter_pass = parsed.till_filter_pass
            else:
                # Handle invalid filter name.
                return debugger_cli_common.RichTextLines([
                    "ERROR: tensor filter \"%s\" does not exist." %
                    parsed.till_filter_pass
                ])

        if parsed.no_debug:
            action = framework.OnRunStartAction.NON_DEBUG_RUN
            debug_urls = []
        else:
            action = framework.OnRunStartAction.DEBUG_RUN
            debug_urls = self._get_run_debug_urls()

        annotations = {
            debugger_cli_common.EXIT_TOKEN_KEY:
            framework.OnRunStartResponse(action, debug_urls)
        }

        return debugger_cli_common.RichTextLines([], annotations=annotations)
Ejemplo n.º 3
0
    def on_run_start(self, request):
        """Override abstract on-run-start callback method."""

        self._obs["on_run_start_count"] += 1
        self._obs["run_fetches"] = request.fetches
        self._obs["run_feed_dict"] = request.feed_dict

        return framework.OnRunStartResponse(
            framework.OnRunStartAction.DEBUG_RUN,
            ["file://" + self._dump_root])
Ejemplo n.º 4
0
    def _on_run_start_step_handler(self, args, screen_info=None):
        """Command handler for "invoke_stepper" command during on-run-start."""

        _ = screen_info  # Currently unused.

        # No parsing is currently necessary for invoke_stepper. This may change
        # in the future when the command has arguments.

        # Raise CommandLineExit exception to cause the CLI to exit.
        raise debugger_cli_common.CommandLineExit(
            exit_token=framework.OnRunStartResponse(
                framework.OnRunStartAction.INVOKE_STEPPER, []))
Ejemplo n.º 5
0
    def _on_run_start_step_handler(self, args, screen_info=None):
        """Command handler for "invoke_stepper" command during on-run-start."""

        _ = screen_info  # Currently unused.

        # No parsing is currently necessary for invoke_stepper. This may change
        # in the future when the command has arguments.

        action = framework.OnRunStartAction.INVOKE_STEPPER
        annotations = {
            debugger_cli_common.EXIT_TOKEN_KEY:
            framework.OnRunStartResponse(action, [])
        }

        return debugger_cli_common.RichTextLines([], annotations=annotations)
Ejemplo n.º 6
0
    def on_run_start(self, request):
        """Overrides on-run-start callback.

    Invoke the CLI to let user choose what action to take:
      run / run --no_debug / step.

    Args:
      request: An instance of OnSessionInitRequest.

    Returns:
      An instance of OnSessionInitResponse.

    Raises:
      RuntimeError: If user chooses to prematurely exit the debugger.
    """

        self._update_run_calls_state(request.run_call_count, request.fetches,
                                     request.feed_dict)

        if self._run_till_filter_pass:
            # If we are running till a filter passes, we just need to keep running
            # with the DEBUG_RUN option.
            return framework.OnRunStartResponse(
                framework.OnRunStartAction.DEBUG_RUN,
                self._get_run_debug_urls())

        run_start_cli = curses_ui.CursesUI()

        run_start_cli.register_command_handler(
            "run",
            self._on_run_start_run_handler,
            self._on_run_start_parsers["run"].format_help(),
            prefix_aliases=["r"])
        run_start_cli.register_command_handler(
            "invoke_stepper",
            self._on_run_start_step_handler,
            self._on_run_start_parsers["invoke_stepper"].format_help(),
            prefix_aliases=["s"])

        if isinstance(request.fetches, list) or isinstance(
                request.fetches, tuple):
            fetch_lines = [fetch.name for fetch in request.fetches]
        else:
            fetch_lines = [repr(request.fetches)]

        if not request.feed_dict:
            feed_dict_lines = ["(Empty)"]
        else:
            feed_dict_lines = []
            for feed_key in request.feed_dict:
                feed_dict_lines.append(feed_key.name)

        # TODO(cais): Refactor into its own function.
        help_intro = [
            "======================================",
            "About to enter Session run() call #%d:" % request.run_call_count,
            "", "Fetch(es):"
        ]
        help_intro.extend(["  " + line for line in fetch_lines])
        help_intro.extend(["", "Feed dict(s):"])
        help_intro.extend(["  " + line for line in feed_dict_lines])
        help_intro.extend([
            "======================================", "",
            "Select one of the following commands to proceed ---->", "  run:",
            "      Execute the run() call with the debug tensor-watching",
            "  run -n:",
            "      Execute the run() call without the debug tensor-watching",
            "  run -f <filter_name>:",
            "      Keep executing run() calls until a dumped tensor passes ",
            "      a given, registered filter emerge. Registered filter(s):"
        ])

        if self._tensor_filters:
            for filter_name in self._tensor_filters:
                help_intro.append("        * " + filter_name)
        else:
            help_intro.append("        (None)")

        help_intro.extend([
            "",
            "For more details, see help below:"
            "",
        ])
        run_start_cli.set_help_intro(help_intro)

        # Create initial screen output detailing the run.
        title = "run-start: " + self._run_description
        response = run_start_cli.run_ui(init_command="help",
                                        title=title,
                                        title_color="yellow")
        if response == debugger_cli_common.EXPLICIT_USER_EXIT:
            # Explicit user "exit" command leads to sys.exit(1).
            print("Note: user exited from debugger CLI: sys.exit(1) called.",
                  file=sys.stderr)
            sys.exit(1)

        return response