Initializing variables inside the forward module


I have some cases where I have to initialize the variables inside the forward function of my network module. Is it okay?

One example case where I am feeling to do this is:-

If I am doing multi GPU training and I have a batch of bbox locations which i have to crop. Because of dynamic number of bboxs per tensor. I also pass the indices corresponding to each crop location. So, it is fine to initialize this indices variable before calling the forward. But in case of MultiGPU training, I might need to do this inside the forward.

It is indeed okay. :slight_smile: