question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write custom serialisation for experience replay

See original GitHub issue

Although it is now possible to save/load experience replay memories (https://github.com/Kaixhin/PlaNet/issues/3), naively using torch.save fails with large memories. Dealing with this would require custom serialisation code.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kaixhincommented, Dec 16, 2019

I was just talking about https://github.com/Kaixhin/PlaNet/blob/master/memory.py#L15-L18 , but yes, anything that needs to be stored to recover the whole ExperienceReplay class.

1reaction
alec-tschantzcommented, Dec 16, 2019

Oh nice, this absolutely seems viable. (10**6, 3, 64, 64) is 12 GB on the hard-drive but reading and writing are mostly instant. As a minimal working example:

class Buffer(object):
    def __init__(self, buffer_size=10 ** 6):
        self.buffer_size = buffer_size
        self.obs_shape = (buffer_size, 3, 64, 64)
        self.obs_path = "obs.dat"
        self.idx = 0

    def create_new_file(self):
        obs_f = np.memmap(
            self.obs_path, dtype=np.uint8, mode="w+", shape=self.obs_shape
        )
        del obs_f

    def add(self, obs):
        obs_f = np.memmap(
            self.obs_path, dtype=np.uint8, mode="w+", shape=self.obs_shape
        )
        obs_f[self.idx] = obs
        del obs_f
        self.idx += 1

    def sample(self, idxs):
        obs_f = np.memmap(self.obs_path, dtype=np.uint8, mode="r", shape=self.obs_shape)
        data = obs_f[idxs]
        del obs_f
        return data

if __name__ == "__main__":
    buffer = Buffer()
    for i in range(10 ** 6):
        obs = (np.random.rand(3, 64, 64) * 255).astype(np.uint8)
        buffer.add(obs)
    idxs = np.random.randint(0, 10 ** 4, size=100)
    data = buffer.sample(idxs)

I’ll get round to integrating it with your buffer at some point - if you think it’d be worthwhile.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with Custom Deserialization in Jackson
This quick tutorial will illustrate how to use Jackson 2 to deserialize JSON using a custom Deserializer.
Read more >
Understanding TypeScript object serialization - LogRocket Blog
Learn about object serialization in TypeScript, the way systems communicate seamlessly, and the issues with serialization in TypeScript.
Read more >
Serialization — Ray 2.2.0 - the Ray documentation
Numpy arrays in the object store are shared between workers on the same node (zero-copy deserialization). Overview#. Ray has decided to use a...
Read more >
Create and Deserialize a JSON Array
The example below explains how to use activities such as Invoke Code and Deserialize Json Array to create a JSON array, deserialize it,...
Read more >
DataConverters - AWS Flow Framework for Java
The framework will create objects of the DataConverter type you specified on @Activities annotation to serialize the inputs to the activity and to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found