liuliu / swift-diffusion

BSD 3-Clause "New" or "Revised" License
429 stars 33 forks source link

Wrapping the code in different graph.withNoGrad spikes up the memory usage. why? #36

Open ghost opened 1 year ago

ghost commented 1 year ago

run now in the txt2img example you have one big graph.withNoGrad and the for loop is inside it.

rather than that, if i have one graph.withNoGrad for text model stuff , and one graph.withNoGrad for each iteration, ie. if i have graph.withNoGrad inside the for loop. Than it increases the memory usage from 3GB to 4.2GB/

what could be the reason? all the .run etc are still inside graph.withNoGrad , just different graph.withNoGrad

liuliu commented 1 year ago

Yes, in theory. But there could be some other computations book-kept somewhere. Without seeing the code, hard for me to tell. You can insert https://liuliu.github.io/s4nnc/documentation/nnc/dynamicgraph/statistics-swift.property to see whether you have computations / tensors recorded in between (graph.statistics). It also could be a bug that some variables we should be able to garbage collect but fail to.

ghost commented 1 year ago

Thanks, ill take a look