# Using PyTorch Gradients

**URL:** https://discuss.pennylane.ai/t/using-pytorch-gradients/747
**Category:** PennyLane Help
**Created:** [December 27, 2020, 11:23am UTC](https://discuss.pennylane.ai/t/using-pytorch-gradients/747 "2020-12-27T11:23:59Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@andrew](https://discuss.pennylane.ai/u/andrew)
#### Post date: [December 28, 2020, 3:31pm UTC](https://discuss.pennylane.ai/t/using-pytorch-gradients/747/4 "2020-12-28T15:31:04Z")

</div>

> You might need to elaborate here, but if you mean simply compute the gradient of a hybrid classical-quantum cost function, PennyLane supports both autograd (the default) and TensorFlow.

Ah apologies for not being clear. I mean if I created a cost function that itself depends on a loss, something that could look something like:

```auto
def cost(circuit_out, circuit_in):
    grad = torch.autograd.grad(outputs=circuit_out, inputs=circuit_in)
    return np.sum(grad - circuit_in)

```

You would then treat this cost “normally”, as you have in your examples. I ask as a follow up to a comment made [here](http://discuss.pennylane.ai/t/variational-classifiers-and-qngoptimizer/524/10) :

> Yes, that constraint comes from Autograd, which is the default interface in PennyLane

I just wanted to be sure I interpreted this correctly, and that this is still the case.

> Can you try the following code snippet, and let me know if it works for you?

Yes, that works now! Thank you very much!

---

_[View the full topic](https://discuss.pennylane.ai/t/using-pytorch-gradients/747)._
