Hi,
I’m not sure that I understand this loss function and how to use it though, as long as I understand,
a target variable (in your snippet, c) is assumed to be shape of (batch_size,) and representing whether every single sample in x1 is similar to the counterpart in x2.
For example, in your second case which failed to calculate a loss, c was supposed to represent one sample of a shape of (2, 10, 10) is similar to the counterpart of b shape of (2, 10, 10) or not.
Also, I guess the reason why backward computations are unavailable is that inputs to the loss function did not go through any operations.
For example, the loss computed using 2 vectors from embedding layer can propagate gradient like this.
In [9]: l = nn.Embedding(10, 20)

In [10]: a = l(torch.LongTensor([0]))

In [11]: a.size()
Out[11]: torch.Size([1, 20])

In [12]: b = l(torch.LongTensor([2]))

In [13]: loss = F.cosine_embedding_loss(a, b, torch.ones(1, requires_grad=False))

In [14]: loss.backward()

In [15]: exit

Hope this will help you a bit.