...
loss = 0
if cond1:
    loss += torch.mean(torch.sum(pred1* torch.log(pred1)),1))
if cond2:
    loss += torch.mean(torch.sum(pred2* torch.log(pred2)),1))
loss.backward()

As far as I know this is because the loss is initialized with int.
Unresolved attribute reference 'backward' for class 'int' less... (Ctrl+F1) 
Inspection info: This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.