ppbrown commited on
Commit
e2a91db
·
verified ·
1 Parent(s): 500c790

Upload pipeline.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pipeline.py +17 -4
pipeline.py CHANGED
@@ -89,6 +89,10 @@ class StableDiffusionT5Pipeline(StableDiffusionPipeline):
89
  )
90
 
91
  if t5_projection is None:
 
 
 
 
92
  self.t5_projection = self.create_clipholder().to(vae.device, dtype=vae.dtype)
93
  else:
94
  if isinstance(t5_projection, CLIPTextModelWithProjection):
@@ -96,6 +100,17 @@ class StableDiffusionT5Pipeline(StableDiffusionPipeline):
96
  else:
97
  raise TypeError("Error: expected t5_projection to be type CLIPTextModelWithProjection")
98
 
 
 
 
 
 
 
 
 
 
 
 
99
  # Ensure everything is properly registered for to("cuda")
100
  # and also for saving the model
101
  self.register_modules(t5_projection=self.t5_projection)
@@ -137,10 +152,8 @@ class StableDiffusionT5Pipeline(StableDiffusionPipeline):
137
  **kwargs,
138
  ):
139
 
140
- # Scaling value computed by analyzing stock output over a few thousand prompts,
141
- # and computing stdD
142
- # vs alleged expected value of 0.2
143
- scaling_factor = 1.8 # coincidentally, this is about the same as vae.config.scaling_factor
144
 
145
  pos_hidden, neg_hidden = self.encode_prompt_t5(prompt, negative_prompt, device)
146
 
 
89
  )
90
 
91
  if t5_projection is None:
92
+ print("WARNING: no CLIPTextModelWithProjection found. This may indicate an error")
93
+ answer=input("Should I auto-generate one? type 'Yes' to proceed")
94
+ if answer != "Yes":
95
+ exit(1)
96
  self.t5_projection = self.create_clipholder().to(vae.device, dtype=vae.dtype)
97
  else:
98
  if isinstance(t5_projection, CLIPTextModelWithProjection):
 
100
  else:
101
  raise TypeError("Error: expected t5_projection to be type CLIPTextModelWithProjection")
102
 
103
+ checkval = getattr(self.t5_projection.config, "scaling_factor", None)
104
+ if not checkval:
105
+ #0.013 # This is my kinda calculated factor, for norms ~ 1.0
106
+ #scaling_factor = 0.13025 # This would be the vae scaling factor
107
+ #scaling_factor = 0.035 # This is a commonly used factor for T5
108
+ # buuut... to make output stdD similar to CLIP, scaling factor = 1.8
109
+ # (See check-cache-stdd-t5.py)
110
+ scaling_factor = 1.8
111
+ print("INFO: Pipeline setting empty t5 scaling factor to", scaling_factor)
112
+ self.t5_projection.config.scaling_factor = scaling_factor
113
+
114
  # Ensure everything is properly registered for to("cuda")
115
  # and also for saving the model
116
  self.register_modules(t5_projection=self.t5_projection)
 
152
  **kwargs,
153
  ):
154
 
155
+
156
+ scaling_factor = self.t5_projection.config.scaling_factor
 
 
157
 
158
  pos_hidden, neg_hidden = self.encode_prompt_t5(prompt, negative_prompt, device)
159