Download load_model.py from Asbyx/MNLP_M3_quantized_model: direct link, hf CLI and curl.
- Browser
- Download file 955 Bytes
-
https://huggingface.co/Asbyx/MNLP_M3_quantized_model/resolve/main/load_model.py
- Command line
-
hf download hf://Asbyx/MNLP_M3_quantized_model/load_model.py
-
curl -L -o load_model.py https://huggingface.co/Asbyx/MNLP_M3_quantized_model/resolve/main/load_model.py
955 Bytes
| # 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") | |