Why does this print 2 different values ?
import torch
import torch.nn as nn
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class Test(nn.Module):
def __init__(self):
super().__init__()
self.lin3 = nn.Linear(5, 400)
self.rnn2 = nn.GRU(1, 100, num_layers=2, bidirectional=True, batch_first=True)
def forward(self, discrete_code):
c2 = self.lin3(discrete_code/5).reshape((4, discrete_code.shape[0], 100))
x, _ = self.rnn2(torch.zeros(discrete_code.shape[0], 64, 1).to(device), c2)
return x[:1, 0, 0]
model = Test().to(device)
candidats = torch.randn(10, 5).to(device)
print(model(candidats[:1])) # e.g., tensor([0.1234])
print(model(candidats[:2])) # e.g., tensor([0.1234]) EXPECTED SAME