# Load/save replay buffer

**URL:** <https://discuss.ray.io/t/load-save-replay-buffer/3022>\
**Category:** RLlib\
**Created:** [July 26, 2021, 5:56pm UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022 "2021-07-26T17:56:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![axr8716](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@axr8716](https://discuss.ray.io/u/axr8716)\
**Post date:** [July 26, 2021, 5:56pm UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/1 "2021-07-26T17:56:32Z")

</div>

Hi all

I am looking for a way to save and load replay buffer for off-policy methods. I am looking into this like a transfer learning approach. Please let me know.

---

<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:** [July 26, 2021, 10:58pm UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/2 "2021-07-26T22:58:12Z")

</div>

There is currently no support for this. I am sure they would welcome a PR if you implement it. Then we could add it to the save\_state methods.currently there are often performance drops when resuming training with off policy algorithms because even though the weights are restored for the policies, the replay buffer restarts empty.

---

<div class="post-metadata">

**Author:** ![sven1977](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sven1977/32/53_2.png) [@sven1977](https://discuss.ray.io/u/sven1977)\
**Post date:** [July 28, 2021, 3:41pm UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/3 "2021-07-28T15:41:05Z")

</div>

Hey @axr8716 , yeah, what @mannyv said :), it’s not supported right now, but on our TODO list.

The problem is that the replay buffer objects currently only “sit” inside the Trainer’s execution plan function, so we have no reference to it from within the Trainer of Policies. We need to make these objects registrable (via some convention). This way, they would be accessible when saving/restoring a Trainer. Feel free to do a PR that fixes the problem. A simple POC that only works e.g. for SimpleQ would suffice to get this rolling. 🙂

---

<div class="post-metadata">

**Author:** ![James\_Liu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/james_liu/32/1415_2.png) [@James\_Liu](https://discuss.ray.io/u/James_Liu)\
**Post date:** [September 16, 2022, 3:29am UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/4 "2022-09-16T03:29:26Z")

</div>

I am wondering if it is supported now or not.  
Thanks

---

<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:** [September 17, 2022, 3:04am UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/5 "2022-09-17T03:04:09Z")

</div>

Hi @James_Liu,

I think it should be supported now.

> <https://github.com/ray-project/ray/blob/6ca0b2f8e5a1d9b93cd138b3ae0d58a9fac0e632/rllib/algorithms/algorithm.py#L2496>

> <https://github.com/ray-project/ray/pull/17999>
>
> The content of replay buffers for off policy algos are currently not stored when… taking a checkpoint of a Trainer. This PR:
> \- adds a config option (\`store\_buffer\_in\_checkpoints\`) to enable this behavior.
> \- makes sure that warnings are raised if \`store\_buffer\_in\_checkpoints\` is True and checkpoint does NOT have any replay data in it or if \`store\_buffer\_in\_checkpoints\` is False and checkpoint does have replay data in it.
> \- test cases for PrioritizedReplay were added to make sure get\_state/set\_state works properly.
> \- existing test cases for SimpleQ/DQN/DDPG were augmented to make sure checkpointing with replay\_buffer content works ok.
> 
> 
> 
> \## Why are these changes needed?
> 
> Issue #8151 
> 
> 
> 
> \## Related issue number
> 
> Closes #8151 
> 
> 
> 
> \## Checks
> 
> \- \[x\] I've run \`scripts/format.sh\` to lint the changes in this PR.
> \- \[x\] I've included any doc changes needed for https://docs.ray.io/en/master/.
> \- \[x\] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
> \- Testing Strategy
> - \[x\] Unit tests
> - \[\] Release tests
> - \[\] This PR is not tested :(

---

<div class="post-metadata">

**Author:** ![James\_Liu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/james_liu/32/1415_2.png) [@James\_Liu](https://discuss.ray.io/u/James_Liu)\
**Post date:** [September 18, 2022, 6:49pm UTC](https://discuss.ray.io/t/load-save-replay-buffer/3022/6 "2022-09-18T18:49:28Z")

</div>

@mannyv Yes. There is JSonReader and I can use it to read saved replay buffer. Thanks,
