Image-to-Image
Diffusers
Safetensors
image-decomposition
layered-image-editing
diffusion
flux
lora
transparent-rgba
Instructions to use SynLayers/synlayers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use SynLayers/synlayers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("fill-in-base-model", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("SynLayers/synlayers") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps
- Draw Things
Upload infer/common_infer.py with huggingface_hub
Browse files- infer/common_infer.py +13 -3
infer/common_infer.py
CHANGED
|
@@ -29,6 +29,14 @@ def resolve_local_config_path(path: str | None) -> str | None:
|
|
| 29 |
return os.path.join(PROJECT_ROOT, path)
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def scale_box_xyxy(box, source_size: int, target_size: int) -> tuple:
|
| 33 |
"""Scale an xyxy box from source_size to target_size."""
|
| 34 |
scale = target_size / source_size
|
|
@@ -92,7 +100,9 @@ def initialize_pipeline(config):
|
|
| 92 |
single_layer_decoder=config.get("single_layer_decoder", None),
|
| 93 |
)
|
| 94 |
transp_vae = CustomVAE(vae_args)
|
| 95 |
-
transp_vae_weights =
|
|
|
|
|
|
|
| 96 |
missing_keys, unexpected_keys = transp_vae.load_state_dict(
|
| 97 |
transp_vae_weights["model"], strict=False
|
| 98 |
)
|
|
@@ -141,7 +151,7 @@ def initialize_pipeline(config):
|
|
| 141 |
layer_pe_path = os.path.join(layer_ckpt, "layer_pe.pth") if layer_ckpt else ""
|
| 142 |
if os.path.exists(layer_pe_path):
|
| 143 |
print(f"[INFO] Loading layer_pe from {layer_pe_path}...", flush=True)
|
| 144 |
-
layer_pe = torch.
|
| 145 |
transformer.load_state_dict(layer_pe, strict=False)
|
| 146 |
|
| 147 |
print("[INFO] Loading MultiLayer-Adapter...", flush=True)
|
|
@@ -174,4 +184,4 @@ def initialize_pipeline(config):
|
|
| 174 |
print(f"[INFO] Loading trained LoRA from {lora_ckpt}...", flush=True)
|
| 175 |
pipeline.load_lora_weights(lora_ckpt, adapter_name="layer")
|
| 176 |
|
| 177 |
-
return pipeline, transp_vae
|
|
|
|
| 29 |
return os.path.join(PROJECT_ROOT, path)
|
| 30 |
|
| 31 |
|
| 32 |
+
def load_trusted_checkpoint(path: str, map_location=None):
|
| 33 |
+
"""Load SynLayers-owned checkpoints saved before PyTorch changed weights_only defaults."""
|
| 34 |
+
try:
|
| 35 |
+
return torch.load(path, map_location=map_location, weights_only=False)
|
| 36 |
+
except TypeError:
|
| 37 |
+
return torch.load(path, map_location=map_location)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def scale_box_xyxy(box, source_size: int, target_size: int) -> tuple:
|
| 41 |
"""Scale an xyxy box from source_size to target_size."""
|
| 42 |
scale = target_size / source_size
|
|
|
|
| 100 |
single_layer_decoder=config.get("single_layer_decoder", None),
|
| 101 |
)
|
| 102 |
transp_vae = CustomVAE(vae_args)
|
| 103 |
+
transp_vae_weights = load_trusted_checkpoint(
|
| 104 |
+
transp_vae_path, map_location=torch.device("cuda")
|
| 105 |
+
)
|
| 106 |
missing_keys, unexpected_keys = transp_vae.load_state_dict(
|
| 107 |
transp_vae_weights["model"], strict=False
|
| 108 |
)
|
|
|
|
| 151 |
layer_pe_path = os.path.join(layer_ckpt, "layer_pe.pth") if layer_ckpt else ""
|
| 152 |
if os.path.exists(layer_pe_path):
|
| 153 |
print(f"[INFO] Loading layer_pe from {layer_pe_path}...", flush=True)
|
| 154 |
+
layer_pe = load_trusted_checkpoint(layer_pe_path, map_location=torch.device("cuda"))
|
| 155 |
transformer.load_state_dict(layer_pe, strict=False)
|
| 156 |
|
| 157 |
print("[INFO] Loading MultiLayer-Adapter...", flush=True)
|
|
|
|
| 184 |
print(f"[INFO] Loading trained LoRA from {lora_ckpt}...", flush=True)
|
| 185 |
pipeline.load_lora_weights(lora_ckpt, adapter_name="layer")
|
| 186 |
|
| 187 |
+
return pipeline, transp_vae
|