GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers
Paper • 2210.17323 • Published • 12
How to use kevinbazira/aya-expanse-32b-gptq-4bit with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="kevinbazira/aya-expanse-32b-gptq-4bit")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("kevinbazira/aya-expanse-32b-gptq-4bit")
model = AutoModelForCausalLM.from_pretrained("kevinbazira/aya-expanse-32b-gptq-4bit", device_map="auto")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use kevinbazira/aya-expanse-32b-gptq-4bit with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "kevinbazira/aya-expanse-32b-gptq-4bit"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kevinbazira/aya-expanse-32b-gptq-4bit",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/kevinbazira/aya-expanse-32b-gptq-4bit
How to use kevinbazira/aya-expanse-32b-gptq-4bit with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "kevinbazira/aya-expanse-32b-gptq-4bit" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kevinbazira/aya-expanse-32b-gptq-4bit",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "kevinbazira/aya-expanse-32b-gptq-4bit" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kevinbazira/aya-expanse-32b-gptq-4bit",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use kevinbazira/aya-expanse-32b-gptq-4bit with Docker Model Runner:
docker model run hf.co/kevinbazira/aya-expanse-32b-gptq-4bit
This repository contains a quantized version of the CohereForAI/aya-expanse-32b model using the GPTQ method in 4-bit precision.
Before using the quantized model, please ensure your environment has:
Load and use the quantized model as shown below in Python:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Set up device
device = torch.device('cuda:1') # Remember to use the correct device here
# Load model and tokenizer
model_name = "kevinbazira/aya-expanse-32b-gptq-4bit"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map={"": device.index}
)
# Prepare input
# https://huggingface.co/docs/transformers/en/pad_truncation
input_text = "Add your prompt here."
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding="max_length", max_length=64)
inputs = {key: value.to(device) for key, value in inputs.items()}
# Perform text generation
# https://huggingface.co/docs/transformers/en/main_classes/text_generation
outputs = model.generate(
**inputs,
num_return_sequences=1,
min_new_tokens=64,
max_new_tokens=64,
do_sample=False,
use_cache=True,
num_beams=1
)
# Decode and print the output
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
contact@kevinbazira.com. I'll be happy to help!Base model
CohereLabs/aya-expanse-32b