Either use the proposed approach from your cross post 1 or initialize the layers first and use a switch in the custom forward method.


I would write a custom dropout layer, which accepts an additional flag to resample the mask.