Skip to content
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

About Diffuser unet_2d_blocks.py #11

Closed
hmxiong opened this issue Sep 26, 2023 · 5 comments
Closed

About Diffuser unet_2d_blocks.py #11

hmxiong opened this issue Sep 26, 2023 · 5 comments

Comments

@hmxiong
Copy link

hmxiong commented Sep 26, 2023

Great work!! I have a question about code. When I use COCO Instance weights to generate images, the error "Tensors must have same number of dimensions: got 3 and 4" will be reported in model/diffusers/models/unet_2d_blocks.py. I am using the latest version of diffusers code and stable diffusion-1.4 , torch-1.10 + cu111 . The following is my error message:

File "/home/xhm/Desktop/Code/Diffusion/DatasetDM/parallel_generate_Instance_COCO_AnyClass.py", line 412, in sub_processor
images_here, x_t = ptp_utils.text2image(unet,vae,tokenizer,text_encoder,scheduler, prompts, controller, num_inference_steps=NUM_DIFFUSION_STEPS, guidance_scale=5, generator=g_cpu, low_resource=LOW_RESOURCE, Train=False)
File "/home/xhm/anaconda3/envs/datasetdm/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/xhm/Desktop/Code/Diffusion/DatasetDM/ptp_utils.py", line 212, in text2image
latents = diffusion_step_DDM(Unet, scheduler, controller, latents, context, t, guidance_scale, low_resource)
File "/home/xhm/Desktop/Code/Diffusion/DatasetDM/ptp_utils.py", line 141, in diffusion_step_DDM
noise_pred = unet(latents_input, t, encoder_hidden_states=context)["sample"]
File "/home/xhm/anaconda3/envs/datasetdm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/xhm/Desktop/Code/Diffusion/DatasetDM/model/unet.py", line 144, in forward
sample, up_samples = upsample_block(
File "/home/xhm/anaconda3/envs/datasetdm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/xhm/Desktop/Code/Diffusion/DatasetDM/model/diffusers/models/unet_2d_blocks.py", line 2202, in forward
hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1)
RuntimeError: Tensors must have same number of dimensions: got 3 and 4

I'm really sorry, I can't take a screenshot due to my computer.Thank you so much!!!

@hkxiao
Copy link

hkxiao commented Sep 28, 2023

I meet the same question. @hmxiong

@weijiawu
Copy link
Collaborator

I suspect that the error is caused by the version of Diffuser. Perhaps you can try replacing the files under ./model with Diffuser version 0.3.0 (https://pypi.org/project/diffusers/0.3.0/#files) and see if that resolves the issue.

Thanks for your attention~

@hmxiong
Copy link
Author

hmxiong commented Sep 29, 2023

Sorry, this method did not solve my problem. Here I will show the code analysis as follows:
in /diffusers/models/unet_blocks.py UpBlock2D Function only reture the hidden_states ,but in /model/unet.py you need both sample and up_samples. I think by solving this problem, I can solve mine.
image
image

@weijiawu
Copy link
Collaborator

We have already updated the diffuser at https://github.com/showlab/DatasetDM/tree/main/model/diffusers. You can directly use this version. Hope this can be helpful to you.

@hmxiong
Copy link
Author

hmxiong commented Oct 2, 2023

Thanks for sharing, the problem has been solved!!

@hmxiong hmxiong closed this as completed Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants