It should work. However, a more decent way I would say is to use torch.nn.functional.dropout http://pytorch.org/docs/nn.html?highlight=dropout#torch.nn.functional.dropout 69
like
x = F.dropout(x, p, self.is_training)