Error: grad can be implicitly created only for scalar outputs

Once I use what is suggested above for the same issue (multiple input dimensions), I receive the following:

ValueError: only one element tensors can be converted to Python scalars

in the part,

if show_progress:
            iterator.set_postfix(loss=loss.item())

and few lines later:

return loss.detach().cpu().item()

throws ValueError: only one element tensors can be converted to Python scalars

any suggestions?