ford442 commited on
Commit
5858e45
·
verified ·
1 Parent(s): 3c1f632

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -6,6 +6,9 @@
6
  # copies of the Software, and to permit persons to whom the Software is
7
  import spaces
8
  import os
 
 
 
9
  import random
10
  import uuid
11
  import gradio as gr
@@ -127,21 +130,22 @@ def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
127
  return {"latents": callback_kwargs["latents"]}
128
 
129
  def load_and_prepare_model():
 
130
  vaeXL = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
131
  #vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None, use_safetensors=False).to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
132
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
133
- sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
134
  pipe = StableDiffusionXLPipeline.from_pretrained(
135
  'ford442/RealVisXL_V5.0_BF16',
136
  #torch_dtype=torch.bfloat16,
137
  add_watermarker=False,
138
  # low_cpu_mem_usage = False,
139
  token = HF_TOKEN,
140
- scheduler = sched,
141
  )
142
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
143
  pipe.vae = vaeXL #.to(torch.bfloat16)
144
- #pipe.scheduler = sched
145
  #pipe.vae.do_resize=False
146
  #pipe.vae.vae_scale_factor=8
147
  pipe.vae.set_default_attn_processor()
@@ -164,23 +168,20 @@ def load_and_prepare_model():
164
 
165
  #pipe.unet.to(memory_format=torch.channels_last)
166
  #pipe.enable_vae_tiling()
167
- #pipe.unet = torch.compile(pipe.unet, backend="hidet")
168
  pipe.to(device=device, dtype=torch.bfloat16)
169
 
170
  return pipe
171
 
172
  hidet.option.parallel_build(True)
173
- hidet.option.parallel_tune(-1,4.0)
174
 
175
  torch._dynamo.config.suppress_errors = True
176
  torch._dynamo.disallow_in_graph(diffusers.models.attention.BasicTransformerBlock)
177
- # Preload and compile both models
178
-
179
- pipe = load_and_prepare_model()
180
 
181
 
182
  # more search
183
- hidet.torch.dynamo_config.search_space(0)
184
  #hidet.torch.dynamo_config.dump_graph_ir("./local_graph")
185
  hidet.option.cache_dir("local_cache")
186
  # automatically transform the model to use float16 data type
@@ -191,7 +192,10 @@ hidet.option.cache_dir("local_cache")
191
  hidet.torch.dynamo_config.use_tensor_core()
192
  #hidet.torch.dynamo_config.steal_weights(False)
193
 
194
- pipe.unet = torch.compile(pipe.unet, backend="hidet")
 
 
 
195
  MAX_SEED = np.iinfo(np.int32).max
196
 
197
  neg_prompt_2 = " 'non-photorealistic':1.5, 'unrealistic skin','unattractive face':1.3, 'low quality':1.1, ('dull color scheme', 'dull colors', 'digital noise':1.2),'amateurish', 'poorly drawn face':1.3, 'poorly drawn', 'distorted face', 'low resolution', 'simplistic' "
 
6
  # copies of the Software, and to permit persons to whom the Software is
7
  import spaces
8
  import os
9
+ import subprocess
10
+ subprocess.run(['ulimit', '-s', '512M'])
11
+
12
  import random
13
  import uuid
14
  import gradio as gr
 
130
  return {"latents": callback_kwargs["latents"]}
131
 
132
  def load_and_prepare_model():
133
+ sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
134
  vaeXL = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
135
  #vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None, use_safetensors=False).to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
136
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
137
+ #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
138
  pipe = StableDiffusionXLPipeline.from_pretrained(
139
  'ford442/RealVisXL_V5.0_BF16',
140
  #torch_dtype=torch.bfloat16,
141
  add_watermarker=False,
142
  # low_cpu_mem_usage = False,
143
  token = HF_TOKEN,
144
+ # scheduler = sched,
145
  )
146
  #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
147
  pipe.vae = vaeXL #.to(torch.bfloat16)
148
+ pipe.scheduler = sched
149
  #pipe.vae.do_resize=False
150
  #pipe.vae.vae_scale_factor=8
151
  pipe.vae.set_default_attn_processor()
 
168
 
169
  #pipe.unet.to(memory_format=torch.channels_last)
170
  #pipe.enable_vae_tiling()
171
+ pipe.unet = torch.compile(pipe.unet, backend="hidet")
172
  pipe.to(device=device, dtype=torch.bfloat16)
173
 
174
  return pipe
175
 
176
  hidet.option.parallel_build(True)
177
+ hidet.option.parallel_tune(-1,8.0)
178
 
179
  torch._dynamo.config.suppress_errors = True
180
  torch._dynamo.disallow_in_graph(diffusers.models.attention.BasicTransformerBlock)
 
 
 
181
 
182
 
183
  # more search
184
+ hidet.torch.dynamo_config.search_space(1)
185
  #hidet.torch.dynamo_config.dump_graph_ir("./local_graph")
186
  hidet.option.cache_dir("local_cache")
187
  # automatically transform the model to use float16 data type
 
192
  hidet.torch.dynamo_config.use_tensor_core()
193
  #hidet.torch.dynamo_config.steal_weights(False)
194
 
195
+ # Preload and compile both models
196
+
197
+ pipe = load_and_prepare_model()
198
+
199
  MAX_SEED = np.iinfo(np.int32).max
200
 
201
  neg_prompt_2 = " 'non-photorealistic':1.5, 'unrealistic skin','unattractive face':1.3, 'low quality':1.1, ('dull color scheme', 'dull colors', 'digital noise':1.2),'amateurish', 'poorly drawn face':1.3, 'poorly drawn', 'distorted face', 'low resolution', 'simplistic' "