Tangzy7
(Tangzy7)
December 18, 2018, 9:14am
#1
the model’s forward function is

```
def forward(self,x0, x1)
output1 = self.forward_once(x0)
output2 = self.forward_once(x1)
return output1,output2
```

So, are the following two implementations different？

```
output1,output2 = model(x0, x1)
loss = criterion (output1,output2)
loss.backward()
```

And here is the another way:

```
output1 = model.forward_once(x0)
output2 = model.forward_once(x1)
loss = criterion (output1,output2)
loss.backward()
```

Are they different?

ptrblck
December 18, 2018, 11:50am
#2
Both approaches should be equal, even though I would suggest to use the former, as this will call the internal `__call__`

method, which properly registers all hooks etc.
Do you see and differences between both?

Tangzy7
(Tangzy7)
December 19, 2018, 1:19am
#3
Yes. I tried the second one and got a overfitting. I didn’t try the first one, but just found the following implementation is also ok.

```
input_cat = torch.cat([x0,x1],0)
output_cat = model(input_cat )
loss = criterion (first half of output_cat , second half of output_cat)
```