"""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