python/tvm/driver/tvmc/runner.py
def add_run_parser(subparsers, main_parser):
    """Include parser for 'run' subcommand"""

    # Use conflict_handler='resolve' to allow '--list-options' option to be properly overriden when
    # augmenting the parser with the micro device options (i.e. when '--device micro').
    parser = subparsers.add_parser("run", help="run a compiled module", conflict_handler="resolve")
    parser.set_defaults(func=drive_run)

    # TODO --device needs to be extended and tested to support other targets,
    #      like 'webgpu', etc (@leandron)
    parser.add_argument(
        "--device",
        choices=["cpu", "cuda", "cl", "metal", "vulkan", "rocm", "micro"],
        default="cpu",
        help="target device to run the compiled module. Defaults to 'cpu'",
    )
    parser.add_argument(
        "--fill-mode",
        choices=["zeros", "ones", "random"],
        default="random",
        help="fill all input tensors with values. In case --inputs/-i is provided, "
        "they will take precedence over --fill-mode. Any remaining inputs will be "
        "filled using the chosen fill mode. Defaults to 'random'",
    )
    parser.add_argument("-i", "--inputs", help="path to the .npz input file")
    parser.add_argument("-o", "--outputs", help="path to the .npz output file")
    parser.add_argument(
        "--print-time",
        action="store_true",
        help="record and print the execution time(s). (non-micro devices only)",
    )
    parser.add_argument(
        "--print-top",
        metavar="N",
        type=int,
        help="print the top n values and indices of the output tensor",
    )
    parser.add_argument(
        "--profile",
        action="store_true",
        help="generate profiling data from the runtime execution. "
        "Using --profile requires the Graph Executor Debug enabled on TVM. "
        "Profiling may also have an impact on inference time, "
        "making it take longer to be generated. (non-micro devices only)",
    )
    parser.add_argument(
        "--repeat", metavar="N", type=int, default=1, help="run the model n times. Defaults to '1'"
    )
    parser.add_argument(
        "--number", metavar="N", type=int, default=1, help="repeat the run n times. Defaults to '1'"
    )
    parser.add_argument(
        "--rpc-key",
        help="the RPC tracker key of the target device. (non-micro devices only)",
    )
    parser.add_argument(
        "--rpc-tracker",
        help="hostname (required) and port (optional, defaults to 9090) of the RPC tracker, "
        "e.g. '192.168.0.100:9999'. (non-micro devices only)",
    )
    parser.add_argument(
        "PATH",
        help="path to the compiled module file or to the project directory if '--device micro' "
        "is selected.",
    )
    parser.add_argument(
        "--list-options",
        action="store_true",
        help="show all run options and option choices when '--device micro' is selected. "
        "(micro devices only)",
    )

    disposable_parser = TVMCSuppressedArgumentParser(main_parser)
    try:
        known_args, _ = disposable_parser.parse_known_args()
    except TVMCException:
        return

    if vars(known_args).get("device") != "micro":
        # No need to augment the parser for micro targets.
        return

    project_dir = known_args.PATH

    try:
        project_ = project.GeneratedProject.from_directory(project_dir, None)
    except ProjectAPIServerNotFoundError:
        sys.exit(f"Error: Project API server not found in {project_dir}!")
    except TemplateProjectError:
        sys.exit(
            f"Error: Project directory error. That usually happens when model.tar is not found."
        )

    project_info = project_.info()
    options_by_method = get_project_options(project_info)

    parser.formatter_class = (
        argparse.RawTextHelpFormatter
    )  # Set raw help text so customized help_text format works
    parser.set_defaults(valid_options=options_by_method["open_transport"])

    required = any([opt["required"] for opt in options_by_method["open_transport"]])
    nargs = "+" if required else "*"

    help_text_by_option = [opt["help_text"] for opt in options_by_method["open_transport"]]
    help_text = "\n\n".join(help_text_by_option) + "\n\n"

    parser.add_argument(
        "--project-option", required=required, metavar="OPTION=VALUE", nargs=nargs, help=help_text
    )

    parser.add_argument(
        "--list-options",
        action="help",
        help="show this help message with platform-specific options and exit.",
    )
