Zhendong-Wang / Diffusion-GAN

Official PyTorch implementation for paper: Diffusion-GAN: Training GANs with Diffusion
MIT License
626 stars 67 forks source link

Error while running train.py #24

Open nourgeek opened 1 year ago

nourgeek commented 1 year ago

Hi, I wanted to train a model with cifar dataset, so I followed the steps described in the readme; but while running the train.py file exactly as you described in the readme, I got an error which you can see below:

Traceback (most recent call last): File "train.py", line 603, in main() # pylint: disable=no-value-for-parameter File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\click\core.py", line 1128, in call return self.main(args, kwargs) File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\click\core.py", line 1053, in main rv = self.invoke(ctx) File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\click\core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\click\core.py", line 754, in invoke return __callback(args, kwargs) File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\click\decorators.py", line 26, in new_func return f(get_current_context(), *args, kwargs) File "train.py", line 596, in main subprocess_fn(rank=0, args=args, temp_dir=temp_dir) File "train.py", line 422, in subprocess_fn training_loop.training_loop(rank=rank, args) File "C:\Users\user\Desktop\Project\Diffusion-GAN\diffusion-insgen\training\training_loop.py", line 351, in training_loop loss.accumulate_gradients(phase=phase.name, real_img=real_img, real_c=real_c, gen_z=gen_z, gen_c=gen_c, sync=sync, gain=gain, cl_phases=cl_phases, D_ema=D_ema, g_fake_cl=not no_cl_on_g, *cl_loss_weight) File "C:\Users\user\Desktop\Project\Diffusion-GAN\diffusion-insgen\training\contrastive_loss.py", line 92, in accumulate_gradients gen_logits = self.run_D(gen_img, gen_c, sync=False) File "C:\Users\user\Desktop\Project\Diffusion-GAN\diffusion-insgen\training\contrastive_loss.py", line 55, in run_D img, t = self.augment_pipe(img) File "C:\ProgramData\miniconda3\envs\difgan\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "C:\Users\user\Desktop\Project\Diffusion-GAN\diffusion-insgen\training\augment.py", line 203, in forward x_t = q_sample(x_0, alphas_bar_sqrt, one_minus_alphas_bar_sqrt, t, File "C:\Users\user\Desktop\Project\Diffusion-GAN\diffusion-insgen\training\augment.py", line 86, in q_sample alphas_t_sqrt = alphas_bar_sqrt[t].view(-1, 1, 1, 1) IndexError: tensors used as indices must be long, byte or bool tensors

I used environment.yml given in the directory as my environment. My PC specs: Windows 10 64bit - Nvidia GTX 1660 Thanks in advance for your help

Zhendong-Wang commented 1 year ago

Hi there, are you sure that you didn't modify anything? I double checked the code works well on my Linux/Ubuntu machines with the environment.yml.

If the problems exist, could consider modify https://github.com/Zhendong-Wang/Diffusion-GAN/blob/2ca5e7aa21f07a3ff0e78966e5796c580126c14f/diffusion-insgen/training/augment.py#L202 , where you want the t to be long tensors.

nourgeek commented 1 year ago

Hi, Thanks for your response. I changed to Linux/Ubuntu and used the environment.yml, but unfortunately there is another error:

warnings.warn('Failed to build CUDA kernels for upfirdn2d. Falling back to slow reference implementation. Details:\n\n' + traceback.format_exc()) Traceback (most recent call last): File "train.py", line 603, in main() # pylint: disable=no-value-for-parameter File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, kwargs) File "train.py", line 596, in main subprocess_fn(rank=0, args=args, temp_dir=temp_dir) File "train.py", line 422, in subprocess_fn training_loop.training_loop(rank=rank, args) File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/training_loop.py", line 351, in training_loop loss.accumulate_gradients(phase=phase.name, real_img=real_img, real_c=real_c, gen_z=gen_z, gen_c=gen_c, sync=sync, gain=gain, cl_phases=cl_phases, D_ema=D_ema, g_fake_cl=not no_cl_on_g, cl_loss_weight) File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/contrastive_loss.py", line 162, in accumulate_gradients loss_Dreal = loss_Dreal + lw_real_cl self.run_cl(real_img_tmp, real_c, sync, Dphase.module, D_ema, loss_name='D_cl') File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/contrastive_loss.py", line 77, in run_cl loss = contrastive_head(logits0, logits1, loss_only=loss_only, update_q=update_q) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/contrastive_head.py", line 183, in forward self._dequeue_and_enqueue(k) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, kwargs) File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/contrastive_head.py", line 51, in _dequeue_and_enqueue keys = concat_all_gather(keys) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/home/user/Desktop/Diffusion-GAN/diffusion-insgen/training/contrastive_head.py", line 197, in concat_allgather for in range(torch.distributed.get_world_size())] File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 711, in get_world_size return _get_group_size(group) File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 263, in _get_group_size default_pg = _get_default_group() File "/home/user/miniconda3/envs/difgan/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 347, in _get_default_group raise RuntimeError("Default process group has not been initialized, "

I would be glad if there is any way you know how to fix this.

Zhendong-Wang commented 1 year ago

This problem is inherited from InsGen code. The issue is solved here https://github.com/Zhendong-Wang/Diffusion-GAN/issues/10