Files
pytorch/benchmarks/dynamo/microbenchmarks/fx_microbenchmarks.py
Jason Ansel 9aa3fedb75 Slightly faster FX graph iterator (#121611)
Before:
```
iterating over 100000000 FX nodes took 5.9s (16830686 nodes/s)
```

After:
```
iterating over 100000000 FX nodes took 5.0s (19937698 nodes/s)
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/121611
Approved by: https://github.com/oulgen
2024-03-11 20:00:19 +00:00

31 lines
466 B
Python

import timeit
import torch.fx
N = 100000
K = 1000
def huge_graph():
def fn(x):
for _ in range(N):
x = x.sin()
return x
return torch.fx.symbolic_trace(fn)
def main():
g = huge_graph()
def fn():
for n in g.graph.nodes:
pass
t = min(timeit.repeat(fn, number=K, repeat=3))
print(f"iterating over {N*K} FX nodes took {t:.1f}s ({N*K/t:.0f} nodes/s)")
if __name__ == "__main__":
main()