I fixed the problem.
I must change the name of the loss function
from     loss = loss(output, labels.float())
to lossfun = dnn.BCEWithLogitsLoss()  or any name other than loss.
does any one know why this name make the problem?