I am experimenting with autoencoders, where y is the original image and x is the reconstructed one, but some pixels are not observable (masked according to various criteria). And the mask can change from one training example to another. Thank you for clarification about automatic differentiation.