Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16"
5number_gpus = 1
6max_model_len = 8192
7
8sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
9
10tokenizer = AutoTokenizer.from_pretrained(model_id)
11
12messages = [
13 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
14 {"role": "user", "content": "Who are you?"},
15]
16
17prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
18
19llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
20
21outputs = llm.generate(prompts, sampling_params)
22
23generated_text = outputs[0].outputs[0].text
24print(generated_text)1from transformers import AutoTokenizer
2from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
3from datasets import load_dataset
4
5model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
6
7num_samples = 756
8max_seq_len = 4064
9
10tokenizer = AutoTokenizer.from_pretrained(model_id)
11
12def preprocess_fn(example):
13 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
14
15ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
16ds = ds.shuffle().select(range(num_samples))
17ds = ds.map(preprocess_fn)
18
19examples = [tokenizer(example["text"], padding=False, max_length=max_seq_len, truncation=True) for example in ds]
20
21quantize_config = BaseQuantizeConfig(
22 bits=4,
23 group_size=128,
24 desc_act=True,
25 model_file_base_name="model",
26 damp_percent=0.1,
27)
28
29model = AutoGPTQForCausalLM.from_pretrained(
30 model_id,
31 quantize_config,
32 device_map="auto",
33)
34
35model.quantize(examples)
36model.save_pretrained("Meta-Llama-3.1-8B-Instruct-quantized.w4a16")| Category | Benchmark | Meta-Llama-3.1-8B-Instruct | Meta-Llama-3.1-8B-Instruct-quantized.w4a16 (this model) | Recovery |
| LLM as a judge | Arena Hard | 25.8 (25.1 / 26.5) | 27.2 (27.6 / 26.7) | 105.4% |
| OpenLLM v1 | MMLU (5-shot) | 68.3 | 66.9 | 97.9% |
| MMLU (CoT, 0-shot) | 72.8 | 71.1 | 97.6% | |
| ARC Challenge (0-shot) | 81.4 | 80.2 | 98.0% | |
| GSM-8K (CoT, 8-shot, strict-match) | 82.8 | 82.9 | 100.2% | |
| Hellaswag (10-shot) | 80.5 | 79.9 | 99.3% | |
| Winogrande (5-shot) | 78.1 | 78.0 | 99.9% | |
| TruthfulQA (0-shot, mc2) | 54.5 | 52.8 | 96.9% | |
| Average | 74.3 | 73.5 | 98.9% | |
| OpenLLM v2 | MMLU-Pro (5-shot) | 30.8 | 28.8 | 93.6% |
| IFEval (0-shot) | 77.9 | 76.3 | 98.0% | |
| BBH (3-shot) | 30.1 | 28.9 | 96.1% | |
| Math-lvl-5 (4-shot) | 15.7 | 14.8 | 94.4% | |
| GPQA (0-shot) | 3.7 | 4.0 | 109.8% | |
| MuSR (0-shot) | 7.6 | 6.3 | 83.2% | |
| Average | 27.6 | 26.5 | 96.1% | |
| Coding | HumanEval pass@1 | 67.3 | 67.1 | 99.7% |
| HumanEval+ pass@1 | 60.7 | 59.1 | 97.4% | |
| Multilingual | Portuguese MMLU (5-shot) | 59.96 | 58.69 | 97.9% |
| Spanish MMLU (5-shot) | 60.25 | 58.39 | 96.9% | |
| Italian MMLU (5-shot) | 59.23 | 57.82 | 97.6% | |
| German MMLU (5-shot) | 58.63 | 56.22 | 95.9% | |
| French MMLU (5-shot) | 59.65 | 57.58 | 96.5% | |
| Hindi MMLU (5-shot) | 50.10 | 47.14 | 94.1% | |
| Thai MMLU (5-shot) | 49.12 | 46.72 | 95.1% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4064,max_gen_toks=1024,tensor_parallel_size=1 \
--tasks mmlu_cot_0shot_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3940,max_gen_toks=100,tensor_parallel_size=1 \
--tasks arc_challenge_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,max_gen_toks=1024,tensor_parallel_size=1 \
--tasks gsm8k_cot_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 8 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks hellaswag \
--num_fewshot 10 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks winogrande \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_pt_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_es_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_it_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_de_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_fr_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_hi_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_th_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size autopython3 codegen/generate.py \
--model neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16 \
--bs 16 \
--temperature 0.2 \
--n_samples 50 \
--root "." \
--dataset humanevalpython3 evalplus/sanitize.py \
humaneval/neuralmagic--Meta-Llama-3.1-8B-Instruct-quantized.w4a16_vllm_temp_0.2evalplus.evaluate \
--dataset humaneval \
--samples humaneval/neuralmagic--Meta-Llama-3.1-8B-Instruct-quantized.w4a16_vllm_temp_0.2-sanitized