Sampling
The
sample method generates samples from a distribution, and in this process, it does not consider the gradient of the parameters. This is used when differentiation through the sampling process is not necessary. On the other hand, rsample refers to reparameterization sampling, which enables gradient-based optimization through the sampling process (loss calculation Pathwise derivative).torch.distributions members
torch.distributions functions
Probability distributions - torch.distributions — PyTorch 2.3 documentation
The distributions package contains parameterizable probability distributions
and sampling functions. This allows the construction of stochastic computation
graphs and stochastic gradient estimators for optimization. This package
generally follows the design of the TensorFlow Distributions package.
https://pytorch.org/docs/stable/distributions.html
What is the difference between sample() and rsample()?
When I sample from a distribution in PyTorch, both sample and rsample appear to give similar results:
import torch, seaborn as sns
x = torch.distributions.Normal(torch.tensor([0.0]), torch.tensor(...
https://stackoverflow.com/questions/60533150/what-is-the-difference-between-sample-and-rsample

Seonglae Cho