コード例 #1
0
 def test_trt_int8_calibration_cache(self):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--trt", "--int8",
             "--calibration-cache", outpath.name
         ])
         check_file_non_empty(outpath.name)
コード例 #2
0
 def test_inputs(self, opts):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--onnxrt", "--save-inputs",
             outpath.name
         ])
         run_polygraphy_inspect(["data", outpath.name] + opts)
コード例 #3
0
 def test_model_trt_engine_sanity(self, run_inspect_model):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--trt", "--save-engine",
             outpath.name
         ])
         run_inspect_model([outpath.name, "--model-type=engine"])
コード例 #4
0
 def test_trt_multiple_profiles(self):
     run_polygraphy_run([
         ONNX_MODELS["dynamic_identity"].path, "--trt", "--onnxrt",
         "--trt-min-shapes", "X,1x2x1x1", "--trt-opt-shapes", "X,1x2x1x1",
         "--trt-max-shapes", "X,1x2x1x1", "--trt-min-shapes", "X,1x2x4x4",
         "--trt-opt-shapes", "X,1x2x4x4", "--trt-max-shapes", "X,1x2x4x4"
     ])
コード例 #5
0
 def test_custom_per_output_tolerance(self):
     run_polygraphy_run([
         ONNX_MODELS["identity_identity"].path, "--onnxrt", "--onnxrt",
         "--onnx-outputs", "mark", "all", "--atol", "identity_out_0,1.0",
         "identity_out_2,3.0", "0.5", "--rtol", "identity_out_0,1.0",
         "identity_out_2,3.0", "0.5"
     ])
コード例 #6
0
 def test_onnx_rt_exclude_outputs_with_layerwise(self):
     with tempfile.NamedTemporaryFile() as outfile0:
         run_polygraphy_run([ONNX_MODELS["identity_identity"].path, "--onnxrt", "--onnx-outputs", "mark", "all", "--onnx-exclude-outputs", "identity_out_2", "--save-outputs", outfile0.name])
         results = load_json(outfile0.name)
         [result] = list(results.values())[0]
         assert len(result) == 1
         assert "identity_out_0" in result
コード例 #7
0
 def test_int8_calibration_cache(self):
     with tempfile.NamedTemporaryFile() as outpath:
         cmd = [ONNX_MODELS["identity"].path, "--trt", "--int8", "--calibration-cache", outpath.name]
         if mod.version(trt.__version__) >= mod.version("7.0"):
             cmd += ["--onnxrt"]
         run_polygraphy_run(cmd)
         check_file_non_empty(outpath.name)
コード例 #8
0
ファイル: test_inspect.py プロジェクト: stjordanis/TensorRT
def identity_engine():
    with tempfile.NamedTemporaryFile() as outpath:
        run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--trt", "--save-engine",
            outpath.name
        ])
        yield outpath.name
コード例 #9
0
ファイル: test_surgeon.py プロジェクト: leo-XUKANG/TensorRT-1
def test_polygraphy_surgeon_extract_sanity():
    with tempfile.NamedTemporaryFile() as modelpath:
        run_polygraphy_surgeon([
            "extract", ONNX_MODELS["identity_identity"].path, "-o",
            modelpath.name, "--inputs", "identity_out_0,auto,auto"
        ])
        run_polygraphy_run([modelpath.name, "--model-type=onnx", "--onnxrt"])
コード例 #10
0
 def test_tf_save_pb(self):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             TF_MODELS["identity"].path, "--tf",
             "--gpu-memory-fraction=0.5", "--save-pb", outpath.name
         ])
         check_file_non_empty(outpath.name)
コード例 #11
0
 def test_save_load_engine(self):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--trt", "--save-engine",
             outpath.name
         ])
         assert is_file_non_empty(outpath.name)
         run_polygraphy_run(["--trt", outpath.name, "--model-type=engine"])
コード例 #12
0
 def test_tf_save_tensorboard(self):
     with tempfile.TemporaryDirectory() as outdir:
         run_polygraphy_run([
             TF_MODELS["identity"].path, "--tf",
             "--gpu-memory-fraction=0.5", "--save-tensorboard", outdir
         ])
         files = glob.glob("{:}{:}*".format(outdir, os.path.sep))
         assert len(files) == 1
コード例 #13
0
 def test_tf2onnx_save_onnx(self):
     with util.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             TF_MODELS["identity"].path, "--onnxrt", "--model-type=frozen",
             "--save-onnx", outpath.name
         ])
         assert is_file_non_empty(outpath.name)
         assert onnx.load(outpath.name)
