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
How to restore from h5 file saved by PrioritizedVectorReplayBuffer? #728
Comments
Sorry about that. It's a bug and we haven't added this kind of test before. |
Is there a plan to fix this bug? |
will do today |
Thank you very much. |
Could you please paste your full script to reproduce the bug? I just found I use PrioVecBuf to save and PrioBuf to load, which is absolutely wrong usage but can produce almost the same KeyError. After correcting this, I don't see any undesired behavior in my side. |
The behavior in your script above is desirable. The PrioVecBuf needs to delete all of its sub-priobuf's weight and merge to a single segment tree, in order to enable global weight sampling. |
This should work I guess, if the buffer's type is the same. |
I tried this, after reading, len(train_collector.buffer) is correct 650,000 steps. However, after continuing to collect data such as 8000 steps, len(train_collector.buffer)=8000. |
Can you write a minimal example to show the bug? |
This comment was marked as resolved.
This comment was marked as resolved.
Excuse me, do I need to add anything else? |
This is expected because it only returns a buffer instead of modifying one buffer in place.
I mean you can write something like the unit test code: tianshou/test/base/test_buffer.py Lines 935 to 964 in 278c91a
That is, manually add one or more fake data, save it, then immediately reload it, and check whether other functionality behaves correctly or not, instead of the whole training script... |
My major is not computer, I haven't written unit tests yet, I need to learn to write. |
Take your time, I believe you'll learn more after writing some tests to get a better understanding. |
I just read the introduction to unit testing and it is worth learning. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
# check shallow copy in PrioritizedVectorReplayBuffer
new_buffers = {
"vector": PrioritizedVectorReplayBuffer(size * 4, 4, alpha=0.6, beta=0.4),
}
for k in ["vector"]:
new_buffers[k].info.number.n[0] = -100
assert new_buffers[k].buffers[0].info.number.n[0] == -100 You access a buffer that contains nothing, this seems not correct. |
At this point, index=='weight', there is no weight in the buffer, so an error is reported. I don't know how to write the unit test here. tianshou/tianshou/data/batch.py Lines 236 to 237 in 278c91a
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-11-5b960fabffe8>", line 1, in <module>
self.__dict__[index]
KeyError: 'weight'
```
|
Use |
It's because you cannot directly sample data from PrioVectorReplayBuffer's sub_buffer. Just put |
When I run the following statement, it prompts:
KeyError: 'weight'
, how can I modify it?data, idx = source.sample(0)
The text was updated successfully, but these errors were encountered: