# Trainable parameter as input

**URL:** <https://discuss.pytorch.org/t/trainable-parameter-as-input/15642>\
**Category:** autograd\
**Created:** [March 28, 2018, 10:55pm UTC](https://discuss.pytorch.org/t/trainable-parameter-as-input/15642 "2018-03-28T22:55:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![backpropper](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/backpropper/32/77927_2.png) [@backpropper](https://discuss.pytorch.org/u/backpropper)\
**Post date:** [March 28, 2018, 10:55pm UTC](https://discuss.pytorch.org/t/trainable-parameter-as-input/15642/1 "2018-03-28T22:55:37Z")

</div>

I can’t understand the difference:

```auto
prior = Variable(torch.zeros(24), requires_grad=True)
prior_param = [nn.Parameter(prior.data)]
h_test = torch.autograd.grad(outputs=prior.mean(), inputs=prior_param) #does not work
h_test = torch.autograd.grad(outputs=prior.mean(), inputs=prior) #works

```

I want to make a trainable parameter as an input to the computation graph.  
The error is  
`RuntimeError: One of the differentiated Variables appears to not have been used in the graph`

---

<div class="post-metadata">

**Author:** ![royboy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/royboy/32/4106_2.png) [@royboy](https://discuss.pytorch.org/u/royboy)\
**Post date:** [March 29, 2018, 12:26am UTC](https://discuss.pytorch.org/t/trainable-parameter-as-input/15642/2 "2018-03-29T00:26:46Z")

</div>

What version of pytorch are you using? I couldn’t repro this.

---

<div class="post-metadata">

**Author:** ![backpropper](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/backpropper/32/77927_2.png) [@backpropper](https://discuss.pytorch.org/u/backpropper)\
**Post date:** [March 29, 2018, 12:55am UTC](https://discuss.pytorch.org/t/trainable-parameter-as-input/15642/3 "2018-03-29T00:55:30Z")

</div>

I am using 0.3.1.post2

---

<div class="post-metadata">

**Author:** ![royboy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/royboy/32/4106_2.png) [@royboy](https://discuss.pytorch.org/u/royboy)\
**Post date:** [March 30, 2018, 7:28pm UTC](https://discuss.pytorch.org/t/trainable-parameter-as-input/15642/4 "2018-03-30T19:28:46Z")

</div>

I think it’s because you’re using the `prior` as the output. This works on 0.3.1:

```auto
prior = Variable(torch.zeros(24), requires_grad=True)
prior_param = nn.Parameter(prior.data)
h_test = torch.autograd.grad(outputs=prior_param.mean(), inputs=[prior_param])
h_test = torch.autograd.grad(outputs=prior.mean(), inputs=prior)

```

I’m not sure why the code you posted works for 0.4 and not 0.3.1, but it’s probably something to do with the tensor variable merge.
