mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
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
31 lines
466 B
Python
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()
|