Important difference between Tensorflow and Pytorch
As can be seen above the shape of some of the layers differs this is due to the fact that in Pytorch the weight matrix is transposed compared to tensorflow (see this issue). This is as expected since Tensorflow uses the dot product where pytorch uses a matrix vector product for producing the outputs. When initializing weights using the same random seed you therefore have to use the following for pytorch:
Closed as the same behaviour is present when translating TF1 code to TF2 eager. This issue is not present when eager execution is disabled in TF2. The debugging continuous on this issue #9 .
Compare the weight matrixes (Tensorflow vs Pytorch)
Set random seeds to get same initial states and random numbers
Layer shape comparison
Gaussian actor
Lyapunov critic
Important difference between Tensorflow and Pytorch
As can be seen above the shape of some of the layers differs this is due to the fact that in Pytorch the weight matrix is transposed compared to tensorflow (see this issue). This is as expected since Tensorflow uses the dot product where pytorch uses a matrix vector product for producing the outputs. When initializing weights using the same random seed you therefore have to use the following for pytorch:
and for tensorflow:
When working with manually created layers you have to use the following syntax in pytorch:
and in tensorflow:
Check initial weights in tensorflow
The following code can be used to checkout the network weights in tensorflow (see this question):
In 877906f11a8d5fabb24929e8168ec6a278b0291f the weights, biases and seeds were set to be equal to aid in a comparison between tensorflow and pytorch.
Compare networks
Gaussian Actor
Pytorch:
Tensorflow:
Lyapunov Critic
Pytorch:
Tensorflow: