Instructions to use Hemanth-thunder/stable_diffusion_lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Hemanth-thunder/stable_diffusion_lora with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("Hemanth-thunder/stable_diffusion_lora", dtype=torch.bfloat16, device_map="cuda") prompt = "hmat" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
| import os | |
| import torch | |
| from peft import set_peft_model_state_dict | |
| from transformers import TrainerCallback, TrainerControl, TrainerState, TrainingArguments | |
| from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR | |
| class SavePeftModelCallback(TrainerCallback): | |
| def on_save( | |
| self, | |
| args: TrainingArguments, | |
| state: TrainerState, | |
| control: TrainerControl, | |
| **kwargs, | |
| ): | |
| checkpoint_folder = os.path.join(args.output_dir, f"{PREFIX_CHECKPOINT_DIR}-{state.global_step}") | |
| kwargs["model"].save_pretrained(checkpoint_folder) | |
| pytorch_model_path = os.path.join(checkpoint_folder, "pytorch_model.bin") | |
| torch.save({}, pytorch_model_path) | |
| return control | |
| class LoadBestPeftModelCallback(TrainerCallback): | |
| def on_train_end( | |
| self, | |
| args: TrainingArguments, | |
| state: TrainerState, | |
| control: TrainerControl, | |
| **kwargs, | |
| ): | |
| print(f"Loading best peft model from {state.best_model_checkpoint} (score: {state.best_metric}).") | |
| best_model_path = os.path.join(state.best_model_checkpoint, "adapter_model.bin") | |
| adapters_weights = torch.load(best_model_path) | |
| model = kwargs["model"] | |
| set_peft_model_state_dict(model, adapters_weights) | |
| return control | |