Your code seems to work correctly and I can use it to enable or disable the dropout layer:
def apply_dropout(m):
    if type(m) == nn.Dropout:
        m.train()

def de_apply_dropout(m):
    if type(m) == nn.Dropout:
        m.eval()

class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
        self.lin = nn.Linear(10, 10)
        self.drop = nn.Dropout()
        
    def forward(self, x):
        x = self.lin(x)
        x = self.drop(x)
        return x

model = MyModel()
x = torch.randn(100, 10)
out = model(x)
print((out==0.0).sum())
> tensor(480)

model.eval()
out = model(x)
print((out==0.0).sum())
> tensor(0)

model.train()
out = model(x)
print((out==0.0).sum())
> tensor(501)

model.apply(de_apply_dropout)
out = model(x)
print((out==0.0).sum())
> tensor(0)

model.apply(apply_dropout)
out = model(x)
print((out==0.0).sum())
> tensor(475)