这是indexloc提供的服务,不要输入任何密码
Skip to content

Saving and loading replay buffer with HDF5 #261

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

Merged
merged 46 commits into from
Dec 17, 2020

Conversation

nicoguertler
Copy link
Contributor

@nicoguertler nicoguertler commented Dec 9, 2020

  • I have marked all applicable categories:
    • exception-raising fix
    • algorithm implementation fix
    • documentation modification
    • new feature
  • If applicable, I have mentioned the relevant/related issue(s)

As mentioned in #260, this pull request is about an implementation of saving and loading the replay buffer with HDF5.

I added a test of this feature but its probably not exhaustive. Feedback on whether saving and loading works for real projects is welcome.

@codecov-io
Copy link

codecov-io commented Dec 9, 2020

Codecov Report

Merging #261 (c4197e9) into master (cd48142) will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #261      +/-   ##
==========================================
+ Coverage   94.40%   94.54%   +0.13%     
==========================================
  Files          41       41              
  Lines        2611     2677      +66     
==========================================
+ Hits         2465     2531      +66     
  Misses        146      146              
Flag Coverage Δ
unittests 94.54% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tianshou/data/buffer.py 99.04% <100.00%> (+0.07%) ⬆️
tianshou/data/utils/converter.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd48142...c4197e9. Read the comment docs.

Copy link
Collaborator

@Trinkle23897 Trinkle23897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.swp file should not add to this PR.

Copy link
Collaborator

@Trinkle23897 Trinkle23897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are formatting issues.

nicoguertler and others added 7 commits December 9, 2020 13:51
Co-authored-by: n+e <trinkle23897@qq.com>
Co-authored-by: n+e <trinkle23897@qq.com>
Co-authored-by: n+e <trinkle23897@qq.com>
Co-authored-by: n+e <trinkle23897@qq.com>
@Trinkle23897
Copy link
Collaborator

Trinkle23897 commented Dec 9, 2020

Seems it cannot work well with cuda tensor. (github action doesn't have cuda environment :(

$ python3 test/base/test_buffer.py                                               
Traceback (most recent call last):
  File "test/base/test_buffer.py", line 327, in <module>
    test_hdf5()
  File "test/base/test_buffer.py", line 300, in test_hdf5
    vbuf.save(path)
  File "/home/trinkle/github/tianshou-new/tianshou/data/buffer.py", line 409, in save
    self._copy_to_hdf5(k, v, f)
  File "/home/trinkle/github/tianshou-new/tianshou/data/buffer.py", line 370, in _copy_to_hdf5
    grp.create_dataset(k, data=v.numpy())
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

update: resolved

@Trinkle23897
Copy link
Collaborator

Also, could you please add this feature description in the docstring of ReplayBuffer?

@duburcqa
Copy link
Collaborator

It looks perfect to me ! Ready to be merged :) Very good job @nicoguertler

@nicoguertler
Copy link
Contributor Author

Great! Thank you @duburcqa and @Trinkle23897 for your help and advice! There is still some room for improvement. For example, there is no custom conversion for the SegmentTree so for now it is just pickled. But it should be easy to add that later on.

duburcqa
duburcqa previously approved these changes Dec 14, 2020
@duburcqa
Copy link
Collaborator

duburcqa commented Dec 14, 2020

There is still some room for improvement. For example, there is no custom conversion for the SegmentTree so for now it is just pickled. But it should be easy to add that later on.

Yes, but the current implementation can be extended very easily, which is great !

Copy link
Collaborator

@Trinkle23897 Trinkle23897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation!

@duburcqa
Copy link
Collaborator

duburcqa commented Dec 16, 2020

Looks good to me now @Trinkle23897

@Trinkle23897 Trinkle23897 merged commit 5d13d8a into thu-ml:master Dec 17, 2020
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
As mentioned in thu-ml#260, this pull request is about an implementation of saving and loading the replay buffer with HDF5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving and loading replay buffer with HDF5
4 participants