can't infer device on benchmarked function with no args or kwargs (#133290)

when we call benchmarker.benchmark(fn, (), {}) it attempts to infer the device from the args and kwargs, which are both empty. in this case the default behavior is to assume CPU, since `is_cpu_device` is implemented as `all([x.device == "cpu" for x in ... if x is Tensor])`, and `all([]) == True`. I've added a PR that makes this raise an error, but we should just fix this one callsite first

Pull Request resolved: https://github.com/pytorch/pytorch/pull/133290
Approved by: https://github.com/eellison
This commit is contained in:
Nicolas Macchioni
2024-08-13 20:13:44 +00:00
committed by PyTorch MergeBot
parent dfc7c860e4
commit fa7ae6cdbc

View File

@ -21,7 +21,7 @@ class TestBench(TestCase):
cls._bench_fn = functools.partial(torch.nn.functional.linear, x, w)
def test_benchmarker(self):
res = benchmarker.benchmark(self._bench_fn, (), {})
res = benchmarker.benchmark_gpu(self._bench_fn)
log.warning("do_bench result: %s", res)
self.assertGreater(res, 0)