# Custom loading function for quantized model import torch from transformers import AutoModelForCausalLM, AutoConfig def load_quantized_model(model_name_or_path, device="auto"): """ Load quantized model with proper handling of int8 parameters """ print("Loading quantized model...") # Load with no gradients with torch.no_grad(): model = AutoModelForCausalLM.from_pretrained( model_name_or_path, torch_dtype=torch.float32, # This will be mixed automatically device_map=device, trust_remote_code=True, low_cpu_mem_usage=True ) # Ensure int8 parameters don't require gradients for name, param in model.named_parameters(): if param.dtype == torch.int8: param.requires_grad = False print("Model loaded successfully!") return model # Usage: # model = load_quantized_model("your-username/your-model-name")