huggingface / deep-rl-class

This repo contains the syllabus of the Hugging Face Deep Reinforcement Learning Course.
Apache License 2.0
3.71k stars 564 forks source link

[HANDS-ON BUG] #546

Open execbat opened 3 days ago

execbat commented 3 days ago

Describe the bug

Problem with Unit 3: Deep Q-Learning with Atari Games 👾 using RL Baselines3 Zoo

Hello, I have an issue with pushing the model to hub. I execute the line: !python -m rl_zoo3.push_to_hub --algo dqn --env SpaceInvadersNoFrameskip-v4 --repo-name dqn-SpaceInvadersNoFrameskip-v4 -orga execbat -f logs/

Getting this: Loading latest experiment, id=1 Loading logs/dqn/SpaceInvadersNoFrameskip-v4_1/SpaceInvadersNoFrameskip-v4.zip A.L.E: Arcade Learning Environment (version 0.8.1+53f58b7) [Powered by Stella] Stacking 4 frames Wrapping the env in a VecTransposeImage. Uploading to execbat/dqn-SpaceInvadersNoFrameskip-v4, make sure to have the rights ℹ This function will save, evaluate, generate a video of your agent, create a model card and push everything to the hub. It might take up to some minutes if video generation is activated. This is a work in progress: if you encounter a bug, please open an issue. /home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_hub/utils/_deprecation.py:131: FutureWarning: 'Repository' (from 'huggingface_hub.repository') is deprecated and will be removed from version '1.0'. Please prefer the http-based alternatives instead. Given its large adoption in legacy code, the complete removal is only planned on next major release. For more details, please read https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http. warnings.warn(warning_message, FutureWarning) Cloning https://huggingface.co/execbat/dqn-SpaceInvadersNoFrameskip-v4 into local empty directory. WARNING:huggingface_hub.repository:Cloning https://huggingface.co/execbat/dqn-SpaceInvadersNoFrameskip-v4 into local empty directory. Saving model to: hub/dqn-SpaceInvadersNoFrameskip-v4/dqn-SpaceInvadersNoFrameskip-v4 Traceback (most recent call last): File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/rl_zoo3/push_to_hub.py", line 398, in <module> package_to_hub( File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/rl_zoo3/push_to_hub.py", line 247, in package_to_hub _generate_replay(model, eval_env, video_length, is_deterministic, repo_local_path) File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/huggingface_sb3/push_to_hub.py", line 133, in _generate_replay env = VecVideoRecorder( File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 52, in __init__ assert self.env.render_mode == "rgb_array", f"The render_mode must be 'rgb_array', not {self.env.render_mode}" AssertionError: The render_mode must be 'rgb_array', not human Exception ignored in: <function VecVideoRecorder.__del__ at 0x73db523815e0> Traceback (most recent call last): File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 113, in __del__ self.close_video_recorder() File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 103, in close_video_recorder if self.recording: File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 420, in __getattr__ return self.getattr_recursive(name) File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 443, in getattr_recursive attr = self.venv.getattr_recursive(name) File "/home/evgenii/anaconda3/envs/huggingface/lib/python3.9/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 445, in getattr_recursive attr = getattr(self.venv, name) AttributeError: 'DummyVecEnv' object has no attribute 'recording'

So I don;t know how to get the replay file and push altogether to my huggingface repository. Please help. unit3.zip

Material

I made it in conda env on my laptop. env built on python 3.9.18

-OS: Ubuntu 22.04.3 LTS

paulaolmedo commented 2 days ago

I'm having the very same problem, but i'm running the notebook on Google Colab, with the suggested GPU.

c-g-well commented 1 day ago

Also having the same problem. Running the notebook on Google Colab using the t4. Training works fine but when pushing to the hub my model card is also blank.

input !python -m rl_zoo3.push_to_hub --algo dqn --env SpaceInvadersNoFrameskip-v4 --repo-name dqn-SpaceInvadersNoFrameskip-v4-2 -orga cgwell -f logs/

output 2024-06-30` 01:40:27.852357: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered 2024-06-30 01:40:27.852414: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered 2024-06-30 01:40:27.948812: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2024-06-30 01:40:27.956169: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2024-06-30 01:40:29.011445: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT Loading latest experiment, id=4 Loading logs/dqn/SpaceInvadersNoFrameskip-v4_4/SpaceInvadersNoFrameskip-v4.zip A.L.E: Arcade Learning Environment (version 0.8.1+53f58b7) [Powered by Stella] Stacking 4 frames Wrapping the env in a VecTransposeImage. Uploading to cgwell/dqn-SpaceInvadersNoFrameskip-v4-2, make sure to have the rights ℹ This function will save, evaluate, generate a video of your agent, create a model card and push everything to the hub. It might take up to some minutes if video generation is activated. This is a work in progress: if you encounter a bug, please open an issue. /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_deprecation.py:131: FutureWarning: 'Repository' (from 'huggingface_hub.repository') is deprecated and will be removed from version '1.0'. Please prefer the http-based alternatives instead. Given its large adoption in legacy code, the complete removal is only planned on next major release. For more details, please read https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http. warnings.warn(warning_message, FutureWarning) Cloning https://huggingface.co/cgwell/dqn-SpaceInvadersNoFrameskip-v4-2 into local empty directory. WARNING:huggingface_hub.repository:Cloning https://huggingface.co/cgwell/dqn-SpaceInvadersNoFrameskip-v4-2 into local empty directory. Saving model to: hub/dqn-SpaceInvadersNoFrameskip-v4-2/dqn-SpaceInvadersNoFrameskip-v4 Traceback (most recent call last): File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.10/dist-packages/rl_zoo3/push_to_hub.py", line 398, in package_to_hub( File "/usr/local/lib/python3.10/dist-packages/rl_zoo3/push_to_hub.py", line 247, in package_to_hub _generate_replay(model, eval_env, video_length, is_deterministic, repo_local_path) File "/usr/local/lib/python3.10/dist-packages/huggingface_sb3/push_to_hub.py", line 133, in _generate_replay env = VecVideoRecorder( File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 52, in init assert self.env.render_mode == "rgb_array", f"The render_mode must be 'rgb_array', not {self.env.render_mode}" AssertionError: The render_mode must be 'rgb_array', not human Exception ignored in: <function VecVideoRecorder.del at 0x7c8d835f37f0> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 113, in del self.close_video_recorder() File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/vec_video_recorder.py", line 103, in close_video_recorder if self.recording: File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 420, in getattr return self.getattr_recursive(name) File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 443, in getattr_recursive attr = self.venv.getattr_recursive(name) File "/usr/local/lib/python3.10/dist-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 445, in getattr_recursive attr = getattr(self.venv, name) AttributeError: 'DummyVecEnv' object has no attribute 'recording'

execbat commented 13 hours ago

Solved, in case it might be useful. Because of error AssertionError: The render_mode must be 'rgb_array', not human. So pass 'rgb_array' render mode as --env-kwargs when calling rl_zoo3.push_to_hub.

Something like: !python -m rl_zoo3.push_to_hub --algo dqn --env SpaceInvadersNoFrameskip-v4 --verbose 1 --repo-name dqn-SpaceInvadersNoFrameskip-v4 -orga {your_huggingface_nick} -f logs/ --env-kwargs 'render_mode:"rgb_array"'

Hope it will help