Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何存储和读取replay buffer为h5文件 #529

Closed
2 of 11 tasks
jaried opened this issue Oct 31, 2022 · 7 comments
Closed
2 of 11 tasks

如何存储和读取replay buffer为h5文件 #529

jaried opened this issue Oct 31, 2022 · 7 comments
Labels
discussion Discussion of a typical issue help wanted Extra attention is needed

Comments

@jaried
Copy link

jaried commented Oct 31, 2022

  • I have marked all applicable categories:
    • exception-raising bug
    • RL algorithm bug
    • system worker bug
    • system utils bug
    • code design/refactor
    • documentation request
    • new feature request
  • I have visited the readme and doc
  • I have searched through the issue tracker and pr tracker
  • I have mentioned version numbers, operating system and environment, where applicable:
  import ding, torch, sys
  print(ding.__version__, torch.__version__, sys.version, sys.platform)
v0.4.3 1.12.1+cu116 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] win32

请问:
1、缓存如何存为h5,并且如何读缓存
2、需要定期存缓存时,缓存如果过大,如何切割存为h5,并且如何读缓存

@PaParaZz1 PaParaZz1 added the discussion Discussion of a typical issue label Oct 31, 2022
@PaParaZz1
Copy link
Member

PaParaZz1 commented Oct 31, 2022

你这里要缓存的数据是指,是 replay buffer 里的数据吗,具体有多大

@jaried
Copy link
Author

jaried commented Oct 31, 2022

是的,大概12M条,直接保存h5内存根本放不下保存过程中产生的数据,需要分块保存。

我之前用tianshouVectorReplayBuffer就是根据env_id来分块保存的,只有整体保存时间的1/4-1/3,而且不需要多大内存。整体保存,我的256G内存都不够用。

obs大小大概如下:

        self._observation_space = _observation_space = gym.spaces.Dict(
            {
                'agent_state': gym.spaces.Box(
                    low=-1, high=1, shape=(4,336), dtype=np.float32
                ),
                'global_state': gym.spaces.Box(
                    low=-1, high=1, shape=(4, 994), dtype=np.float32
                )
            }
        )

@PaParaZz1 PaParaZz1 added the help wanted Extra attention is needed label Nov 1, 2022
@jaried jaried changed the title 如何存储和读缓存h5文件 如何存储和读 replay buffer为h5文件 Nov 1, 2022
@jaried jaried changed the title 如何存储和读 replay buffer为h5文件 如何存储和读取replay buffer为h5文件 Nov 1, 2022
@PaParaZz1
Copy link
Member

  • 首先第一点,你这个环境的state数据可以适当压缩吗,比如可以用uint8表示的其实没必要用float32。如果这个可以在环境里修改,那么存储在replay buffer中的数据就可以大概缩小为原来的四分之一
  • 然后对于replay buffer内部,我理解这个功能需求,相当于是将replay buffer里的数据通过某种方式,自动转换成h5放到磁盘里,如果读到这部分数据,再去h5里面读一下,从而减少对内存的占用是吗?

@jaried
Copy link
Author

jaried commented Nov 9, 2022

  • 首先第一点,你这个环境的state数据可以适当压缩吗,比如可以用uint8表示的其实没必要用float32。如果这个可以在环境里修改,那么存储在replay buffer中的数据就可以大概缩小为原来的四分之一

目前我用的是sac算法,需要做obs缩放,所以obs用的是-1到1的区间。

  • 然后对于replay buffer内部,我理解这个功能需求,相当于是将replay buffer里的数据通过某种方式,自动转换成h5放到磁盘里,如果读到这部分数据,再去h5里面读一下,从而减少对内存的占用是吗?

replay buffer我是这么用的,1、因为我的env使用了大量数据,数据的质量不一定可控,而且我的env可能会出现bug,为了避免训练时出现异常,我采用了定期存replay buffer的方法,出现异常后可以继续训练。2、我的数据每天更新,因为sac是off-policy,所以第二次训练时,网络权重从0开始,并且读上次训练出好的模型的replay buffer,可以提高成绩。

@PaParaZz1
Copy link
Member

明白了,所以其实你的需求更简单,只需要自动定期存储replay buffer中的数据,且能够在重新训练的时候加载进来就可以了对吧

@jaried
Copy link
Author

jaried commented Nov 9, 2022

是的,很简单。只要能把replay buffer分文件保存和读取就行了,保存h5时使用zip算法压缩。

@PaParaZz1
Copy link
Member

相关功能已在 #542 中实现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion of a typical issue help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants