# Solving error for mismatch tensor size

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-error-for-mismatch-tensor-size%2F81637%3E%5C
**Category:** 🤗Transformers\
**Created:** [April 14, 2024, 3:49am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-error-for-mismatch-tensor-size%2F81637 "2024-04-14T03:49:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarshDubey](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@HarshDubey](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHarshDubey)%5C
**Post date:** [April 14, 2024, 3:49am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsolving-error-for-mismatch-tensor-size%2F81637%2F1 "2024-04-14T03:49:00Z")

</div>

code:  
num\_epochs = 100  
loss\_history =  
for i in range(num\_epochs):  
model.train()  
total\_loss =0.0  
for batch in train\_dataloader:  
pv, fv, ptf, ftf = batch  
fv = fv.unsqueeze(-1)  
optimiser.zero\_grad()  
pom = torch.ones\_like(pv)  
ftf = ftf.view(ptf.shape[0], fv.shape[1], ptf.shape[2])  
outputs = model(past\_values=pv,past\_time\_features=ptf,past\_observed\_mask=pom,future\_values=fv,future\_time\_features=ftf)  
loss = outputs.loss  
loss.backward()  
optimiser.step()  
total\_loss +=loss.item()  
avg\_loss = total\_loss/len(train\_dataloader)  
loss\_history.append(avg\_loss)

* * *

RuntimeError Traceback (most recent call last)  
 in \<cell line: 3\>()  
10 pom = torch.ones\_like(pv)  
11 ftf = ftf.view(ptf.shape[0], fv.shape[1], ptf.shape[2])  
—\> 12 outputs = model(past\_values=pv,past\_time\_features=ptf,past\_observed\_mask=pom,future\_values=fv,future\_time\_features=ftf)  
13 loss = outputs.loss  
14 loss.backward()

14 frames  
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/linear.py in forward(self, input)  
114  
115 def forward(self, input: Tensor) → Tensor:  
 → 116 return F.linear(input, self.weight, self.bias)  
117  
118 def extra\_repr(self) → str:

RuntimeError: mat1 and mat2 shapes cannot be multiplied (3072x46 and 34x64)
