Instructions to use AbstractPhil/SD15-Surge-V1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use AbstractPhil/SD15-Surge-V1 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("AbstractPhil/SD15-Surge-V1", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Update pipeline/pipeline.py
Browse files- pipeline/pipeline.py +27 -19
pipeline/pipeline.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# pipeline/pipeline.py
|
| 2 |
-
|
| 3 |
import torch
|
| 4 |
from diffusers import StableDiffusionPipeline
|
| 5 |
|
|
@@ -26,28 +24,38 @@ class OmegaDiffusionPipeline(StableDiffusionPipeline):
|
|
| 26 |
feature_extractor=feature_extractor,
|
| 27 |
**kwargs,
|
| 28 |
)
|
| 29 |
-
# register your custom bridge *as a module*
|
| 30 |
self.register_modules(bridge=bridge)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
@property
|
| 33 |
def components(self):
|
| 34 |
-
# Return exactly the expected components (no extras!)
|
| 35 |
return {
|
| 36 |
-
"scheduler":
|
| 37 |
-
"tokenizer":
|
| 38 |
-
"vae":
|
| 39 |
-
"unet":
|
| 40 |
-
"text_encoder":
|
| 41 |
-
"bridge":
|
| 42 |
-
"feature_extractor":self.feature_extractor,
|
| 43 |
-
"safety_checker":
|
| 44 |
-
|
| 45 |
-
"kwargs": {},
|
| 46 |
}
|
| 47 |
|
| 48 |
@torch.no_grad()
|
| 49 |
-
def
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
images = self.vae.decode(lat16 / self.vae.config.scaling_factor).sample
|
| 53 |
-
return (images.clamp(-1, 1) + 1) / 2
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
|
|
|
|
| 24 |
feature_extractor=feature_extractor,
|
| 25 |
**kwargs,
|
| 26 |
)
|
|
|
|
| 27 |
self.register_modules(bridge=bridge)
|
| 28 |
|
| 29 |
+
# --- Monkey-patch the VAE.decode method ---
|
| 30 |
+
orig_decode = self.vae.decode
|
| 31 |
+
|
| 32 |
+
def decode_with_bridge(z_scaled, *args, return_dict=False, generator=None, **decode_kwargs):
|
| 33 |
+
# z_scaled = z4 / scaling_factor
|
| 34 |
+
sc = self.vae.config.scaling_factor
|
| 35 |
+
z4 = z_scaled * sc # recover 4-channel latent
|
| 36 |
+
z16 = self.bridge.dec(z4) # map 4→16 channels
|
| 37 |
+
z16_scaled = z16 / sc # rescale for VAE
|
| 38 |
+
# call original decoder
|
| 39 |
+
return orig_decode(z16_scaled, *args, return_dict=return_dict, generator=generator, **decode_kwargs)
|
| 40 |
+
|
| 41 |
+
# Replace VAE.decode at runtime
|
| 42 |
+
self.vae.decode = decode_with_bridge
|
| 43 |
+
|
| 44 |
@property
|
| 45 |
def components(self):
|
|
|
|
| 46 |
return {
|
| 47 |
+
"scheduler": self.scheduler,
|
| 48 |
+
"tokenizer": self.tokenizer,
|
| 49 |
+
"vae": self.vae,
|
| 50 |
+
"unet": self.unet,
|
| 51 |
+
"text_encoder": self.text_encoder,
|
| 52 |
+
"bridge": self.bridge,
|
| 53 |
+
"feature_extractor": self.feature_extractor,
|
| 54 |
+
"safety_checker": self.safety_checker,
|
| 55 |
+
"kwargs": {},
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
@torch.no_grad()
|
| 59 |
+
def __call__(self, *args, **kwargs):
|
| 60 |
+
# let the parent handle everything, including calling vae.decode (now patched)
|
| 61 |
+
return super().__call__(*args, **kwargs)
|
|
|
|
|
|