Views
No views yet
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 |
pip install git+https://github.com/mobiusml/hqq.git1import torch
2from transformers import AutoTokenizer
3from hqq.models.hf.base import AutoHQQHFModel
4from hqq.core.quantize import *
5from hqq.utils.patching import *
6from hqq.utils.generation_hf import HFGenerator
7
8#Settings
9###################################################
10backend = "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)
11compute_dtype = torch.bfloat16 if backend=="torchao_int4" else torch.float16
12device = 'cuda:0'
13cache_dir = '.'
14
15#Load the model
16###################################################
17model_id = "mobiuslabsgmbh/Llama-2-7b-chat-hf_4bitnogs_hqq"
18model = AutoHQQHFModel.from_quantized(model_id, cache_dir=cache_dir, compute_dtype=compute_dtype, adapter='adapter_v0.1.lora', device=device).eval();
19tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir=cache_dir)
20
21#Use optimized inference kernels
22###################################################
23prepare_for_inference(model, backend=backend) #It takes a while...
24
25#Generate
26###################################################
27#For longer context, make sure to allocate enough cache via the cache_size= parameter
28#gen = HFGenerator(model, tokenizer, max_new_tokens=1000, do_sample=True, compile=None) #Slower generation but no warm-up
29gen = HFGenerator(model, tokenizer, max_new_tokens=1000, do_sample=True, compile="partial").warmup() #Faster generation, but warm-up takes a while
30
31gen.generate("Write an essay about large language models", print_tokens=True)
32gen.generate("Tell me a funny joke!", print_tokens=True)
33gen.generate("How to make a yummy chocolate cake?", print_tokens=True)