It seems one or more of your conditions is trying to use multiple values, which is wrong and will raise the error. Here is a small code snippet showing this behavior:
a = torch.tensor([True])
if a: # works
    print('works')
    
b = torch.tensor([True, False])
if b: # fails
    print('fails')
# > RuntimeError: Boolean value of Tensor with more than one value is ambiguous

so you would have to check all conditions and make sure they return a valid single bool value.