Issues during training StyleGAN2

2023-12-17

What is StyleGAN2

StyleGAN2 is a State-Of-The-Art (SOTA) generative adversarial network (GAN).

Issue

When training StyleGAN2, you may most likely will encounter following issue:

Setting up PyTorch plugin "bias_act_plugin"... Failed.
Setting up PyTorch plugin "upfirdn2d_plugin"... Failed.

The reason you see this message is that StyleGAN2 used ninja to build its cuda file. Theoretically, you can solve this by running shell command sudo apt-get install ninja. However, in case you don’t have root permission, you can git clone ninja repo into your project running path, and you can use command ninja -v to check if the ninja is ready. If you have done it right, you should not see something like error: loading 'build.ninja': No such file or directory.

If you have already solved your problem, good. But here is another situation you may encounter. If you are using cuda driver higher than cuda 11.6 or Ubuntu OS higher than 20.04, you may find that the default GCC on your device is higher than gcc8. This will cause ninja build error. Because during the ninja build process, there is an attribute for nvcc that is cc=g++-8. So in this case, nvcc cannot find a correspond g++ on your device. You need to install a older gcc by yourself. Once you have done that, use command ‘gcc -v’ to check your current gcc version.

When you done all the things mentioned above, your training process should be able to run successfully. If not, you might want to check if your environment variables are set correctly.