Downloads · 30 days
36
7% of all-time downloads
mobiuslabsgmbh/Llama-2-7b-chat-hf_4bitnogs_hqq
Llama-2-7b-chat-hf_4bitnogs_hqq is a text generation model from mobiuslabsgmbh. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as llama2.
This is an <a href="https://github.com/mobiusml/hqq/"HQQ</a 4-bit quantized <a href="https://huggingface.co/meta-llama/Llama-2-7b-chat-hf" Llama2-7B-chat model </a <iwithout grouping</i using a low-rank adapter to imp…
Downloads · 30 days
36
7% of all-time downloads
All-time downloads
514
Public
Repo size
4 GB
Likes
1
Public
Click a slice to open those files.
.pt3.8 GB · 95%
From the Hugging Face model README
This is an <a href="https://github.com/mobiusml/hqq/">HQQ</a> 4-bit quantized <a href="https://huggingface.co/meta-llama/Llama-2-7b-chat-hf"> Llama2-7B-chat model </a> <i>without grouping</i> using a low-rank adapter to improve the performance (referred to as <a href="https://mobiusml.github.io/1bit_blog/">HQQ+</a>).
This model doesn't use grouping to make it compatible with the fast <a href="https://github.com/IST-DASLab/marlin/tree/master/marlin">Marlin</a> inference kernel.
Running quantized models efficiently for inference requires using fused matrix-vector multiplications. The kernels available now have some constraints on the choice of the group-size and the axis along-which quantization is performed.
This model doesn't use grouping to make it compatible with all the kernels that operate along axis=1.
| Models | Llama2-7B-chat (fp16) | Llama2-7B-chat (HQQ+ 4-bit/no-gs) |
|---|---|---|
| ARC (25-shot) | 53.67 | 48.46 |
| HellaSwag (10-shot) | 78.56 | 73.33 |
| MMLU (5-shot) | 48.16 | 44.87 |
| TruthfulQA-MC2 | 45.32 | 43.27 |
| Winogrande (5-shot) | 72.53 | 71.67 |
| GSM8K (5-shot) | 23.12 | 27.82 |
| Average | 53.56 | 51.57 |
First, install the latest version of <a href="https://github.com/mobiusml/hqq/">HQQ</a>:
pip install git+https://github.com/mobiusml/hqq.git
Then you can use the sample code below:
import torch
from transformers import AutoTokenizer
from hqq.models.hf.base import AutoHQQHFModel
from hqq.core.quantize import *
from hqq.utils.patching import *
from hqq.utils.generation_hf import HFGenerator
#Settings
###################################################
backend = "torchao_int4" #'torchao_int4' #"torchao_int4" (4-bit only) or "bitblas" (4-bit + 2-bit) or "gemlite" (8-bit, 4-bit, 2-bit, 1-bit)
compute_dtype = torch.bfloat16 if backend=="torchao_int4" else torch.float16
device = 'cuda:0'
cache_dir = '.'
#Load the model
###################################################
model_id = "mobiuslabsgmbh/Llama-2-7b-chat-hf_4bitnogs_hqq"
model = AutoHQQHFModel.from_quantized(model_id, cache_dir=cache_dir, compute_dtype=compute_dtype, adapter='adapter_v0.1.lora', device=device).eval();
tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir=cache_dir)
#Use optimized inference kernels
###################################################
prepare_for_inference(model, backend=backend) #It takes a while...
#Generate
###################################################
#For longer context, make sure to allocate enough cache via the cache_size= parameter
#gen = HFGenerator(model, tokenizer, max_new_tokens=1000, do_sample=True, compile=None) #Slower generation but no warm-up
gen = HFGenerator(model, tokenizer, max_new_tokens=1000, do_sample=True, compile="partial").warmup() #Faster generation, but warm-up takes a while
gen.generate("Write an essay about large language models", print_tokens=True)
gen.generate("Tell me a funny joke!", print_tokens=True)
gen.generate("How to make a yummy chocolate cake?", print_tokens=True)