Hi,
Since the sampling is non-differentiable with respect to the parameters it will not propagate any gradients.
But what you do here is a reparametrisation trick right? And so gradients will not flow back the torch.randn op (but that’s ok) and will flow as expected to x_var and x_mean.
If x_mean or x_var requires gradient, then z will require gradients as well. If they don’t, z won’t either.