AttributeError: 'str' object has no attribute 'items'

Ok so it’s a dict. If I understand your code correctly, you want to apply to(device) to all values in the dict. You could do that like this:

targets = {k: v.to(device) for k, v in targets.items()}
1 Like