|
| 1 | +import torch |
| 2 | +import torch.utils.benchmark as benchmark |
| 3 | +import pickle |
| 4 | + |
| 5 | +fuzzer = benchmark.Fuzzer(parameters=[ |
| 6 | + benchmark.FuzzedParameter('n', minval=4, maxval=16, distribution='uniform'), |
| 7 | + benchmark.FuzzedParameter('c', minval=4, maxval=256, distribution='uniform'), |
| 8 | + benchmark.FuzzedParameter('d', minval=8, maxval=256, distribution='uniform'), |
| 9 | + benchmark.FuzzedParameter('h', minval=8, maxval=256, distribution='uniform'), |
| 10 | + benchmark.FuzzedParameter('w', minval=8, maxval=256, distribution='uniform'), |
| 11 | +], |
| 12 | + tensors=[ |
| 13 | + benchmark.FuzzedTensor('x', |
| 14 | + size='ncdhw', |
| 15 | + min_elements=12, |
| 16 | + max_elements=10000000, |
| 17 | + cuda=True, |
| 18 | + dtype=torch.half, |
| 19 | + max_allocation_bytes=1_000_000_000) |
| 20 | + ], |
| 21 | + seed=42) |
| 22 | + |
| 23 | +res = [] |
| 24 | + |
| 25 | +for kernel_size in [2, 3, 5]: |
| 26 | + for tensors, tensor_params, params in fuzzer.take(20): |
| 27 | + sub_label = str(tensors['x'].size()) |
| 28 | + res.append( |
| 29 | + benchmark.Timer(stmt=f'torch.nn.functional.max_pool3d(x, {kernel_size})', |
| 30 | + setup='', |
| 31 | + globals=tensors, |
| 32 | + label=f'max_pool3d, {kernel_size=}', |
| 33 | + sub_label=sub_label, |
| 34 | + description=f'{torch.__version__}').blocked_autorange(min_run_time=0.1)) |
| 35 | + |
| 36 | +torch_ver = str(torch.__version__) |
| 37 | +torch_git_ver = torch_ver[torch_ver.index('+') + 1:] |
| 38 | + |
| 39 | +with open(f'{torch_git_ver}.pkl', 'wb') as f: |
| 40 | + pickle.dump(res, f) |
| 41 | + |
| 42 | +compare = benchmark.Compare(res) |
| 43 | +# compare.colorize() |
| 44 | +compare.print() |
0 commit comments