Reparametrization in Keras to Pytorch

Hello everyone! Does anyone know how to convert this reparametrization function to pytorch? In particular, I don’t know how to properly do the tf.random.normal(shape=(batch, latent_dim)) in pytorch.

batch, latent_dim = z_mean.shape
epsilon = tf.random.normal(shape=(batch, latent_dim))
 z = z_mean + tf.math.exp(0.5 * z_logsigma) * epsilon

On another topic, does anyone know which is the best alternative for tf.nn.sigmoid_cross_entropy_with_logits() in pytorch?

Thank you

Ok so for the first function you could do something like this

epsilon = torch.normal(0,1, size=(batch, latent_dim))
z = z_mean + torch.exp(0.5 * z_logsigma) * epsilon

and for the loss you can use BCE with logits loss here.