コード例 #14
0
 def test_int8_calibration_base_class(self, base_class):
     cmd = [
         ONNX_MODELS["identity"].path, "--trt", "--int8",
         "--calibration-base-class", base_class
     ]
     if mod.version(trt.__version__) >= mod.version("7.0"):
         cmd += ["--onnxrt"]
     run_polygraphy_run()
コード例 #15
0
 def test_polygraphy_run_gen_script(self):
     with tempfile.NamedTemporaryFile(mode="w") as f:
         run_polygraphy_run(["--gen-script={:}".format(f.name), ONNX_MODELS["identity"].path])
         with open(f.name, "r") as script:
             print(script.read())
         env = copy.deepcopy(os.environ)
         env.update({"PYTHONPATH": ROOT_DIR})
         check_subprocess(sp.run([sys.executable, f.name], env=env))
コード例 #16
0
 def test_plugins(self):
     run_polygraphy_run([
         ONNX_MODELS["identity"].path,
         "--trt",
         "--plugins",
         "nvinfer_plugin.dll"
         if sys.platform.startswith("win") else "libnvinfer_plugin.so",
     ])
コード例 #17
0
 def test_onnx_rt_save_onnx(self):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--onnxrt", "--save-onnx",
             outpath.name
         ])
         assert is_file_non_empty(outpath.name)
         assert onnx.load(outpath.name)
コード例 #18
0
 def test_tf_save_timeline(self):
     with tempfile.NamedTemporaryFile() as outpath:
         run_polygraphy_run([
             TF_MODELS["identity"].path, "--tf",
             "--gpu-memory-fraction=0.5", "--save-timeline", outpath.name
         ])
         timelines = glob.glob(os.path.join(outpath.name, "*"))
         for timeline in timelines:
             assert is_file_non_empty(timeline)
コード例 #19
0
ファイル: test_surgeon.py プロジェクト: leo-XUKANG/TensorRT-1
def test_polygraphy_surgeon_extract_fallback_shape_inference():
    with tempfile.NamedTemporaryFile() as modelpath:
        # Force fallback shape inference by disabling ONNX shape inference
        run_polygraphy_surgeon([
            "extract", ONNX_MODELS["identity_identity"].path, "-o",
            modelpath.name, "--inputs", "identity_out_0,auto,auto",
            "--outputs", "identity_out_2,auto", "--no-shape-inference"
        ])
        run_polygraphy_run([modelpath.name, "--model-type=onnx", "--onnxrt"])
コード例 #20
0
def test_polygraphy_precision_worst_first_sanity():
    with tempfile.NamedTemporaryFile() as outpath:
        run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--onnxrt", "--save-results",
            outpath.name, "--onnx-outputs", "mark", "all"
        ])
        run_polygraphy_precision([
            "worst-first", ONNX_MODELS["identity"].path, "--golden",
            outpath.name, "--int8", "--trt-outputs", "mark", "all"
        ])
コード例 #21
0
ファイル: test_surgeon.py プロジェクト: leo-XUKANG/TensorRT-1
def test_polygraphy_surgeon_sanity():
    with tempfile.NamedTemporaryFile(
    ) as configpath, tempfile.NamedTemporaryFile() as modelpath:
        run_polygraphy_surgeon(
            ["prepare", ONNX_MODELS["identity"].path, "-o", configpath.name])
        run_polygraphy_surgeon([
            "operate", ONNX_MODELS["identity"].path, "-c", configpath.name,
            "-o", modelpath.name
        ])
        run_polygraphy_run([modelpath.name, "--model-type=onnx", "--onnxrt"])
コード例 #22
0
def test_polygraphy_precision_linear_sanity():
    with tempfile.NamedTemporaryFile() as outpath:
        run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--onnxrt", "--save-results",
            outpath.name
        ])
        run_polygraphy_precision([
            "linear", ONNX_MODELS["identity"].path, "--golden", outpath.name,
            "--int8"
        ])
コード例 #23
0
    def test_show_tactics(self, case):
        with util.NamedTemporaryFile() as replay:
            model_name, expected = case

            run_polygraphy_run([ONNX_MODELS[model_name].path, "--trt", "--save-tactics", replay.name])
            status = run_polygraphy_inspect(["tactics", replay.name], disable_verbose=True)

            expected = dedent(expected).strip()
            actual = status.stdout

            check_lines_match(actual, expected, should_check_line=lambda line: "Algorithm: " not in line)
