I am trying to backpropagate through a Bernoulli sample. A simplified version of my code is:
...
parameter = torch.nn.Parameter(torch.ones(8), requires_grad=True) # parameters to learn
prob = torch.sigmoid(parameter) #sigmoid to make a probability [0,1]
bern_sample = torch.distributions.bernoulli.Bernoulli(prob).sample() # draw a sample 

loss = torch.sum(bern_sample)
loss.backward()

Intuitively the variable parameter should be updated by gradient descent in order to make all probabilities close to 0, i.e. bern_sample should contain all zeros.
However when I check gradients wrt to parameter, i.e. parameter.grad, they are None.
What am I doing wrong?
Thanks in advance