Ho, it is a warning from the type checker? Because you define loss=0 and if both conditions are False, you would call .backward() on an int.
I guess you will need to either define loss as a Tensor to begin with, or only call backward if either cond1 or cond2 is met.