There is no option for the nn.Dropout layer or the functional F.dropout call.
However, you could simply create a mask using torch.bernoulli and create a custom dropout layer.
Here is a simple exmaple:
x = torch.randn(10)
p = 0.5
probs = torch.cat((torch.ones(2,), torch.tensor([p]*8))) # don't zero out first 2 values
mask = torch.bernoulli(probs)

out = x * mask

Don’t forget to add the scaling during training or validation as is done for the vanilla dropout. Otherwise the expected values will differ when you disable your dropout and the model might perform bad.