Ejemplo n.º 1
0
    def _run_handler(self, args, screen_info=None):
        """Command handler for "run" command during on-run-start."""

        del screen_info  # Currently unused.

        parsed = self._argparsers["run"].parse_args(args)
        parsed.node_name_filter = parsed.node_name_filter or None
        parsed.op_type_filter = parsed.op_type_filter or None
        parsed.tensor_dtype_filter = parsed.tensor_dtype_filter or None

        if parsed.filter_exclude_node_names and not parsed.till_filter_pass:
            raise ValueError(
                "The --filter_exclude_node_names (or -feon) flag is valid only if "
                "the --till_filter_pass (or -f) flag is used.")

        if parsed.profile:
            raise debugger_cli_common.CommandLineExit(
                exit_token=framework.OnRunStartResponse(
                    framework.OnRunStartAction.PROFILE_RUN, []))

        self._skip_debug = parsed.no_debug
        self._run_through_times = parsed.times

        if parsed.times > 1 or parsed.no_debug:
            # If requested -t times > 1, the very next run will be a non-debug run.
            action = framework.OnRunStartAction.NON_DEBUG_RUN
            debug_urls = []
        else:
            action = framework.OnRunStartAction.DEBUG_RUN
            debug_urls = self._get_run_debug_urls()
        run_start_response = framework.OnRunStartResponse(
            action,
            debug_urls,
            node_name_regex_whitelist=parsed.node_name_filter,
            op_type_regex_whitelist=parsed.op_type_filter,
            tensor_dtype_regex_whitelist=parsed.tensor_dtype_filter)

        if parsed.till_filter_pass:
            # For the run-till-filter-pass (run -f) 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._active_tensor_filter = parsed.till_filter_pass
                self._active_filter_exclude_node_names = (
                    parsed.filter_exclude_node_names)
                self._active_tensor_filter_run_start_response = run_start_response
            else:
                # Handle invalid filter name.
                return debugger_cli_common.RichTextLines([
                    "ERROR: tensor filter \"%s\" does not exist." %
                    parsed.till_filter_pass
                ])

        # Raise CommandLineExit exception to cause the CLI to exit.
        raise debugger_cli_common.CommandLineExit(
            exit_token=run_start_response)
