How to solve error: 'All input tensors must be on the same device. Received cuda:0 and cpu'

There might be some syntax issue since you are applying it directly in the for loop. Try this and see if it works:

---> 18         for idx, (img, label_attr, label_idx) in enumerate(final_train_generator):
     19             l = train_agent.fit_final_classifier(img.cuda(), label_attr.cuda(), label_idx.cuda())
     20             syn_loss += l