Include parser for 'run' subcommand
Include parser for 'run' subcommand
Include parser for ' run ' subcommand
def add_run_parser(subparsers, main_parser):
    parser = subparsers.add_parser("run", help="run a compiled module", conflict_handler="resolve")
    parser.set_defaults(func=drive_run)
    parser.add_argument(
        "--device",
        choices=["cpu", "cuda", "cl", "metal", "vulkan", "rocm", "micro"],
        default="cpu",
        help="target device to run the compiled module. Defaults to 'cpu'",
    )
    parser.add_argument(
        "--fill-mode",
        choices=["zeros", "ones", "random"],
        default="random",
        help="fill all input tensors with values. In case --inputs/-i is provided, "
        "they will take precedence over --fill-mode. Any remaining inputs will be "
        "filled using the chosen fill mode. Defaults to 'random'",
    )
    parser.add_argument("-i", "--inputs", help="path to the .npz input file")
    parser.add_argument("-o", "--outputs", help="path to the .npz output file")
    parser.add_argument(
        "--print-time",
        action="store_true",
        help="record and print the execution time(s). (non-micro devices only)",
    )
    parser.add_argument(
        "--print-top",
        metavar="N",
        type=int,
        help="print the top n values and indices of the output tensor",
    )
    parser.add_argument(
        "--profile",
        action="store_true",
        help="generate profiling data from the runtime execution. "
        "Using --profile requires the Graph Executor Debug enabled on TVM. "
        "Profiling may also have an impact on inference time, "
        "making it take longer to be generated. (non-micro devices only)",
    )
    parser.add_argument(
        "--repeat", metavar="N", type=int, default=1, help="run the model n times. Defaults to '1'"
    )
    parser.add_argument(
        "--number", metavar="N", type=int, default=1, help="repeat the run n times. Defaults to '1'"
    )
    parser.add_argument(
        "--rpc-key",
        help="the RPC tracker key of the target device. (non-micro devices only)",
    )
    parser.add_argument(
        "--rpc-tracker",
        help="hostname (required) and port (optional, defaults to 9090) of the RPC tracker, "
        "e.g. '192.168.0.100:9999'. (non-micro devices only)",
    )
    parser.add_argument(
        "PATH",
        help="path to the compiled module file or to the project directory if '--device micro' "
        "is selected.",
    )
    parser.add_argument(
        "--list-options",
        action="store_true",
        help="show all run options and option choices when '--device micro' is selected. "
        "(micro devices only)",
    )
    disposable_parser = TVMCSuppressedArgumentParser(main_parser)
    try:
        known_args, _ = disposable_parser.parse_known_args()
    except TVMCException:
        return
    if vars(known_args).get("device") != "micro":
        return
    project_dir = known_args.PATH
    try:
        project_ = project.GeneratedProject.from_directory(project_dir, None)
    except ProjectAPIServerNotFoundError:
        sys.exit(f"Error: Project API server not found in {project_dir}!")
    except TemplateProjectError:
        sys.exit(
            f"Error: Project directory error. That usually happens when model.tar is not found."
        )
    project_info = project_.info()
    options_by_method = get_project_options(project_info)
    parser.formatter_class = (
        argparse.RawTextHelpFormatter
    )  
    parser.set_defaults(valid_options=options_by_method["open_transport"])
    required = any([opt["required"] for opt in options_by_method["open_transport"]])
    nargs = "+" if required else "*"
    help_text_by_option = [opt["help_text"] for opt in options_by_method["open_transport"]]
    help_text = "\n\n".join(help_text_by_option) + "\n\n"
    parser.add_argument(
        "--project-option", required=required, metavar="OPTION=VALUE", nargs=nargs, help=help_text
    )
    parser.add_argument(
        "--list-options",
        action="help",
        help="show this help message with platform-specific options and exit.",
    )
