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

ShmemVectorEnv Implementation #174

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 26 commits into from
Aug 4, 2020
Merged

ShmemVectorEnv Implementation #174

merged 26 commits into from
Aug 4, 2020

Conversation

ChenDRAG
Copy link
Collaborator

@ChenDRAG ChenDRAG commented Aug 1, 2020

Following OpenAI baseline, I implement ShmemVectorEnv which is an optimized version of SubprocVectorEnv that uses shared variables to communicate observations. ShmemVectorEnv has exactly the same API as SubprocVectorEnv, but when obs.shape is too large, the usage of shared variables can save us a lot of time.

This pr include:

  • Basic Implementation of ShmemVectorEnv
  • update in test_env.py to test ShmemVectorEnv
  • some improvement in of test_env.py for generalization
  • some fix in test/base/env.py and test_env.py

I borrow from openai baseline to implement ShmemVectorEnv Class. Please refer to https://github.com/openai/baselines/blob/master/baselines/common/vec_env/shmem_vec_env.py

@ChenDRAG ChenDRAG changed the title Scheme ShmemVectorEnv Implementation Aug 1, 2020
@Trinkle23897
Copy link
Collaborator

Trinkle23897 commented Aug 1, 2020

Also need to modify the documentation somewhere.

@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2020

Codecov Report

Merging #174 into dev will increase coverage by 0.46%.
The diff coverage is 88.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #174      +/-   ##
==========================================
+ Coverage   88.93%   89.40%   +0.46%     
==========================================
  Files          38       39       +1     
  Lines        2214     2321     +107     
==========================================
+ Hits         1969     2075     +106     
- Misses        245      246       +1     
Flag Coverage Δ
#unittests 89.40% <88.46%> (+0.46%) ⬆️

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

Impacted Files Coverage Δ
tianshou/env/vecenv/shmemenv.py 88.23% <88.23%> (ø)
tianshou/env/__init__.py 100.00% <100.00%> (ø)
tianshou/env/vecenv/subproc.py 84.88% <100.00%> (ø)
tianshou/data/collector.py 93.90% <0.00%> (+0.03%) ⬆️
tianshou/data/buffer.py 92.59% <0.00%> (+0.11%) ⬆️
tianshou/trainer/onpolicy.py 94.02% <0.00%> (+16.41%) ⬆️

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 996e2f7...46496e7. Read the comment docs.

@Trinkle23897
Copy link
Collaborator

How about #166?

@duburcqa
Copy link
Collaborator

duburcqa commented Aug 2, 2020

It would be nice to refactor this module, to avoid many code duplications. But it could be done in another PR.

@Trinkle23897
Copy link
Collaborator

It would be nice to refactor this module, to avoid many code duplications. But it could be done in another PR.

Yes, I think so. Another PR will reconstruct these vecenv codes to support wait_num.

@ChenDRAG
Copy link
Collaborator Author

ChenDRAG commented Aug 3, 2020

recurse dict is supported now. Ready for review.

How about #166?
I think this should be done in another PR, 'cause it is not related to Shmemenv?

@ChenDRAG ChenDRAG requested a review from youkaichao August 4, 2020 02:06
Copy link
Collaborator

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

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

Nice PR for memory efficiency and speed with large observations 👍

@youkaichao youkaichao merged commit f2bcc55 into thu-ml:dev Aug 4, 2020
@ChenDRAG ChenDRAG deleted the scheme branch August 4, 2020 07:58
@Trinkle23897 Trinkle23897 added enhancement Feature that is not a new algorithm or an algorithm enhancement and removed enhancement Feature that is not a new algorithm or an algorithm enhancement labels Aug 6, 2020
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
* add shmem vecenv, some add&fix in test_env

* generalize test_env IO

* pep8 fix

* comment update

* style change

* pep8 fix

* style fix

* minor fix

* fix a bug

* test fix

* change env

* testenv bug fix& shmem support recurse dict

* bugfix

* pep8 fix

* _NP_TO_CT enhance

* doc update

* docstring update

* pep8 fix

* style change

* style fix

* remove assert

* minor

Co-authored-by: Trinkle23897 <463003665@qq.com>
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.

5 participants