diff --git a/benchmarks/operator_benchmark/benchmark_pytorch.py b/benchmarks/operator_benchmark/benchmark_pytorch.py index 0371c74b7f2..fe558dc8890 100644 --- a/benchmarks/operator_benchmark/benchmark_pytorch.py +++ b/benchmarks/operator_benchmark/benchmark_pytorch.py @@ -94,11 +94,17 @@ class TorchBenchmarkBase(object): """ this is a globally unique name which can be used to label a specific test """ + + # This is a list of attributes which will not be included + # in the test name. + skip_key_list = ['device'] + test_name_str = [] for key in kargs: value = kargs[key] test_name_str.append( - key + str(value if type(value) != bool else int(value))) + ('' if key in skip_key_list else key) + + str(value if type(value) != bool else int(value))) name = (self.module_name() + '_' + '_'.join(test_name_str)).replace(" ", "") return name diff --git a/benchmarks/operator_benchmark/pt/add_test.py b/benchmarks/operator_benchmark/pt/add_test.py index 3be7fb27749..1e4c5222cb9 100644 --- a/benchmarks/operator_benchmark/pt/add_test.py +++ b/benchmarks/operator_benchmark/pt/add_test.py @@ -11,33 +11,49 @@ import torch # Configs for PT add operator add_long_configs = op_bench.cross_product_configs( M=[8, 64, 128], - N=range(2, 10, 3), - K=[2 ** x for x in range(0, 3)], + N=range(2, 128, 64), + K=[8 ** x for x in range(0, 3)], + device=['cpu', 'cuda'], tags=["long"] ) add_short_configs = op_bench.config_list( + attr_names=["M", "N", "K"], attrs=[ [64, 64, 64], [64, 64, 128], ], - attr_names=["M", "N", "K"], - tags=["short"], + cross_product_configs={ + 'device': ['cpu', 'cuda'], + }, + tags=["short"], ) class AddBenchmark(op_bench.TorchBenchmarkBase): - def init(self, M, N, K): - self.input_one = torch.rand(M, N, K) - self.input_two = torch.rand(M, N, K) + def init(self, M, N, K, device): + self.input_one = torch.rand(M, N, K, device=device, requires_grad=self.auto_set()) + self.input_two = torch.rand(M, N, K, device=device, requires_grad=self.auto_set()) self.set_module_name("add") def forward(self): return torch.add(self.input_one, self.input_two) +# The generated test names based on add_short_configs will be in the following pattern: +# add_M8_N16_K32_devicecpu +# add_M8_N16_K32_devicecuda +# add_M8_N16_K32_devicecpu_bwdall +# add_M8_N16_K32_devicecpu_bwd1 +# add_M8_N16_K32_devicecpu_bwd2 +# add_M8_N16_K32_devicecuda_bwdall +# add_M8_N16_K32_devicecuda_bwd1 +# add_M8_N16_K32_devicecuda_bwd2 +# ... +# Those names can be used to filter tests. op_bench.generate_pt_test(add_long_configs + add_short_configs, AddBenchmark) +op_bench.generate_pt_gradient_test(add_long_configs + add_short_configs, AddBenchmark) if __name__ == "__main__":