Ejemplo n.º 2
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.º 3
0
    def on_run_start(self, request):
        """Overrides on-run-start callback.

    Invoke the CLI to let user choose what action to take:
      `run` / `invoke_stepper`.

    Args:
      request: An instance of `OnSessionInitRequest`.

    Returns:
      An instance of `OnSessionInitResponse`.

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

        self._is_run_start = True
        self._update_run_calls_state(request.run_call_count, request.fetches,
                                     request.feed_dict)

        if self._active_tensor_filter:
            # 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())

        if self._run_call_count > 1 and not self._skip_debug:
            if self._run_through_times > 0:
                # Just run through without debugging.
                return framework.OnRunStartResponse(
                    framework.OnRunStartAction.NON_DEBUG_RUN, [])
            elif self._run_through_times == 0:
                # It is the run at which the run-end CLI will be launched: activate
                # debugging.
                return framework.OnRunStartResponse(
                    framework.OnRunStartAction.DEBUG_RUN,
                    self._get_run_debug_urls())

        if self._run_start_response is None:
            self._prep_cli_for_run_start()

            self._run_start_response = self._launch_cli()
            if self._run_through_times > 1:
                self._run_through_times -= 1

        if self._run_start_response == debugger_cli_common.EXPLICIT_USER_EXIT:
            # Explicit user "exit" command leads to sys.exit(1).
            print("Note: user exited from debugger CLI: Calling sys.exit(1).",
                  file=sys.stderr)
            sys.exit(1)

        return self._run_start_response
Ejemplo n.º 4
0
    def on_run_start(self, request):
        """Overrides on-run-start callback.

    Invoke the CLI to let user choose what action to take:
      `run` / `invoke_stepper`.

    Args:
      request: An instance of `OnRunStartRequest`.

    Returns:
      An instance of `OnRunStartResponse`.
    """
        self._is_run_start = True
        self._update_run_calls_state(
            request.run_call_count,
            request.fetches,
            request.feed_dict,
            is_callable_runner=request.is_callable_runner)

        if self._active_tensor_filter:
            # If we are running until a filter passes, we just need to keep running
            # with the previous `OnRunStartResponse`.
            return self._active_tensor_filter_run_start_response

        self._exit_if_requested_by_user()

        if self._run_call_count > 1 and not self._skip_debug:
            if self._run_through_times > 0:
                # Just run through without debugging.
                return framework.OnRunStartResponse(
                    framework.OnRunStartAction.NON_DEBUG_RUN, [])
            elif self._run_through_times == 0:
                # It is the run at which the run-end CLI will be launched: activate
                # debugging.
                return (self._run_start_response
                        or framework.OnRunStartResponse(
                            framework.OnRunStartAction.DEBUG_RUN,
                            self._get_run_debug_urls()))

        if self._run_start_response is None:
            self._prep_cli_for_run_start()

            self._run_start_response = self._launch_cli()
            if self._active_tensor_filter:
                self._active_tensor_filter_run_start_response = self._run_start_response
            if self._run_through_times > 1:
                self._run_through_times -= 1

        self._exit_if_requested_by_user()
        return self._run_start_response
Ejemplo n.º 5
0
  def _run_handler(self, args, screen_info=None):
    """Command handler for "run" command during on-run-start."""

    _ = screen_info  # Currently unused.

    parsed = self._argparsers["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._active_tensor_filter = 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])

    self._skip_debug = parsed.no_debug
    self._run_through_times = parsed.times

    if parsed.times > 1 or parsed.no_debug:
      # If requested -t times > 1, the very next run will be a non-debug run.
      action = framework.OnRunStartAction.NON_DEBUG_RUN
      debug_urls = []
    else:
      action = framework.OnRunStartAction.DEBUG_RUN
      debug_urls = self._get_run_debug_urls()

    # Raise CommandLineExit exception to cause the CLI to exit.
    raise debugger_cli_common.CommandLineExit(
        exit_token=framework.OnRunStartResponse(action, debug_urls))
Ejemplo n.º 6
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.º 7
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.º 8
0
    def on_run_start(self, request):
        """See doc of BaseDebugWrapperSession.on_run_start."""

        (debug_urls, debug_ops, node_name_regex_whitelist,
         op_type_regex_whitelist) = self._prepare_run_watch_config(
             request.fetches, request.feed_dict)

        return framework.OnRunStartResponse(
            framework.OnRunStartAction.DEBUG_RUN,
            debug_urls,
            debug_ops=debug_ops,
            node_name_regex_whitelist=node_name_regex_whitelist,
            op_type_regex_whitelist=op_type_regex_whitelist)
    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 self._tensor_filters:
            # Register tab completion for the filter names.
            run_start_cli.register_tab_comp_context(
                ["run", "r"], list(self._tensor_filters.keys()))

        run_start_cli.set_help_intro(
            cli_shared.get_run_start_intro(request.run_call_count,
                                           request.fetches, request.feed_dict,
                                           self._tensor_filters))

        # 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="blue_on_white")
        if response == debugger_cli_common.EXPLICIT_USER_EXIT:
            # Explicit user "exit" command leads to sys.exit(1).
            print("Note: user exited from debugger CLI: Calling sys.exit(1).",
                  file=sys.stderr)
            sys.exit(1)

        return response
Ejemplo n.º 10
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:
        if isinstance(feed_key, six.string_types):
          feed_dict_lines.append(feed_key)
        else:
          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:
      filter_names = []
      for filter_name in self._tensor_filters:
        filter_names.append(filter_name)
        help_intro.append("        * " + filter_name)

      # Register tab completion for the filter names.
      run_start_cli.register_tab_comp_context(["run", "r"], filter_names)
    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: Calling sys.exit(1).",
          file=sys.stderr)
      sys.exit(1)

    return response