uzh-rpg / agile_flight

Developing and Comparing Vision-based Algorithms for Vision-based Agile Flight
MIT License
152 stars 55 forks source link

updateUnity extremely slow for vector environments #70

Open prafael18 opened 2 years ago

prafael18 commented 2 years ago

Hey everyone!

I was trying to train an agent using the depth images with the default SAC implementation from stable-baselines3 and noticed that training was extremely slow. After doing some profiling, I noticed that the bottleneck was in the updateUnity call, which is needed to retrieve the depth images. I was wondering if this was expected or if I'm doing something wrong that might be making this call take longer than expected.

By the way, I'm running the RPG_Flightmare standalone on a GPU, which I made sure of by checking with nvidia-smi, and I'm training with num_envs = 25. In the Flightmare paper, you guys advertise rendering speeds of up to 230Hz on a laptop, which I assume is achieved for a single environment (i.e. num_envs = 1). Therefore, I find it strange that I'm getting speeds closer to 1.6Hz on a GPU, even if for a larger number of environments. For reference, updateUnity runs at approximately 16Hz for num_envs = 1 on my GPU.

These are my PC specs:

CPU: AMD Ryzen 9 3900X 12-Core Processor
GPU: GeForce RTX 2070 SUPER
RAM: 32GiB DDR4 2133 MHz

And these are my profiling results:

env.wrapper.step() took 0.42ms
env.wrapper.updateUnity() took 616.98ms
env.get_info() took 1.24ms
env.get_depth_image() took 0.04ms
env.get_obs() took 0.05ms
sac.collect_rollouts() took 621.87ms
sac.train() took 39.49ms
antonilo commented 2 years ago

You might want to decrease the image resolution if you train with depth images from scratch

prafael18 commented 2 years ago

I forgot to mention, but these results were for an 84x84 depth image, which is the resolution used by the original DQN network.

Lu-tju commented 2 years ago

Hi, I have met the same problem as you. I run on the server with Xeon(R) CPU E5-2620 and 4 * GeForce RTX 2080. I find that the CPU, GPU, memory, and disk io take up very little, but the rendering of unity is very slow. On my own computer, the unity works well and CPU can consume up to 100%, it looks as if the server does not play a role. Note that it's not caused by training parameters, because it happens when I run run_vision_demo.py as well. Have you solved this problem? thanks a lot!

ali-alridha commented 9 months ago

Facing the same issue