Hi Wjk!
The short answer is that score.max() > 1.0.



 Wjk666:

Then as for the bceloss, it occurs some error.
att = nn.Softmax(dim=-1)(-leakyrelu(a))



Because you calculate Softmax(), the last dimension of att will
sum to one, up to floating-point round-off error.


b = torch.ones(512, 14541, 4)
score = torch.einsum('bnk,bk->bn', [b, att])



You “contract” the last dimension of att with torch.ones().  That is,
you multiply the elements of att by 1.0 and then sum along the
last dimension.  Therefore the elements of score are all 1.0, up
to floating-point round-off error.
By default, pytorch prints out tensor values to 5 digits, so when
you print out score.max() you only see 1.0000.  Print out
score.max() - 1.0, and you will see a small number that is
slightly greater than zero.


bce = nn.BCELoss()
label = torch.full((512, 14541), 3.141592)
bce(score, label)



Here, you pass into BCELoss values that are (slightly, due to round-off
error) greater than one, so BCELoss raises the exception you posted:


RuntimeError: all elements of input should be between 0 and 1



Best.
K. Frank