The problem arises, as the cosine similarity between zero vectors is undefined.
In PyTorch nn.CosineEmbeddingLoss returns apparently a loss of 1 for zero tensors:
loss = torch.nn.CosineEmbeddingLoss(reduction='none')
b = torch.tensor([[0.,0.,0.],[0.,1.,0.],[0.,0.,0.]])
print(loss(b, b, torch.ones_like(b)))
> tensor([[1., 0., 1.],
        [1., 0., 1.],
        [1., 0., 1.]])

which would return 0.6667 if you calculate its mean.