-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Tensorboard files not saving when using SubprocVecEnv #1205
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Reading the code you give, I don't see any instruction for tensorboard, nor any use of the SubprocVecEnv. So I have trouble understanding your problem. Can you rephrase it? The following works well for me: # test_1205.py
from stable_baselines3 import DQN
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.vec_env import SubprocVecEnv
if __name__ == "__main__":
venv = make_vec_env("CartPole-v1", vec_env_cls=SubprocVecEnv, n_envs=2)
model = DQN("MlpPolicy", venv, tensorboard_log="./tensorboard")
model.learn(1000) $ python test_1205.py
$ ls tensorboard
DQN_1 |
Ah, forgot to change that part. The instantiation of the SubprocVecEnv is here
There is nothing for tensorboard because I don't directly do anything with it. It should be taken care of by the stable-baselines3 code within the DQN_ICM's parent class's (OffPolicyAlgorithm) learn method I believe. The tensorboard stuff is all internal to stable-baselines, which is why I'm confused about why it isn't working within the subprocenv. If I use the below env I am able to get the correct tensorboard.
Similar to you, the tensorboard file itself does get saved. However, when I run Tensorboard there are no metrics that are saved to the file somehow. |
Another thing I can't figure out: does the problem occur only with your custom environment, or also with the other standard environments? |
Just ran the sample code you commented and it appears to work as expected - I can see the tensorboard metrics within the file. So this appears to be an issue with just the CustomEnv, but I have not made any changes to the tensorboard code and the issue only appears when using SubprocVecEnv - I don't have the issue with the single env case. One thing that might be relevant is that after training finishes, my code hangs and does not close out when using the SubprocVecEnv - kind of looks like a process or thread doesn't close properly. When I run through the debugger I don't have that issue surprisingly. Maybe since it hangs it doesn't save to tensorboard properly? Although it saves the files without issues so I don't know if that would be it |
So if I sum up simply, your problem is that this: from stable_baselines3 import DQN
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.vec_env import SubprocVecEnv
class CustomEnv(gym.Env): ...
if __name__ == "__main__":
venv = make_vec_env(CustomEnv, vec_env_cls=SubprocVecEnv, n_envs=2)
model = DQN("MlpPolicy", venv, tensorboard_log="./tensorboard")
model.learn(1000) doesn't output anything on your tensorboard, right? |
Yes, more or less. The above does not output anything to tensorboard but
does. (Only difference is I use my modified DQN_ICM algorithm in both cases instead of base DQN) |
Ok, then the problem does not come from |
Incorrect, I'm just saying that it does work when I do
but does not when I do
And the SubprocVecEnv is what I am currently trying to work with |
Sorry I read the opposite.
Does using DQN instead of DQN_ICM solve the problem? |
Just gave it a try and looks like normal DQN does not work either |
Looking quickly at your code, I don't see anything that could explain this. In order for us to help you, we need to be able to reproduce the "error", so you need to provide a minimal code that allows it. |
Okay, let me try and minimize the current code for an MVP and link the open-source modeler used in the environment. |
Make sure that the modeler is required for the bug. Most likely it is not. |
Got an MVP working and surprisingly am able to view the tensorboard metrics in the MVP but not the full codebase. Guess that means it's something with the full codebase that's causing the issue - this helps me narrow it down at least! I'll keep adding until it breaks. |
I advise you to do the opposite: keep removing until the problem disappears. Otherwise you won't get a minimal example. |
Was able to get it working! Switched up the logger, added a Monitor to the vec_env, and added some callbacks. Not sure which was the winner, but the files have logging data in them now. Seems like it wasn't an issue with the environment or stable-baselines, just some things were missing. Thanks for helping out with this! Closing the issue. |
That's good to hear.
Unfortunately, no one else will benefit from it. If you ever figure out what was missing, please post it here. |
Looks like it came down to the EvalCallback - removing the EvalCallback results in a tensorboard file with no data within it. Looks like nothing is getting logged within the tensorboard file unless the callback gets called. |
🐛 Bug
When I train my model with a normal Monitor wrapped env I get the output tensorboard files as expected, but when I use a SubprocVecEnv with multiple parallel environments nothing seems to get logged to the tensorboard file. Is this expected when using SubprocVecEnv given the multiple environments?
Code example
My custom environment is a wrapper for an external modeler, so I can't provide a code sample that would be able to run below. I make a few changes to the DQN algorithm (adding an intrinsic curiosity module) but the tensorboard files save fine when running in a solo environment so I don't think that would be the issue. I added the reset and step methods below in case they help but they likely won't make sense without the necessary modeler.
Relevant log output / Error message
No response
System Info
OS: Linux-5.4.0-80-generic-x86_64-with-glibc2.27 #90~18.04.1-Ubuntu SMP Tue Jul 13 19:40:02 UTC 2021
Python: 3.9.15
Stable-Baselines3: 1.6.2
PyTorch: 1.12.1+cu102
GPU Enabled: False
Numpy: 1.22.4
Gym: 0.21.0
({'OS': 'Linux-5.4.0-80-generic-x86_64-with-glibc2.27 #90
18.04.1-Ubuntu SMP Tue Jul 13 19:40:02 UTC 2021', 'Python': '3.9.15', 'Stable-Baselines3': '1.6.2', 'PyTorch': '1.12.1+cu102', 'GPU Enabled': 'False', 'Numpy': '1.22.4', 'Gym': '0.21.0'}, 'OS: Linux-5.4.0-80-generic-x86_64-with-glibc2.27 #9018.04.1-Ubuntu SMP Tue Jul 13 19:40:02 UTC 2021\nPython: 3.9.15\nStable-Baselines3: 1.6.2\nPyTorch: 1.12.1+cu102\nGPU Enabled: False\nNumpy: 1.22.4\nGym: 0.21.0\n')Checklist
The text was updated successfully, but these errors were encountered: