markhristov commited on
Commit
ac3f08e
·
1 Parent(s): 686a471

No Nvidia GPU...

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -8,11 +8,11 @@ import gradio as gr
8
  #from IPython.display import display
9
 
10
  tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16)
11
- text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16).to("cuda")
12
 
13
  # Here we use a different VAE to the original release, which has been fine-tuned for more steps
14
- vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-ema", torch_dtype=torch.float16).to("cuda")
15
- unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet", torch_dtype=torch.float16).to("cuda")
16
 
17
  beta_start,beta_end = 0.00085,0.012
18
  height = 512
@@ -27,7 +27,7 @@ scheduler = LMSDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_
27
  def text_enc(prompts, maxlen=None):
28
  if maxlen is None: maxlen = tokenizer.model_max_length
29
  inp = tokenizer(prompts, padding="max_length", max_length=maxlen, truncation=True, return_tensors="pt")
30
- return text_encoder(inp.input_ids.to("cuda"))[0].half()
31
 
32
  def do_both(prompts):
33
  def mk_img(t):
@@ -43,7 +43,7 @@ def do_both(prompts):
43
 
44
  latents = torch.randn((bs, unet.config.in_channels, height//8, width//8))
45
  scheduler.set_timesteps(steps)
46
- latents = latents.to("cuda").half() * scheduler.init_noise_sigma
47
 
48
  for i,ts in enumerate(tqdm(scheduler.timesteps)):
49
  inp = scheduler.scale_model_input(torch.cat([latents] * 2), ts)
 
8
  #from IPython.display import display
9
 
10
  tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16)
11
+ text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16).to("cpu")
12
 
13
  # Here we use a different VAE to the original release, which has been fine-tuned for more steps
14
+ vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-ema", torch_dtype=torch.float16).to("cpu")
15
+ unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet", torch_dtype=torch.float16).to("cpu")
16
 
17
  beta_start,beta_end = 0.00085,0.012
18
  height = 512
 
27
  def text_enc(prompts, maxlen=None):
28
  if maxlen is None: maxlen = tokenizer.model_max_length
29
  inp = tokenizer(prompts, padding="max_length", max_length=maxlen, truncation=True, return_tensors="pt")
30
+ return text_encoder(inp.input_ids.to("cpu"))[0].half()
31
 
32
  def do_both(prompts):
33
  def mk_img(t):
 
43
 
44
  latents = torch.randn((bs, unet.config.in_channels, height//8, width//8))
45
  scheduler.set_timesteps(steps)
46
+ latents = latents.to("cpu").half() * scheduler.init_noise_sigma
47
 
48
  for i,ts in enumerate(tqdm(scheduler.timesteps)):
49
  inp = scheduler.scale_model_input(torch.cat([latents] * 2), ts)