What happens when two batches are passed through, does that create two graphs?

Say I passed b1 through my net like this:

y1 = my_net(b1)

Then, I immediately pass another batch to get a different output, like this:


Does that create two graphs?
I’m computing something based on previous two results and then doing backprop

some_function(y1, y2).backward()

Is this ‘safe’?

Hi John_Deterious,
This is safe. As long as y1 and y2 are retained in the memory, the graphs remain. It will be destroyed if you delete the tensors. Calling backward also destroys the graph, unless called with the “retain_graph=True” argument.

1 Like