Video-to-Video
Diffusers
English
Chinese
video-editing
streaming
quantization
int8
text-stream-stripping
Instructions to use kylinfires/Joy-face_change_optimized with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use kylinfires/Joy-face_change_optimized with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("kylinfires/Joy-face_change_optimized", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download training/src/utils/lora.py from kylinfires/Joy-face_change_optimized: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/kylinfires/Joy-face_change_optimized/resolve/main/training/src/utils/lora.py
- Command line
-
hf download hf://kylinfires/Joy-face_change_optimized/training/src/utils/lora.py
-
curl -L -o lora.py https://huggingface.co/kylinfires/Joy-face_change_optimized/resolve/main/training/src/utils/lora.py
1.8 kB
| """Validate and gather adapter weights without materializing the frozen backbone.""" | |
| from collections.abc import Mapping | |
| import torch | |
| import torch.distributed as dist | |
| from torch.distributed.tensor import DTensor | |
| def validate_lora_state_dict(model, weights, adapter_name: str) -> None: | |
| from peft.utils import get_peft_model_state_dict | |
| if not isinstance(weights, Mapping): | |
| raise ValueError(f"LoRA adapter {adapter_name!r} must contain a state dictionary.") | |
| expected = get_peft_model_state_dict(model, adapter_name=adapter_name, save_embedding_layers=False) | |
| missing = sorted(expected.keys() - weights.keys()) | |
| unexpected = sorted(weights.keys() - expected.keys()) | |
| mismatched = [ | |
| name for name in expected.keys() & weights.keys() | |
| if not isinstance(weights[name], torch.Tensor) or weights[name].shape != expected[name].shape | |
| ] | |
| if not expected or missing or unexpected or mismatched: | |
| raise ValueError( | |
| f"LoRA adapter {adapter_name!r} does not match the model: " | |
| f"missing={missing[:20]}, unexpected={unexpected[:20]}, " | |
| f"shape_mismatch={sorted(mismatched)[:20]}." | |
| ) | |
| def gather_lora_state_dict(model, adapter_name: str) -> dict[str, torch.Tensor]: | |
| from peft.utils import get_peft_model_state_dict | |
| # FSDP2 state_dict() returns DTensors without gathering the full model. | |
| adapter_state = get_peft_model_state_dict(model, adapter_name=adapter_name, save_embedding_layers=False) | |
| is_writer = not dist.is_initialized() or dist.get_rank() == 0 | |
| gathered = {} | |
| for name, value in adapter_state.items(): | |
| if isinstance(value, DTensor): | |
| value = value.full_tensor() | |
| if is_writer: | |
| gathered[name] = value.detach().cpu() | |
| return gathered | |