Thanks for your solution. it worked. but I am not sure your implementation works same as BCEWithLogitsLoss ? Because I saw it like Crossentropywithloss function. My Expected loss function must be BCEWithLogitsLoss