Advertisement
fawk232

Untitled

Jan 1st, 2025
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | Source Code | 0 0
  1. import torch
  2. from diffusers import StableDiffusionXLPipeline, AutoencoderKL, StableDiffusionXLImg2ImgPipeline, AutoPipelineForText2Image, \
  3.     DDIMScheduler, EulerAncestralDiscreteScheduler
  4. from transformers import CLIPTextModel
  5.  
  6. from utils.get_pipeline_embeds import get_pipeline_embeds
  7.  
  8. pipeline = StableDiffusionXLPipeline.from_single_file(
  9.     "local_model",
  10.     torch_dtype=torch.float16).to("cuda")
  11.  
  12. text_encoder = pipeline.text_encoder
  13. tokenizer = pipeline.tokenizer
  14.  
  15. pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
  16.  
  17. vae = AutoencoderKL.from_single_file("local_vae").to("cuda")
  18.  
  19.  
  20. pipeline.scheduler.beta_start = 0.00085
  21. pipeline.scheduler.beta_end = 0.012
  22.  
  23. pipeline_text2image = AutoPipelineForText2Image.from_pipe(
  24.     pipeline
  25. )
  26.  
  27. prompt = 25 * "a photo of an astronaut riding a horse on mars"
  28. negative_prompt = 25 * "earth, donkey, plants, water, cars"
  29. num_inference_steps = 20  # Number of steps
  30. guidance_scale = 7.5  # CFG scale
  31.  
  32.  
  33. prompt_embeds, negative_prompt_embeds = get_pipeline_embeds(pipeline, prompt, negative_prompt, "cuda")
  34.  
  35. pooled_prompt_embeds = prompt_embeds.mean(dim=1)
  36. pooled_negative_prompt_embeds = negative_prompt_embeds.mean(dim=1)
  37.  
  38. print("Prompt Embeds Shape:", prompt_embeds.shape)
  39. print("Negative Prompt Embeds Shape:", negative_prompt_embeds.shape)
  40.  
  41.  
  42. image = pipeline_text2image(
  43.     prompt_embeds=prompt_embeds,
  44.     pooled_prompt_embeds=pooled_prompt_embeds,
  45.     negative_prompt_embeds=negative_prompt_embeds,
  46.     negative_pooled_prompt_embeds=pooled_negative_prompt_embeds,
  47.     num_inference_steps=num_inference_steps,
  48.     guidance_scale=guidance_scale,
  49.     text_encoder=text_encoder,
  50. ).images[0]
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement