title: Question about non differentiability function in pytorch
body: <p>I have a problem with neural networks that predicts.</p>
  <pre><code>y_predicted = self.net(x)
  z_predicted = self.calculate_z(y_predicted)
  </code></pre>
  <p>I would like to minimise the loss in prediction in both y and z. However, the method self.calculate_z is non-deterministic and used by a simulation. Is there any way to include the loss between z_predicted and z_real in pytorch?</p>
  <p>Above an example of what I want to do: (x input, y_real (real target 1), z_real (real target 2), self.net (neural network))</p>
  <pre><code>def example(self, x, y_real, z_real):
      y_predicted = self.net(x)
      z_predicted = self.calculate_z(y_predicted)
      self.loss = self.criterionL1(z_predicted, z_real) + self.criterionL1(y_real, y_predicted)
      self.loss.backward()
  </code></pre>