Exemplo n.º 1
0
    def run(self, args):
        script = Script(
            summary=
            "Defines or modifies a TensorRT Network using the Network API.",
            always_create_runners=False)
        script.add_import(imports=["func"], frm="polygraphy")
        script.add_import(imports=["tensorrt as trt"])

        if self.arg_groups[ModelArgs].model_file is not None:
            loader_name = self.arg_groups[
                TrtNetworkLoaderArgs].add_trt_network_loader(script)
            params = safe("builder, network, parser")
        else:
            script.add_import(imports=["CreateNetwork"],
                              frm="polygraphy.backend.trt")
            loader_name = safe("CreateNetwork()")
            params = safe("builder, network")

        script.append_suffix(safe("@func.extend({:})", inline(loader_name)))
        script.append_suffix(safe("def load_network({:}):", inline(params)))
        script.append_suffix(
            safe(
                "\tpass # TODO: Set up the network here. This function should not return anything."
            ))

        script.save(args.output)
Exemplo n.º 2
0
    def build_script(self, args):
        script = Script(
            summary=generate_summary(self.arg_groups[ModelArgs].model_file,
                                     args.runners, args.load_results))

        self.arg_groups[LoggerArgs].add_to_script(script)

        if not args.runners:
            G_LOGGER.warning(
                "No runners have been selected. Inference will not be run!")

        for runner_arg in args.runners:
            add_runner_func = {
                "tf": self.arg_groups[TfRunnerArgs].add_to_script,
                "onnxrt": self.arg_groups[OnnxrtRunnerArgs].add_to_script,
                "trt": self.arg_groups[TrtRunnerArgs].add_to_script,
                "trt_legacy": self.arg_groups[TrtLegacyArgs].add_to_script,
                "pluginref": self.arg_groups[PluginRefArgs].add_to_script,
            }[runner_arg]
            add_runner_func(script)

        RESULTS_VAR_NAME = self.arg_groups[ComparatorRunArgs].add_to_script(
            script)
        SUCCESS_VAR_NAME = self.arg_groups[
            ComparatorCompareArgs].add_to_script(script,
                                                 results_name=RESULTS_VAR_NAME)

        script.add_import(imports=["sys"])

        cmd_run = inline(safe("' '.join(sys.argv)"))
        exit_status = safe(
            "# Report Results\n"
            "cmd_run = {cmd}\n"
            "if not {success}:\n"
            '\tG_LOGGER.critical("FAILED | Command: {{}}".format(cmd_run))\n'
            'G_LOGGER.finish("PASSED | Command: {{}}".format(cmd_run))\n',
            cmd=cmd_run,
            success=SUCCESS_VAR_NAME,
        )
        script.append_suffix(exit_status)

        return script
Exemplo n.º 3
0
    def run(self, args):
        script = Script(summary="Creates a TensorRT Builder Configuration.",
                        always_create_runners=False)
        script.add_import(imports=["func"], frm="polygraphy")
        script.add_import(imports=["tensorrt as trt"])

        loader_name = self.arg_groups[TrtConfigArgs].add_trt_config_loader(
            script)
        if not loader_name:
            script.add_import(imports=["CreateConfig"],
                              frm="polygraphy.backend.trt")
            loader_name = script.add_loader(safe("CreateConfig()"),
                                            "create_trt_config")
        params = safe("config")

        script.append_suffix(safe("@func.extend({:})", inline(loader_name)))
        script.append_suffix(safe("def load_config({:}):", inline(params)))
        script.append_suffix(
            safe(
                "\tpass # TODO: Set up the builder configuration here. This function should not return anything."
            ))

        script.save(args.output)