Here is a little piece of code that works without any problem for me.
import torch
from torch import nn
class Model(nn.Module) :
    def __init__(self, nUser, edim_u):
        super(Model, self).__init__()
        self.U = nn.Embedding(nUser, edim_u)
        #criterion = nn.CrossEntropyLoss()
        #optimizer = torch.optim.SGD(self.parameters(), lr = 3e-4)
        
model = Model(2, 1)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr = 3e-4)