RuntimeError: invalid argument 13

Hi Pytorch fans ;D

I am running an encoder - decoder architecture and I am stuck on this error:

RuntimeError: invalid argument 13: ldc should be at least max(1, m=0), but have 0 at /Users/soumith/mc3build/conda-bld/pytorch_1549593514549/work/aten/src/TH/generic/THBlas.cpp:334

The traceback is the following:

File “/Users/…/code/classes/encoder_decoder.py”, line 130, in forward
x = self.attn_linear(x.view(-1, self.hidden_size * 2 + self.T - 1)) # (batch_size * input_size) * 1

File “/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 489, in call
result = self.forward(*input, **kwargs)

File “/anaconda3/lib/python3.6/site-packages/torch/nn/modules/linear.py”, line 67, in forward
return F.linear(input, self.weight, self.bias)

File “/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py”, line 1352, in linear
ret = torch.addmm(torch.jit._unwrap_optional(bias), input, weight.t())

Any hint on how to tackle it is welcome!
Thank you

Also (sporadically) running into a similar error in the same .cpp file (I’m using a loss function based on stochastic indices into an embedding bank on Ubuntu 18.04). Would love to hear about these errors.

File “pytorch_fun.py”, line 541, in

loss = LALoss(embeddings, emb_idx, toy_bank, cluster_I, args, val=False, centroid_index=centroid_index)

File “pytorch_fun.py”, line 504, in LALoss

NNL_close_background -= torch.log(torch.exp((bank[list(close_background_I[emb_i])] @ embeddings[emb_i].unsqueeze(-1))/args['tau']).sum())

RuntimeError: invalid argument 13: ldc should be at least max(1, m=0), but have 0 at /pytorch/aten/src/TH/generic/THBlas.cpp:367

Update: I believe this error is occurring when matrix multiplications are attempted with tensors having a first dimension shape value of zero (i.e. when the list index into bank has a length of zero) with the other tensor having non-zero shape values in both of the dimensions of the tensor having a zero shape value (only when unsqueeze is used; see below). I was not aware that PyTorch supported tensors with shape values of zero.

Minimal code to reproduce:

a = torch.ones((4,4))
b = torch.ones(4)

a@b
tensor([4., 4., 4., 4.])
a[[]]@b
>>>tensor([])
a[[]]@b.unsqueeze(-1)
Traceback (most recent call last):
File “”, line 1, in
RuntimeError: invalid argument 13: ldc should be at least max(1, m=0), but have 0 at /pytorch/aten/src/TH/generic/THBlas.cpp:367

I encountered the same problem using v1.1.0 stable version. When training on GPU, everything works fine. When I use CPU, then the error occurs.