# How do I copy the model?

**URL:** <https://discuss.ray.io/t/how-do-i-copy-the-model/2668>\
**Category:** RLlib\
**Created:** [June 26, 2021, 1:28pm UTC](https://discuss.ray.io/t/how-do-i-copy-the-model/2668 "2021-06-26T13:28:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xim\_Lee](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xim_lee/32/300_2.png) [@Xim\_Lee](https://discuss.ray.io/u/Xim_Lee)\
**Post date:** [June 26, 2021, 1:28pm UTC](https://discuss.ray.io/t/how-do-i-copy-the-model/2668/1 "2021-06-26T13:28:13Z")

</div>

Hi, everybody!  
I have a question.

```auto
agent.get_weights()

```

I have got the weights of the policy model. And I want to make a copy\_model using the torch.  
How do I copy the model?  
I want to use the loss.backward() for IRL [How to get the weight?](https://discuss.ray.io/t/how-to-get-the-weight/2646)

---

<div class="post-metadata">

**Author:** ![mannyv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mannyv/32/606_2.png) [@mannyv](https://discuss.ray.io/u/mannyv)\
**Post date:** [June 26, 2021, 1:54pm UTC](https://discuss.ray.io/t/how-do-i-copy-the-model/2668/2 "2021-06-26T13:54:09Z")

</div>

I think this example should have what you are looking for:

> <https://github.com/ray-project/ray/blob/6bfa97eed77fb6332cb6ba5aa4aa37dd54764349/rllib/examples/restore_1_of_n_agents_from_checkpoint.py#L109-L119>

---

<div class="post-metadata">

**Author:** ![Xim\_Lee](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xim_lee/32/300_2.png) [@Xim\_Lee](https://discuss.ray.io/u/Xim_Lee)\
**Post date:** [June 28, 2021, 12:29am UTC](https://discuss.ray.io/t/how-do-i-copy-the-model/2668/3 "2021-06-28T00:29:51Z")

</div>

Hi @mannyv, thanks for your reply.  
I’ll try using the code you gave me.
