Backpropagation with for loops

Hi everyone :slight_smile:

I have a conceptual question regarding for loops in the forward method of a Convolutional Neural Network and the corresponding backpropagation.

I read that when you want to loop over modules in the forward method you can make use of the nn.ModuleList class. But what if I would like to use a for loop for something else? How does this influence the backpropagation? Say I would like to loop over the channels of an image and process them individually, does that influence the backpropagation?

Any help is very much appreciated!

All the best
snowe

It “influences” the computation graph in the sense that each operation would be added to the graph and the backpropagation should just work. It shouldn’t be necessary to take extra steps and could just use for loops etc. without a problem.

2 Likes

Thank you @ptrblck :slight_smile:

I was worrying that it might only use the last loop or so or overwrite them but nice to hear otherwise!