Views
No views yet
8.0 or higher.nvcr.io/nvidia/pytorch:23.06-py3 image is runtime v12.1 but otherwise the same as the configuration above and has also been verified to work.1git clone https://github.com/mit-han-lab/llm-awq \
2&& cd llm-awq \
3&& git checkout f084f40bd996f3cf3a0633c1ad7d9d476c318aaa \
4&& pip install -e . \
5&& cd awq/kernels \
6&& python setup.py install1import time
2import torch
3from awq.quantize.quantizer import real_quantize_model_weight
4from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer, TextStreamer
5from accelerate import init_empty_weights, load_checkpoint_and_dispatch
6from huggingface_hub import snapshot_download
7
8model_name = "abhinavkulkarni/Salesforce-codegen25-7b-multi-w4-g128-awq"
9
10# Config
11config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
12
13# Tokenizer
14tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name, trust_remote_code=True)
15
16# Model
17w_bit = 4
18q_config = {
19 "zero_point": True,
20 "q_group_size": 128,
21}
22
23load_quant = snapshot_download(model_name)
24
25with init_empty_weights():
26 model = AutoModelForCausalLM.from_config(config=config,
27 torch_dtype=torch.float16, trust_remote_code=True)
28
29real_quantize_model_weight(model, w_bit=w_bit, q_config=q_config, init_only=True)
30model.tie_weights()
31
32model = load_checkpoint_and_dispatch(model, load_quant, device_map="balanced")
33
34# Inference
35prompt = f'''def hello_world():\n'''
36
37input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
38output = model.generate(
39 inputs=input_ids,
40 temperature=0.7,
41 max_new_tokens=512,
42 top_p=0.15,
43 top_k=0,
44 repetition_penalty=1.1,
45 eos_token_id=tokenizer.eos_token_id,
46 streamer=streamer)| Task | Version | Metric | Value | Stderr | |
|---|---|---|---|---|---|
| wikitext | 1 | word_perplexity | 28.8147 | ||
| byte_perplexity | 1.8748 | ||||
| bits_per_byte | 0.9067 |
| Task | Version | Metric | Value | Stderr | |
|---|---|---|---|---|---|
| wikitext | 1 | word_perplexity | 29.4323 | ||
| byte_perplexity | 1.8823 | ||||
| bits_per_byte | 0.9125 |
1@article{Nijkamp2023codegen2,
2 title={CodeGen2: Lessons for Training LLMs on Programming and Natural Languages},
3 author={Nijkamp, Erik and Hayashi, Hiroaki and Xiong, Caiming and Savarese, Silvio and Zhou, Yingbo},
4 journal={arXiv preprint},
5 year={2023}
6}@article{lin2023awq,
title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration},
author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song},
journal={arXiv},
year={2023}
}