Views
No views yet
runwayml/stable-diffusion-v1-5
Adapter file: unet_lora_final_5000.safetensors
Trained on: MagicBrush dataset (osunlp/MagicBrush)
Training steps: 5000
LoRA rank (r): 8
Device: Apple M4 Pro (MPS)
Usage: Apply this adapter to SD v1.5 UNet to enable instruction-guided editing in MagicBrush style.1from safetensors.torch import load_file
2from diffusers import StableDiffusionPipeline
3import torch
4
5pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to("mps")
6lora = load_file("unet_lora_final_5000.safetensors")
7
8# naive mapping — best-effort; adjust if attribute paths differ
9def apply_lora_to_unet(unet, lora_state):
10 for name, arr in lora_state.items():
11 parts = name.split(".")
12 target = unet
13 for p in parts[:-1]:
14 if hasattr(target, p):
15 target = getattr(target, p)
16 else:
17 try:
18 idx = int(p)
19 target = target[idx]
20 except Exception:
21 target = None
22 break
23 if target is None:
24 continue
25 attr = parts[-1]
26 if hasattr(target, attr):
27 t = torch.from_numpy(arr) if not isinstance(arr, torch.Tensor) else arr
28 getattr(target, attr).data.copy_(t.to(getattr(target, attr).device))
29
30apply_lora_to_unet(pipe.unet, lora)
31# then run pipe(...) as usual
32