コード例 #24
0
 def test_tactic_replay(self):
     with tempfile.NamedTemporaryFile() as tactic_replay:
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--trt", "--save-tactics",
             tactic_replay.name
         ])
         assert is_file_non_empty(tactic_replay.name)
         run_polygraphy_run([
             ONNX_MODELS["identity"].path, "--trt", "--load-tactics",
             tactic_replay.name
         ])
コード例 #25
0
 def test_trt_layerwise_outputs(self):
     with tempfile.NamedTemporaryFile() as outfile0:
         run_polygraphy_run([
             ONNX_MODELS["identity_identity"].path, "--trt",
             "--trt-outputs", "mark", "all", "--save-results", outfile0.name
         ])
         results = misc.pickle_load(outfile0.name)
         [result] = list(results.values())[0]
         assert len(result) == 2
         assert "identity_out_0" in result
         assert "identity_out_2" in result
コード例 #26
0
 def test_explicit_profile_implicit_runtime_shape(self):
     run_polygraphy_run([
         ONNX_MODELS["dynamic_identity"].path,
         "--trt",
         "--onnxrt",
         "--trt-min-shapes",
         "X:[1,2,1,1]",
         "--trt-opt-shapes",
         "X:[1,2,1,1]",
         "--trt-max-shapes",
         "X:[1,2,1,1]",
     ])
コード例 #27
0
    def test_save_load_outputs(self, tmp_path):
        OUTFILE0 = os.path.join(tmp_path, "outputs0.pkl")
        OUTFILE1 = os.path.join(tmp_path, "outputs1.pkl")
        run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--onnxrt", "--save-results",
            OUTFILE0
        ])
        run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--onnxrt", "--save-results",
            OUTFILE1
        ])

        status = run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--onnxrt", "--load-results",
            OUTFILE0, OUTFILE1
        ])
        assert "Difference is within tolerance" in status.stdout + status.stderr  # Make sure it actually compared stuff.

        # Should work with only one file
        status = run_polygraphy_run(
            [ONNX_MODELS["identity"].path, "--load-results", OUTFILE0])
        assert "Difference is within tolerance" not in status.stdout + status.stderr  # Make sure it DIDN'T compare stuff.

        # Should work even with no runners specified
        status = run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--load-results", OUTFILE0, OUTFILE1
        ])
        assert "Difference is within tolerance" in status.stdout + status.stderr  # Make sure it actually compared stuff.

        # Should work even when comparing a single runner to itself.
        status = run_polygraphy_run([
            ONNX_MODELS["identity"].path, "--load-results", OUTFILE0, OUTFILE0
        ])
        assert "Difference is within tolerance" in status.stdout + status.stderr  # Make sure it actually compared stuff.
コード例 #28
0
 def test_explicit_profile_opt_runtime_shapes_differ(self):
     run_polygraphy_run([
         ONNX_MODELS["dynamic_identity"].path,
         "--trt",
         "--onnxrt",
         "--input-shapes",
         "X:[1,2,2,2]",
         "--trt-min-shapes",
         "X:[1,2,1,1]",
         "--trt-opt-shapes",
         "X:[1,2,3,3]",
         "--trt-max-shapes",
         "X:[1,2,4,4]",
     ])
コード例 #29
0
    def test_data_loader_script_calibration(self):
        with tempfile.NamedTemporaryFile("w+", suffix=".py") as f:
            f.write(
                dedent("""
                    import numpy as np

                    def load_data():
                        for _ in range(5):
                            yield {"x": np.ones((1, 1, 2, 2), dtype=np.float32) * 6.4341}
                    """))
            f.flush()

            run_polygraphy_run([
                ONNX_MODELS["identity"].path, "--trt", "--int8",
                "--data-loader-script", f.name
            ])
コード例 #30
0
 def test_multiple_profiles(self):
     run_polygraphy_run([
         ONNX_MODELS["dynamic_identity"].path,
         "--trt",
         "--onnxrt",
         "--trt-min-shapes",
         "X:[1,2,1,1]",
         "--trt-opt-shapes",
         "X:[1,2,1,1]",
         "--trt-max-shapes",
         "X:[1,2,1,1]",
         "--trt-min-shapes",
         "X:[1,2,4,4]",
         "--trt-opt-shapes",
         "X:[1,2,4,4]",
         "--trt-max-shapes",
         "X:[1,2,4,4]",
     ])