ml-explore / ml-explore/mlx-examples
Add support for HF checkpoints for SD/ SDXL in the Text-to-Image example.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
It's mostly just a dump of how we can unlock 10K+ LoRA's on the Hub for MLX-examples.
Currently the model example loads the individual weights like here: code pointer
Majority of the LoRA checkpoints on the Hub would have some form of weights like here - note: that these are just the LoRA weights and not the weights of the whole backbone.
These weights can be fused with the base model by running the following code-snippet:
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
pipeline.load_lora_weights("sayakpaul/corgy_dog_LoRA-test", weight_name="pytorch_lora_weights.safetensors")
pipeline.fuse_lora()
Once fused we'd have a similar structure as required by the MLX example script.
So the new flow could be as follow:
- If an end-user provides LoRA weights then load them.
- Once loaded fuse them with their base_model.
- After fusing pass the local directory over to the loading function.
- Generate images!
Bonus: Usually the LoRA weights have reference to their base_model in the README (Example) - so later on when we have support for SDXL too this could work out well.
Let me know if this doesn't make sense! 🤗
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with stable_diffusion/stable_diffusion/model_io.py at the linked loading code and trace the model example's loading function. Compare the Hugging Face LoRA checkpoint layout with the provided DiffusionPipeline flow, then verify that fused local weights can be passed to image generation for SD and SDXL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- huggingface, python, pytorch
- Domain
- ai, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100