Hi ptrblck,
Thanks! That clarifies it a bit more.
However, I don’t understand why this error is being raised. In my case, it’s when I call the backward() function on my loss I think. Some background on my task: technically speaking, I’m working on neural machine translation, linguistically speaking I’m reconstructing on the sound level. Let me know, if that is relevant. Can you help me shoot this error? Or do I open a new thread?
for epoch in range(num_epochs):
    print(f"[Epoch {epoch} / {num_epochs}]")
    
    reconstructed_word = reconstruct_word(model, word1)
    
    with open('out.txt', 'a') as f:
        print(f"Reconstruct example words {word1, word2, word3, word4, word5,} \n as {reconstructed_word}", file=f)

    model.train()
    optimizer.zero_grad()
    model.eval()    
    
    for batch_idx, element in enumerate(train_iterator):
                #Get input and targets
                #batch_idx is the iterator and elememt are the element in train_iterator
                inp_data = element.italian.to(device)
                targets = element.latin.to(device)
    
                #Forward propagation
                output = model(inp_data, targets)
                print("Output shape:", output.shape)
                print("Target shape:", targets.max(), targets.min())
                
                output = output[1:].reshape(-1, output.shape[2])
                targets = targets[1:].reshape(-1)
                print("Output shape 2:", output.shape)
                print("Target shape 2:", targets.max(), targets.min())
                
         
                optimizer.zero_grad()
                loss = criterion(output, targets) #error gets thrown either here or down at loss.backward()
                print("Loss:", loss)

                loss.backward()

                torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1)
    
                optimizer.step()
             

Best,
hizella