def add_run_parser ( subparsers , main_parser ) : parser = subparsers . add_parser ( "run" , help = "run a compiled module" , conflict_handler = "resolve" ) parser . set_defaults ( func = drive_run ) parser . add_argument ( "--device" , choices = [ "cpu" , "cuda" , "cl" , "metal" , "vulkan" , "rocm" , "micro" ] , default = "cpu" , help = "target device to run the compiled module. Defaults to 'cpu'" , ) parser . add_argument ( "--fill-mode" , choices = [ "zeros" , "ones" , "random" ] , default = "random" , help = "fill all input tensors with values. In case --inputs/-i is provided, " "they will take precedence over --fill-mode. Any remaining inputs will be " "filled using the chosen fill mode. Defaults to 'random'" , ) parser . add_argument ( "-i" , "--inputs" , help = "path to the .npz input file" ) parser . add_argument ( "-o" , "--outputs" , help = "path to the .npz output file" ) parser . add_argument ( "--print-time" , action = "store_true" , help = "record and print the execution time(s). (non-micro devices only)" , ) parser . add_argument ( "--print-top" , metavar = "N" , type = int , help = "print the top n values and indices of the output tensor" , ) parser . add_argument ( "--profile" , action = "store_true" , help = "generate profiling data from the runtime execution. " "Using --profile requires the Graph Executor Debug enabled on TVM. " "Profiling may also have an impact on inference time, " "making it take longer to be generated. (non-micro devices only)" , ) parser . add_argument ( "--repeat" , metavar = "N" , type = int , default = 1 , help = "run the model n times. Defaults to '1'" ) parser . add_argument ( "--number" , metavar = "N" , type = int , default = 1 , help = "repeat the run n times. Defaults to '1'" ) parser . add_argument ( "--rpc-key" , help = "the RPC tracker key of the target device. (non-micro devices only)" , ) parser . add_argument ( "--rpc-tracker" , help = "hostname (required) and port (optional, defaults to 9090) of the RPC tracker, " "e.g. '192.168.0.100:9999'. (non-micro devices only)" , ) parser . add_argument ( "PATH" , help = "path to the compiled module file or to the project directory if '--device micro' " "is selected." , ) parser . add_argument ( "--list-options" , action = "store_true" , help = "show all run options and option choices when '--device micro' is selected. " "(micro devices only)" , ) disposable_parser = TVMCSuppressedArgumentParser ( main_parser ) try : known_args , _ = disposable_parser . parse_known_args ( ) except TVMCException : return if vars ( known_args ) . get ( "device" ) != "micro" : return project_dir = known_args . PATH try : project_ = project . GeneratedProject . from_directory ( project_dir , None ) except ProjectAPIServerNotFoundError : sys . exit ( f"Error: Project API server not found in {project_dir}!" ) except TemplateProjectError : sys . exit ( f"Error: Project directory error. That usually happens when model.tar is not found." ) project_info = project_ . info ( ) options_by_method = get_project_options ( project_info ) parser . formatter_class = ( argparse . RawTextHelpFormatter ) parser . set_defaults ( valid_options = options_by_method [ "open_transport" ] ) required = any ( [ opt [ "required" ] for opt in options_by_method [ "open_transport" ] ] ) nargs = "+" if required else "*" help_text_by_option = [ opt [ "help_text" ] for opt in options_by_method [ "open_transport" ] ] help_text = "\n\n" . join ( help_text_by_option ) + "\n\n" parser . add_argument ( "--project-option" , required = required , metavar = "OPTION=VALUE" , nargs = nargs , help = help_text ) parser . add_argument ( "--list-options" , action = "help" , help = "show this help message with platform-specific options and exit." , )
Include parser for 'run' subcommand
Include parser for ' run ' subcommand
"""Include parser for 'run' subcommand""" # Use conflict_handler='resolve' to allow '--list-options' option to be properly overriden when # augmenting the parser with the micro device options (i.e. when '--device micro'). # TODO --device needs to be extended and tested to support other targets, #      like 'webgpu', etc (@leandron) # No need to augment the parser for micro targets. # Set raw help text so customized help_text format works
subparsers
main_parser