Downloads · 30 days
9
38% of all-time downloads
huzaifa1117/tinyllama_AWQ_4bit
tinyllama_AWQ_4bit is a machine learning model from huzaifa1117. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This code demonstrates how to load and run inference using the huzaifa1117/tinyllamaAWQ4bit model with quantization for efficient computation on CUDA devices.
Downloads · 30 days
9
38% of all-time downloads
All-time downloads
24
Public
Parameters
1.1B
766 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors766 MB · 100%
How the weights are stored.
I32969M · 88%
From the Hugging Face model README
This code demonstrates how to load and run inference using the huzaifa1117/tinyllama_AWQ_4bit model with quantization for efficient computation on CUDA devices.
To begin, ensure you have the necessary libraries installed:
pip install torch transformers peft awq
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
HqqConfig
)
from peft import PeftModel
import torch
from awq import AutoAWQForCausalLM
# Use CUDA if available
device = torch.device("cuda")
# Model ID and quantization configuration
model_id = "huzaifa1117/tinyllama_AWQ_4bit"
quant_config = HqqConfig(nbits=1, group_size=64, quant_zero=False, quant_scale=False, axis=1)
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Load the model with quantization on CUDA
model = AutoAWQForCausalLM.from_pretrained(model_id, low_cpu_mem_usage=True, use_cache=False, device_map='cuda')
# Move the model to the CUDA device
model.to(device)
# Tokenize input and run inference
input_text = "Your input text here"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
output = model.generate(input_ids, max_length=50)
# Decode and print the output
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
print(output_text)
The model uses HqqConfig to apply 1-bit quantization for all linear layers, ensuring high performance on resource-constrained hardware:
quant_config = HqqConfig(nbits=1, group_size=64, quant_zero=False, quant_scale=False, axis=1)
This project is licensed under the terms of the MIT license.