While I am not clear about the picture you have posted - (why is the shape of x (3,2) if there are just three input nodes). One clear issue with your code though is that none of the variables have a requires_grad=True. For autograd to track stuff at least one of the inputs should have requires_grad=True.
As far as the implementation of the diagram is concerned I would do something like this (assuming each node yields a scalar in the first layer):
# Layer 1
x = torch.randn((3,1), requires_grad=True)
# tensor([ 1.4079,  1.5536,  0.2737])
mask = torch.Tensor([[0,1,0],[1,0,1]])
# tensor([[ 0,  1,  0],
#         [ 1,  0,  1]])
y = mask * x.expand_as(mask)
# tensor([[ 0.0000,  1.5536,  0.0000],
#      [ 1.4079,  0.0000,  0.2737]])
y.grad_fn
# <MulBackward1 at 0x7f4b7a6725c0>

If I am correct about what you are trying to do you don’t need masked_scatter but simple boolean masking.
In any case, masked_scatter_ seems to be working for me and calculating the gradients correctly.