Thanks. I have tried with
x = torch.tensor([0.0, 1.0], requires_grad=True)
y = torch.tensor([0.5, 0.5], requires_grad=True) 
mask = (x < y).float() 
z = (x * mask + y * (1 - mask) * 10).sum()
z.backward()

In [18]: x.grad                                                                 
Out[18]: tensor([1., 0.])

In [19]: y.grad                                                                 
Out[19]: tensor([ 0., 10.])

It seems it is working and the result looks reasonable for this trivial case. Not sure if it applies to general cases.