ford442 commited on
Commit
94a95e7
·
verified ·
1 Parent(s): 6a55473

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -11,6 +11,8 @@ import uuid
11
  import gradio as gr
12
  import numpy as np
13
  from PIL import Image
 
 
14
  import diffusers
15
  from diffusers import AutoencoderKL, StableDiffusionXLPipeline
16
  from diffusers import EulerAncestralDiscreteScheduler
@@ -20,6 +22,7 @@ import datetime
20
  import cyper
21
  from image_gen_aux import UpscaleWithModel
22
  import torch
 
23
 
24
  torch.backends.cuda.matmul.allow_tf32 = False
25
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
@@ -148,19 +151,39 @@ def load_and_prepare_model():
148
  pipe.watermark=None
149
  pipe.safety_checker=None
150
 
151
- # Freeze vae and unet
152
  pipe.vae.requires_grad_(False)
153
  pipe.unet.requires_grad_(False)
154
  pipe.text_encoder.requires_grad_(False)
155
  pipe.unet.eval()
156
  pipe.vae.eval()
157
  pipe.text_encoder.eval()
 
 
 
158
 
159
  return pipe
160
 
 
 
 
161
  # Preload and compile both models
162
  pipe = load_and_prepare_model()
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  MAX_SEED = np.iinfo(np.int32).max
165
 
166
  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' "
 
11
  import gradio as gr
12
  import numpy as np
13
  from PIL import Image
14
+ import hidet
15
+
16
  import diffusers
17
  from diffusers import AutoencoderKL, StableDiffusionXLPipeline
18
  from diffusers import EulerAncestralDiscreteScheduler
 
22
  import cyper
23
  from image_gen_aux import UpscaleWithModel
24
  import torch
25
+ import torch._dynamo
26
 
27
  torch.backends.cuda.matmul.allow_tf32 = False
28
  torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
 
151
  pipe.watermark=None
152
  pipe.safety_checker=None
153
 
154
+ ''' # Freeze vae and unet
155
  pipe.vae.requires_grad_(False)
156
  pipe.unet.requires_grad_(False)
157
  pipe.text_encoder.requires_grad_(False)
158
  pipe.unet.eval()
159
  pipe.vae.eval()
160
  pipe.text_encoder.eval()
161
+ '''
162
+
163
+ pipe.unet = pipe.unet.to(memory_format=torch.contiguous_format)
164
 
165
  return pipe
166
 
167
+ hidet.option.parallel_build(True)
168
+ torch._dynamo.config.suppress_errors = True
169
+ torch._dynamo.disallow_in_graph(diffusers.models.attention.BasicTransformerBlock)
170
  # Preload and compile both models
171
  pipe = load_and_prepare_model()
172
 
173
+
174
+ # more search
175
+ hidet.torch.dynamo_config.search_space(0)
176
+ #hidet.torch.dynamo_config.dump_graph_ir("./local_graph")
177
+ hidet.option.cache_dir("local_cache")
178
+ # automatically transform the model to use float16 data type
179
+ #hidet.torch.dynamo_config.use_fp16(True)
180
+ # use float16 data type as the accumulate data type in operators with reduction
181
+ #hidet.torch.dynamo_config.use_fp16_reduction(True)
182
+ # use tensorcore
183
+ hidet.torch.dynamo_config.use_tensor_core()
184
+ pipe.unet = torch.compile(pipe.unet, backend="hidet")
185
+
186
+
187
  MAX_SEED = np.iinfo(np.int32).max
188
 
189
  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' "