Instructions to use xmadai/gemma-2-9b-it-xMADai-INT4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xmadai/gemma-2-9b-it-xMADai-INT4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="xmadai/gemma-2-9b-it-xMADai-INT4") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("xmadai/gemma-2-9b-it-xMADai-INT4") model = AutoModelForMultimodalLM.from_pretrained("xmadai/gemma-2-9b-it-xMADai-INT4") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use xmadai/gemma-2-9b-it-xMADai-INT4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xmadai/gemma-2-9b-it-xMADai-INT4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xmadai/gemma-2-9b-it-xMADai-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/xmadai/gemma-2-9b-it-xMADai-INT4
- SGLang
How to use xmadai/gemma-2-9b-it-xMADai-INT4 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "xmadai/gemma-2-9b-it-xMADai-INT4" \ --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": "xmadai/gemma-2-9b-it-xMADai-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "xmadai/gemma-2-9b-it-xMADai-INT4" \ --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": "xmadai/gemma-2-9b-it-xMADai-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use xmadai/gemma-2-9b-it-xMADai-INT4 with Docker Model Runner:
docker model run hf.co/xmadai/gemma-2-9b-it-xMADai-INT4
This model has been xMADified!
This repository contains google/gemma-2-9b-it quantized from 16-bit floats to 4-bit integers, using xMAD.ai proprietary technology.
Why should I use this model?
Accuracy: This xMADified model is the best quantized version of the
google/gemma-2-9b-itmodel (8 GB only). See Table 1 below for model quality benchmarks.Memory-efficiency: The full-precision model is around 18.5 GB, while this xMADified model is only around 8 GB, making it feasible to run on a 12 GB GPU.
Fine-tuning: These models are fine-tunable over the same reduced (12 GB GPU) hardware in mere 3-clicks. Watch our product demo here
Table 1: xMAD vs. Hugging Quants
| Model | MMLU | Arc Challenge | Arc Easy | LAMBADA Standard | LAMBADA OpenAI | PIQA | WinoGrande |
|---|---|---|---|---|---|---|---|
| xmadai/gemma-2-9b-it-xMADai-INT4 (this model) | 71.17 | 62.37 | 85.61 | 70.60 | 72.15 | 81.50 | 75.06 |
| hugging-quants/gemma-2-9b-it-AWQ-INT4 | 71.04 | 61.77 | 85.14 | 69.16 | 70.68 | 80.41 | 75.06 |
How to Run Model
Loading the model checkpoint of this xMADified model requires around 8 GB of VRAM. Hence it can be efficiently run on a 12 GB GPU.
Package prerequisites:
- Run the following *commands to install the required packages.
pip install torch==2.4.0 # Run following if you have CUDA version 11.8: pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu118
pip install transformers accelerate optimum
pip install -vvv --no-build-isolation "git+https://github.com/PanQiWei/AutoGPTQ.git@v0.7.1"
Sample Inference Code
from transformers import AutoTokenizer
from auto_gptq import AutoGPTQForCausalLM
model_id = "xmadai/gemma-2-9b-it-xMADai-INT4"
prompt = [
{"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
{"role": "user", "content": "What's Deep Learning?"},
]
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
inputs = tokenizer.apply_chat_template(
prompt,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
return_dict=True,
).to("cuda")
model = AutoGPTQForCausalLM.from_quantized(
model_id,
device_map='auto',
trust_remote_code=True,
)
outputs = model.generate(**inputs, do_sample=True, max_new_tokens=1024)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
Citation
If you found this model useful, please cite our research paper.
@article{zhang2024leanquant,
title={LeanQuant: Accurate and Scalable Large Language Model Quantization with Loss-error-aware Grid},
author={Zhang, Tianyi and Shrivastava, Anshumali},
journal={arXiv preprint arXiv:2407.10032},
year={2024},
url={https://arxiv.org/abs/2407.10032},
}
Contact Us
For additional xMADified models, access to fine-tuning, and general questions, please contact us at support@xmad.ai and join our waiting list.
- Downloads last month
- 4