I don’t know how your models are implemented, so in case you are stuck debugging it, please post a minimal executable code snippet so that I can take a look.
Could you try to minimize the code and try to isolate the failing part only, please?
Based on your description it seems that the loss calculation is wrong, so I would guess that the model definition as well as some random data would be sufficient to reproduce the issue.
Hello!Do you have time to help? My report here is wrong
from option import Options
When I use pip install option, I still report an error
Traceback (most recent call last):
File "/home/pxg/DAN/DANet05/experiments/segmentation/train.py", line 24, in <module>
from option import Options
ImportError: cannot import name 'Options'
It seems the options Python package cannot import the Options module. In case you are using a script with the same name, rename it and try to rerun the import.
Hi, I am getting an AttributeError: ‘tuple’ object has no attribute ‘loss’. I provided the code snippet where error is, but unable to rectify it.
for batch in loop:
# initialize calculated gradients (from prev step)
optim.zero_grad()
# pull all tensor batches required for training
input_ids = batch['input_ids'].to(device)
attention_mask = batch['attention_mask'].to(device)
token_type_ids = batch['token_type_ids'].to(device)
labels = batch['labels'].to(device)
# process
outputs = model(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
# extract loss
loss = outputs.loss # Error line
# calculate loss for every parameter that needs grad update
loss.backward()
Your model’s forward method seems to return a tuple, which you could index to get the entries, while it seems you are expecting to get an object containing a .loss attribute.
Could you check the return statement in forward and see what is returned?