Skip to content

Commit

Permalink
Add compile time smoketest for foreach (pytorch#126136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlazos authored and pytorchmergebot committed May 14, 2024
1 parent a8eac0e commit 7ed67cd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/inductor/test_compiled_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,25 @@ def test_get_value_on_static_address(self):

self.assertEqual(ret_val, x)

# compile a large foreach op and verify
# that the time taken is within an expected range
@requires_cuda
def test_compile_time_smoketest(self):
import time

xs = [torch.ones(2, 2, device="cuda") for _ in range(100)]
ys = [torch.ones(2, 2, device="cuda") for _ in range(100)]

@torch.compile
def fn(xs, ys):
return torch._foreach_add(xs, ys)

start = time.perf_counter()
fn(xs, ys)
end = time.perf_counter()

self.assertLess(end - start, 90)


for optim_cls, name, kwargs, scheduler_cls in COMPILED_OPT_KWARG_DB:
setattr(
Expand Down

0 comments on commit 7ed67cd

Please sign in to comment.