Views
No views yet

| Models | Mixtral Original | HQQ quantized |
|---|---|---|
| Runtime VRAM | 94 GB | 13.6 GB |
| ARC (25-shot) | 70.22 | 68.26 |
| Hellaswag (10-shot) | 87.63 | 85.73 |
| MMLU (5-shot) | 71.16 | 68.69 |
| TruthfulQA-MC2 | 64.58 | 64.52 |
| Winogrande (5-shot) | 81.37 | 80.19 |
| GSM8K (5-shot) | 60.73 | 52.69 |
| Average | 72.62 | 70.01 |
#This model is deprecated and requires older versions
pip install hqq==0.1.8
pip install transformers==4.46.01import transformers
2from threading import Thread
3
4model_id = 'mobiuslabsgmbh/Mixtral-8x7B-Instruct-v0.1-hf-attn-4bit-moe-2bitgs8-metaoffload-HQQ'
5#Load the model
6from hqq.engine.hf import HQQModelForCausalLM, AutoTokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = HQQModelForCausalLM.from_quantized(model_id)
9
10#Optional: set backend/compile
11#You will need to install CUDA kernels apriori
12# git clone https://github.com/mobiusml/hqq/
13# cd hqq/kernels && python setup_cuda.py install
14from hqq.core.quantize import *
15HQQLinear.set_backend(HQQBackend.ATEN_BACKPROP)
16
17
18def chat_processor(chat, max_new_tokens=100, do_sample=True):
19 tokenizer.use_default_system_prompt = False
20 streamer = transformers.TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
21
22 generate_params = dict(
23 tokenizer("<s> [INST] " + chat + " [/INST] ", return_tensors="pt").to('cuda'),
24 streamer=streamer,
25 max_new_tokens=max_new_tokens,
26 do_sample=do_sample,
27 top_p=0.90,
28 top_k=50,
29 temperature= 0.6,
30 num_beams=1,
31 repetition_penalty=1.2,
32 )
33
34 t = Thread(target=model.generate, kwargs=generate_params)
35 t.start()
36 outputs = []
37 for text in streamer:
38 outputs.append(text)
39 print(text, end="", flush=True)
40
41 return outputs
42
43################################################################################################
44#Generation
45outputs = chat_processor("How do I build a car?", max_new_tokens=1000, do_sample=False)1from hqq.engine.hf import HQQModelForCausalLM, AutoTokenizer
2
3model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
4model = HQQModelForCausalLM.from_pretrained(model_id, use_auth_token=hf_auth, cache_dir=cache_path)
5
6#Quantize params
7from hqq.core.quantize import *
8attn_prams = BaseQuantizeConfig(nbits=4, group_size=64, offload_meta=True)
9experts_params = BaseQuantizeConfig(nbits=2, group_size=8, offload_meta=True)
10
11zero_scale_group_size = 128
12attn_prams['scale_quant_params']['group_size'] = zero_scale_group_size
13attn_prams['zero_quant_params']['group_size'] = zero_scale_group_size
14experts_params['scale_quant_params']['group_size'] = zero_scale_group_size
15experts_params['zero_quant_params']['group_size'] = zero_scale_group_size
16
17quant_config = {}
18#Attention
19quant_config['self_attn.q_proj'] = attn_prams
20quant_config['self_attn.k_proj'] = attn_prams
21quant_config['self_attn.v_proj'] = attn_prams
22quant_config['self_attn.o_proj'] = attn_prams
23#Experts
24quant_config['block_sparse_moe.experts.w1'] = experts_params
25quant_config['block_sparse_moe.experts.w2'] = experts_params
26quant_config['block_sparse_moe.experts.w3'] = experts_params
27
28#Quantize
29model.quantize_model(quant_config=quant_config, compute_dtype=torch.float16);
30model.eval();