The first part of the z calculation seems to be xi.
Wouldn’t it work if you just initialize state with Variable(torch.ones(batch_size*3, hidden_size)) and use z = Variable(torch.randn(batch_size*3, compressed_size)) * ...?
In this way a simple call to myfunc would result in a Tensor with dims [3, 5].