MCPcopy Create free account
hub / github.com/pytorch/pytorch / linear_test

Method linear_test

test/test_throughput_benchmark.py:36–68  ·  view source on GitHub ↗
(self, Module, profiler_output_path="")

Source from the content-addressed store, hash-verified

34
35class TestThroughputBenchmark(TestCase):
36 def linear_test(self, Module, profiler_output_path=""):
37 D_in = 10
38 H = 5
39 D_out = 15
40 B = 8
41 NUM_INPUTS = 2
42
43 module = Module(D_in, H, D_out)
44
45 inputs = []
46
47 for i in range(NUM_INPUTS):
48 inputs.append([torch.randn(B, D_in), torch.randn(B, D_in)])
49 bench = ThroughputBenchmark(module)
50
51 for input in inputs:
52 # can do both args and kwargs here
53 bench.add_input(input[0], x2=input[1])
54
55 for i in range(NUM_INPUTS):
56 # or just unpack the list of inputs
57 module_result = module(*inputs[i])
58 bench_result = bench.run_once(*inputs[i])
59 torch.testing.assert_close(bench_result, module_result)
60
61 stats = bench.benchmark(
62 num_calling_threads=4,
63 num_warmup_iters=100,
64 num_iters=1000,
65 profiler_output_path=profiler_output_path,
66 )
67
68 print(stats)
69
70
71 def test_script_module(self):

Callers 3

test_script_moduleMethod · 0.95
test_moduleMethod · 0.95
test_profilingMethod · 0.95

Calls 8

add_inputMethod · 0.95
run_onceMethod · 0.95
benchmarkMethod · 0.95
ThroughputBenchmarkClass · 0.90
ModuleClass · 0.70
rangeFunction · 0.50
appendMethod · 0.45
randnMethod · 0.45

Tested by

no test coverage detected