Image-to-Image
Diffusers
English
lora
qwen-image-edit
face-swap
head-swap
image-editing
ai-generated
comfyui
bfs
flux 2
flux
klein
Instructions to use Alissonerdx/BFS-Best-Face-Swap with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Alissonerdx/BFS-Best-Face-Swap 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("black-forest-labs/FLUX.2-klein-9B,black-forest-labs/FLUX.2-klein-4B,black-forest-labs/FLUX.2-klein-base-4B,black-forest-labs/FLUX.2-klein-base-9B,black-forest-labs/FLUX.2-klein-9b-fp8,black-forest-labs/FLUX.2-klein-4b-fp8,Qwen/Qwen-Image-Edit-2511", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("Alissonerdx/BFS-Best-Face-Swap") 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] - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
Which V5 to use?
#6
by deleted - opened
Could you try adjusting my code, It was working, but I haven't had time to update it since.
https://huggingface.co/spaces/Alissonerdx/BFS-Best-Face-Swap/tree/main
I can’t contribute/push commits with dev mode activated.
Here’s a change to the converter you could try, but I don’t know if it’s going to work.
# convert_lora.py
import torch
import safetensors.torch
UP_SUFFIXES = (".lora_up.weight", ".lora_A.weight")
DOWN_SUFFIXES = (".lora_down.weight", ".lora_B.weight")
ALPHA_SUFFIX = ".alpha"
def _map_key(k: str) -> str:
# map common comfy/kohya -> diffusers-ish naming
nk = k
nk = nk.replace("model.diffusion_model.", "transformer.")
nk = nk.replace("diffusion_model.", "transformer.")
nk = nk.replace("lora_unet.", "transformer.")
nk = nk.replace("lora_unet_", "transformer.")
return nk
def _collect_prefixes(keys):
prefixes = set()
for k in keys:
for suf in UP_SUFFIXES + DOWN_SUFFIXES:
if k.endswith(suf):
prefixes.add(k[:-len(suf)])
return prefixes
def _infer_rank(state, prefix: str) -> int:
# rank usually equals first dim of down (or up)
for suf in DOWN_SUFFIXES:
t = state.get(prefix + suf)
if t is not None and hasattr(t, "shape") and len(t.shape) > 0:
return int(t.shape[0])
for suf in UP_SUFFIXES:
t = state.get(prefix + suf)
if t is not None and hasattr(t, "shape") and len(t.shape) > 0:
return int(t.shape[0])
return 1
def convert_comfyui_lora_to_diffusers(input_path: str, output_path: str):
original = safetensors.torch.load_file(input_path)
# 1) map keys (but don't drop alpha yet)
mapped = {}
for k, v in original.items():
mapped[_map_key(k)] = v
prefixes = _collect_prefixes(mapped.keys())
# 2) remove orphan alphas (alpha without a corresponding up/down pair)
for k in list(mapped.keys()):
if k.endswith(ALPHA_SUFFIX):
prefix = k[:-len(ALPHA_SUFFIX)]
if prefix not in prefixes:
mapped.pop(k)
# 3) add missing alphas (alpha missing but up/down exist)
for p in prefixes:
akey = p + ALPHA_SUFFIX
if akey not in mapped:
rank = _infer_rank(mapped, p)
mapped[akey] = torch.tensor(float(rank), dtype=torch.float32)
safetensors.torch.save_file(mapped, output_path, metadata={"format": "diffusers"})
return output_path
That got formatted horribly, sorry.
E: fixed formatting