Sorry for late reply.Yes the backpropagation is working but the first linear layer gradient is always zero(I can’t get the reason behind it, if you can suggest something it will be helpful). I still have some confusion which I want to understand.

Do we need to multiply the mask after getting the activation output from linear layer like f1=nn.Linear(), then mask_output = mask * self.Relu(f1(x)) or proceed in different way where the ouput of the previous layer x needs  to be mutipled first with mask like

#x is the output of the previous layer
mask_out = x*mask
f1=nn.Linear()
out1 = self.Relu(f1(mask_out)))


Since we are using our own mask as dropout so at the time of evaluation so are passing a variable to the model for checking whether we are in train or eval state using model.eval(). is this correct?

3)Also since pytorch uses dropout as inverted dropout so how do we handle this case for train and eval case using our own mask.