Exemple #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)
  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))
  def _exiting_handler(self, argv, screen_info=None):
    """A handler that exits with an exit token."""

    if argv:
      exit_token = argv[0]
    else:
      exit_token = None

    raise debugger_cli_common.CommandLineExit(exit_token=exit_token)
  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, []))
  def testConstructionWithToken(self):
    exit_exc = debugger_cli_common.CommandLineExit(exit_token={"foo": "bar"})

    self.assertTrue(isinstance(exit_exc, Exception))
    self.assertEqual({"foo": "bar"}, exit_exc.exit_token)
  def testConstructionWithoutToken(self):
    exit_exc = debugger_cli_common.CommandLineExit()

    self.assertTrue(isinstance(exit_exc, Exception))