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

Support for SD3 #92

Open
adhikjoshi opened this issue Jun 13, 2024 · 11 comments
Open

Support for SD3 #92

adhikjoshi opened this issue Jun 13, 2024 · 11 comments

Comments

@adhikjoshi
Copy link

Support for SD3

@Skquark
Copy link

Skquark commented Jun 13, 2024

Wondering the same. Just getting SD3 integrated into DiffusionDeluxe and wondering if I should try the same compel code I had working for SDXL, only without the refiner. The difference with the 3 pipeline is we have 3 tokenizers and text_encoders instead of 2, and not sure if it'll work with passing only 2 or if it's gonna need some reworking. I'm gonna try it out, but I get the impression it's not gonna work immediately with the new architecture, fingers crossed..

@damian0815
Copy link
Owner

i unfortunately do not have the resources to update compel for SD3. i'd be happy to accept a pull request if someone wanted to figure out how to do it. keeping up with AI dev is exhausting and i'm not getting paid to do this.

@AbhinavGopal
Copy link

AbhinavGopal commented Jun 20, 2024

I'm thinking of working on this! If anyone is interested on working on this together, shoot me an email @ [email protected] :)

@MohamedAliRashad
Copy link

MohamedAliRashad commented Jun 28, 2024

@damian0815 How can we help you ?

@damian0815
Copy link
Owner

figure out what needs to be done to support SD3 and do it :D

@damian0815
Copy link
Owner

i might see if i can spare a few hours this weekend to take a look.

@MohamedAliRashad
Copy link

MohamedAliRashad commented Jun 29, 2024

@damian0815 You don't need to. A library named sd_embed has achieved what we want.

@Daniel-SicSo-Edinburgh
Copy link

Yes, sd_embed did SD3 support for this. I would still like to see support within compel just because it is structured a bit better IMO.

@Daniel-SicSo-Edinburgh
Copy link

Also, if you are using SD3 without T5, you can use the already existing functionality with some adjustments:

path_to_file = '.../sd3_medium_incl_clips.safetensors' #path to sd3_medium_incl_clips.safetensors

model = StableDiffusion3Pipeline.from_single_file(path_to_file,
                                                  torch_dtype=torch.float16,
                                                  use_safetensors=True,
                                                  text_encoder_3=None)

prompt = 'Some prompt'
neg_prompt = 'Some negative prompt'

compeler = Compel(tokenizer=[model[1].tokenizer, model[1].tokenizer_2],
                  text_encoder=[model[1].text_encoder, model[1].text_encoder_2],
                  returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
                  truncate_long_prompts=False,
                  requires_pooled=[True, True],
                  device="cuda")
                                            
embeds, pooled_embeds = compeler([prompt, neg_prompt])

prompt_embed = embeds[0].unsqueeze(0)
neg_prompt_embed = embeds[1].unsqueeze(0)

prompt_embed = torch.nn.functional.pad(prompt_embed, (0, 2048))
neg_prompt_embed = torch.nn.functional.pad(neg_prompt_embed, (0, 2048))

pooled_prompt_embed = pooled_embeds[0].unsqueeze(0)
pooled_neg_prompt_embed = pooled_embeds[1].unsqueeze(0)


images = model(prompt_embeds=prompt_embed,
                pooled_prompt_embeds=pooled_prompt_embed,
                negative_prompt_embeds=neg_prompt_embed,
                negative_pooled_prompt_embeds=pooled_neg_prompt_embed,
                guidance_scale=3,
                num_inference_steps=40).images
                
 images[0].save('output_image.png')

@damian0815
Copy link
Owner

i have compel SD3 90% of the way there..

@nom
Copy link

nom commented Jul 28, 2024

i have compel SD3 90% of the way there..

Any update?

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

7 participants