ford442 commited on
Commit
a41a9cf
·
verified ·
1 Parent(s): 8cd4081

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -12,6 +12,9 @@ import gradio as gr
12
  import numpy as np
13
  from PIL import Image
14
  import torch
 
 
 
15
  from diffusers import AutoencoderKL, StableDiffusionXLPipeline
16
  #from diffusers import EulerAncestralDiscreteScheduler
17
  from typing import Tuple
@@ -100,6 +103,10 @@ def load_and_prepare_model():
100
  #pipe.vae.vae_scale_factor=8
101
  #pipe.to(device=device, dtype=torch.bfloat16)
102
  pipe.to(device)
 
 
 
 
103
  pipe.to(torch.bfloat16)
104
  pipe.vae.set_default_attn_processor()
105
  print(f'init noise scale: {pipe.scheduler.init_noise_sigma}')
@@ -110,6 +117,25 @@ def load_and_prepare_model():
110
  # Preload and compile both models
111
  pipe = load_and_prepare_model()
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  MAX_SEED = np.iinfo(np.int64).max
114
 
115
  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' "
 
12
  import numpy as np
13
  from PIL import Image
14
  import torch
15
+ import hidet
16
+ import diffusers
17
+
18
  from diffusers import AutoencoderKL, StableDiffusionXLPipeline
19
  #from diffusers import EulerAncestralDiscreteScheduler
20
  from typing import Tuple
 
103
  #pipe.vae.vae_scale_factor=8
104
  #pipe.to(device=device, dtype=torch.bfloat16)
105
  pipe.to(device)
106
+
107
+ #Make sure the unet is contiguous
108
+ pipe.unet = pipe.unet.to(memory_format=torch.contiguous_format)
109
+
110
  pipe.to(torch.bfloat16)
111
  pipe.vae.set_default_attn_processor()
112
  print(f'init noise scale: {pipe.scheduler.init_noise_sigma}')
 
117
  # Preload and compile both models
118
  pipe = load_and_prepare_model()
119
 
120
+
121
+ # for compile
122
+ hidet.option.parallel_build(True)
123
+ torch._dynamo.config.suppress_errors = True
124
+ torch._dynamo.disallow_in_graph(diffusers.models.attention.BasicTransformerBlock)
125
+ # more search
126
+ hidet.torch.dynamo_config.search_space(0)
127
+ #hidet.torch.dynamo_config.dump_graph_ir("./local_graph")
128
+ hidet.option.cache_dir("local_cache")
129
+ # automatically transform the model to use float16 data type
130
+ hidet.torch.dynamo_config.use_fp16(True)
131
+ # use float16 data type as the accumulate data type in operators with reduction
132
+ hidet.torch.dynamo_config.use_fp16_reduction(True)
133
+ # use tensorcore
134
+ hidet.torch.dynamo_config.use_tensor_core()
135
+ pipe.unet = torch.compile(pipe.unet, backend="hidet")
136
+
137
+
138
+
139
  MAX_SEED = np.iinfo(np.int64).max
140
 
141
  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' "