MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / replay_dir

Function replay_dir

tools/Polygraphy/tests/tools/conftest.py:66–109  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

64
65@pytest.fixture(scope="session", params=["", "subdir"])
66def replay_dir(request):
67 def fake_context(name, num_inputs=1, num_outputs=1):
68 return FakeAlgorithmContext(name=name, num_inputs=num_inputs, num_outputs=num_outputs)
69
70 def fake_algo(
71 implementation=6, tactic=0, num_io=2, tensor_format=trt.TensorFormat.LINEAR, dtype=trt.float32, strides=(1, 2)
72 ):
73 io_info = [
74 TensorInfo(
75 tensor_format=tensor_format, dtype=dtype, strides=strides, vectorized_dim=-1, components_per_element=1
76 )
77 ] * num_io
78 return FakeAlgorithm(algorithm_variant=FakeAlgorithmVariant(implementation, tactic), io_info=io_info)
79
80 def make_replay(tactic):
81 return TacticReplayData().add("layer0", Algorithm.from_trt(fake_context("layer0"), fake_algo(0, tactic)))
82
83 with tempfile.TemporaryDirectory() as dir:
84
85 def make_path(prefix, *args):
86 path = os.path.join(dir, prefix)
87 if request.param:
88 path = os.path.join(path, request.param)
89 path = os.path.join(path, *args)
90 return path
91
92 # Good tactics
93 save_json(make_replay(0), make_path("good", "0.json"))
94 save_json(make_replay(1), make_path("good", "1.json"))
95
96 # Bad tactics
97 save_json(make_replay(1), make_path("bad", "0.json"))
98 save_json(make_replay(2), make_path("bad", "1.json"))
99
100 EXPECTED_OUTPUT = dedent(
101 """
102 [I] Loaded {num} good tactic replays.
103 [I] Loaded {num} bad tactic replays.
104 [I] Found potentially bad tactics:
105 [I] Layer: layer0
106 Algorithms: ['(Implementation: 0, Tactic: 2) | Inputs: (TensorInfo(TensorFormat.LINEAR, DataType.FLOAT, (1, 2), -1, 1),) | Outputs: (TensorInfo(TensorFormat.LINEAR, DataType.FLOAT, (1, 2), -1, 1),)']
107 """
108 )
109 yield dir, EXPECTED_OUTPUT

Callers

nothing calls this directly

Calls 3

save_jsonFunction · 0.90
make_replayFunction · 0.85
make_pathFunction · 0.85

Tested by

no test coverage detected