Text-to-Image
Transformers
Safetensors
Hunyuan
text-generation
hunyuan
quantization
nf4
comfyui
custom-nodes
autoregressive
DiT
HunyuanImage-3.0
bitsandbytes
4bit
custom_code
4-bit precision
Instructions to use dong16/HunyuanImage-3-NF4-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dong16/HunyuanImage-3-NF4-v2 with Transformers:
# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("dong16/HunyuanImage-3-NF4-v2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| """ | |
| Quick loader for quantized HunyuanImage-3.0 model. | |
| Generated automatically by hunyuan_quantize_nf4.py | |
| """ | |
| import torch | |
| from transformers import AutoModelForCausalLM, BitsAndBytesConfig | |
| def load_quantized_hunyuan(model_path="H:\Testing\HunyuanImage-3-NF4-v2"): | |
| """Load the NF4 quantized HunyuanImage-3.0 model.""" | |
| quant_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_use_double_quant=True, | |
| bnb_4bit_compute_dtype=torch.bfloat16, | |
| ) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_path, | |
| quantization_config=quant_config, | |
| device_map="cuda:0", # Load entirely on GPU 0 | |
| trust_remote_code=True, | |
| torch_dtype=torch.bfloat16, | |
| attn_implementation="sdpa", | |
| ) | |
| # Load tokenizer | |
| model.load_tokenizer(model_path) | |
| return model | |
| if __name__ == "__main__": | |
| print("Loading quantized model...") | |
| model = load_quantized_hunyuan() | |
| print("Model loaded successfully!") | |
| print(f"Device map: {model.hf_device_map}") | |