示例#1
0
    def _register_this_run_info(self, curses_cli):
        curses_cli.register_command_handler(
            "run",
            self._run_handler,
            self._argparsers["run"].format_help(),
            prefix_aliases=["r"])
        curses_cli.register_command_handler(
            "HOME",
            self._run_info_handler,
            self._argparsers["HOME"].format_help(),
            prefix_aliases=["home"])
        curses_cli.register_command_handler(
            "print_input",
            self._print_input_handler,
            self._argparsers["print_input"].format_help(),
            prefix_aliases=["pi"])

        if self._tensor_filters:
            # Register tab completion for the filter names.
            curses_cli.register_tab_comp_context(["run", "r"],
                                                 list(self._tensor_filters.keys()))
        if self._input_dict:
            # Register tab completion for input_dict keys.
            input_keys = [common.get_graph_element_name(key)
                          for key in self._input_dict.keys()]
            curses_cli.register_tab_comp_context(["print_input", "pi"], input_keys)
示例#2
0
    def _print_input_handler(self, args, screen_info=None):
        np_printoptions = ui_shared.get_np_printoptions_frm_scr(
            screen_info)

        if not self._input_dict:
            return ui_shared.error(
                "The input_dict of the current run is None or empty.")

        parsed = self._argparsers["print_input"].parse_args(args)
        tensor_name, tensor_slicing = (
            command_parser.parse_tensor_name_with_slicing(parsed.tensor_name))

        input_key = None
        input_value = None
        for key in self._input_dict:
            key_name = common.get_graph_element_name(key)
            if key_name == tensor_name:
                input_key = key_name
                input_value = self._input_dict[key]
                break

        if input_key is None:
            return ui_shared.error(
                "The input_dict of the current run does not contain the key %s" %
                tensor_name)
        return ui_shared.format_tensor(
            input_value,
            input_key + " (input)",
            np_printoptions,
            print_all=parsed.print_all,
            tensor_slicing=tensor_slicing,
            highlight_options=ui_shared.parse_ranges_highlight(parsed.ranges),
            include_numeric_summary=parsed.numeric_summary)
示例#3
0
def get_run_short_description(run_call_count,
                              outputs,
                              input_dict,
                              is_callable_runner=False):
    """Get a short description of the run() call.

    Parameters
    ----------
    run_call_count : int
        Run call counter.

    outputs : dict
        Outputs of the `GraphRuntime.run()` call.

    input_dict : dict
        Inputs to the `GraphRuntime.run()` call.

    is_callable_runner : bool
        whether a runner returned is callable

    Returns
    -------
    description : str
        A short description of the run call, including information about the output(s) and input(s).
    """
    if is_callable_runner:
        return "runner from make_callable()"

    description = "run #%d: " % run_call_count

    if ';' not in outputs:
        description += "1 input (%s); " % common.get_graph_element_name(
            outputs)
    else:
        # Could be (nested) list, tuple, dict or namedtuple.
        num_outputs = len(common.get_flattened_names(outputs))
        if num_outputs > 1:
            description += "%d outputs; " % num_outputs
        else:
            description += "%d output; " % num_outputs

    if not input_dict:
        description += "0 inputs"
    else:
        if len(input_dict) == 1:
            for key in input_dict:
                description += "1 input (%s)" % (
                    key if isinstance(key, six.string_types)
                    or not hasattr(key, "name") else key.name)
        else:
            description += "%d inputs" % len(input_dict)

    return description
示例#4
0
def get_run_start_intro(graph_node_count,
                        outputs,
                        input_dict,
                        is_callable_runner=False):
    """Generate formatted intro for run-start UI.

    Parameters
    ----------
      run_call_count: (int) Run call counter.
      outputs: Outputs of the `GraphRuntime.run()` call. See doc of `GraphRuntime.run()`
        for more details.
      input_dict: Inputs to the `GraphRuntime.run()` call. See doc of `GraphRuntime.run()`
        for more details.
      tensor_filters: (dict) A dict from tensor-filter name to tensor-filter
        callable.
      is_callable_runner: (bool) whether a runner returned by
          GraphRuntime.make_callable is being run.

    Returns:
      (RichTextLines) Formatted intro message about the `GraphRuntime.run()` call.
    """

    output_lines = common.get_flattened_names(outputs)

    if not input_dict:
        input_dict_lines = [ui_common.RichLine("  (Empty)")]
    else:
        input_dict_lines = []
        for input_key in input_dict:
            input_key_name = common.get_graph_element_name(input_key)
            input_dict_line = ui_common.RichLine("  ")
            input_dict_line += ui_common.RichLine(
                input_key_name,
                ui_common.MenuItem(None, "pi '%s'" % input_key_name))
            # Surround the name string with quotes, because input_key_name may contain
            # spaces in some cases, e.g., SparseTensors.
            input_dict_lines.append(input_dict_line)
    input_dict_lines = ui_common.rich_text_lines_frm_line_list(
        input_dict_lines)

    out = ui_common.RichTextLines(_HORIZONTAL_BAR)
    out.append("")
    out.append("")
    out.append(" Choose any of the below option to continue...")
    out.append(" ---------------------------------------------")

    out.extend(
        _recommend_command("run",
                           "Run the NNVM graph with debug",
                           create_link=True))
    out.extend(
        _recommend_command("run -nodebug",
                           "Run the NNVM graph without debug",
                           create_link=True))

    out.append("")
    out.append(_HORIZONTAL_BAR)
    if is_callable_runner:
        out.append(
            " Running a runner returned by GraphRuntime.make_callable()")
    else:
        out.append("")
        out.append(" TVM Graph details")  # % run_call_count)
        out.append(" -----------------")
        out.append("")
        out.append(" Node count:")
        out.append("  " + str(graph_node_count))
        out.append("")
        out.append(" Input(s):")
        out.extend(input_dict_lines)
        out.append("")
        out.append(" Output(s):")
        out.extend(
            ui_common.RichTextLines(["  " + line for line in output_lines]))
        out.append("")
    out.append(_HORIZONTAL_BAR)

    # Make main menu for the run-start intro.
    menu = ui_common.Menu()
    menu.append(ui_common.MenuItem("run", "run"))
    out.annotations[ui_common.MAIN_MENU_KEY] = menu

    return out