Download model_loading.py from srijaydeshpande/motion_video_generator: direct link, hf CLI and curl.
- Browser
- Download file 964 Bytes
-
https://huggingface.co/spaces/srijaydeshpande/motion_video_generator/resolve/main/model_loading.py
- Command line
-
hf download hf://spaces/srijaydeshpande/motion_video_generator/model_loading.py
-
curl -L -o model_loading.py https://huggingface.co/spaces/srijaydeshpande/motion_video_generator/resolve/main/model_loading.py
964 Bytes
| """Eager 8-bit loading so both native pipelines fit one ZeroGPU allocation.""" | |
| import torch | |
| from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig | |
| from transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfig | |
| QUANTIZATION = "bitsandbytes-int8 (transformer and text encoder)" | |
| def load_quantized_components(model_dir, transformer_class, encoder_class): | |
| """Use the ZeroGPU-aware BNB loader, without device mapping other components.""" | |
| transformer = transformer_class.from_pretrained( | |
| model_dir, subfolder="transformer", dtype=torch.bfloat16, | |
| quantization_config=DiffusersBitsAndBytesConfig(load_in_8bit=True), | |
| device_map="cuda", | |
| ) | |
| text_encoder = encoder_class.from_pretrained( | |
| str(model_dir) + "/text_encoder", dtype=torch.bfloat16, | |
| quantization_config=TransformersBitsAndBytesConfig(load_in_8bit=True), | |
| device_map="cuda", | |
| ) | |
| return transformer, text_encoder | |