micrograd icon indicating copy to clipboard operation
micrograd copied to clipboard

Does it make sense to cache the result of topological sort?

Open sayanb opened this issue 9 months ago • 1 comments

Every time backward() is called, it performs a topological sort. On a very large network with multiple backward passes, this could be computationally very expensive. Does it make sense to cache the result of the topological sort just once and use it every subsequent time, since the structure of the network does not change between multiple forward and backward passes?

sayanb avatar Apr 01 '25 13:04 sayanb

well from what I understand from karpathy's video for every forward pass the graph is rebuilt because the value is changing, hence the backward pass should always create a new topological order since the graph structure is different

s-adhit avatar May 11 '25 20:05 s-adhit