The second approach should have worked.
Could you add the .long() cast again and print the type of labels in your training loop?
PS: I’ve formatted your code as it was a bit difficult to read. You can add code using three backticks `.