Thank you for your reply.
My input is in fact the output of my model ie the last fully connected layer (nn.Linear(…,nb_classes)). It works well when using criterion = nn.CrossEntropyLoss(). The problem appears only when using the loss function I have implemented.
If I give my model a batch composed of 2 images for instance, I obtain the following :
input = tensor([[-0.4151,  0.0702, -0.4210,  0.4268,  0.0183,  0.1305, -0.5303, -0.1792,
-0.6745, -0.0481, -0.2302],
[-0.0338, -0.3070, -0.8314,  0.3735,  0.4717, -0.2299, -0.4984, -0.1337,
-0.3467,  0.1117, -0.2985]], grad_fn=<ThAddmmBackward))
labels = tensor([0,10])
ksi = = torch.tensor([[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.],
[1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.]],requires_grad = True)
At the moment, my cost sensitive matrix is ones matrix because I just want to debug the code first.
I have  slightly modified my LogSoftmax function:
def LogSoftmax(input,labels,ksi):
layer = torch.empty(input.shape)
for j in range(input.shape[0]):
for i in range(input.shape[1]):
layer[j,i] = log(ksi[labels[j],i]*exp(input[j,i])) - log(sum([ksi[labels[j],k]*exp(input[j,k]) for k in range(len(ksi))]))
return layer