Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w8a16"
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 datasets import Dataset
3from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5import random
6
7model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
8
9num_samples = 256
10max_seq_len = 8192
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14max_token_id = len(tokenizer.get_vocab()) - 1
15input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
16attention_mask = num_samples * [max_seq_len * [1]]
17ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
18
19recipe = GPTQModifier(
20 targets="Linear",
21 scheme="W8A16",
22 ignore=["lm_head"],
23 dampening_frac=0.01,
24)
25
26model = SparseAutoModelForCausalLM.from_pretrained(
27 model_id,
28 device_map="auto",
29 trust_remote_code=True,
30)
31
32oneshot(
33 model=model,
34 dataset=ds,
35 recipe=recipe,
36 max_seq_length=max_seq_len,
37 num_calibration_samples=num_samples,
38)
39model.save_pretrained("Meta-Llama-3.1-8B-Instruct-quantized.w8a16")| Category | Benchmark | Meta-Llama-3.1-8B-Instruct | Meta-Llama-3.1-8B-Instruct-quantized.w8a16 (this model) | Recovery |
| OpenLLM v1 | ||||
| Hellaswag (10-shot) | 80.47 | 80.48 | 100.0% | |
| Winogrande (5-shot) | 78.06 | 77.51 | 99.3% | |
| TruthfulQA (0-shot, mc2) | 54.48 | 54.41 | 99.9% | |
| Average | 74.05 | 74.12 | 100.1% | |
| Multilingual | Portuguese MMLU (5-shot) | 59.96 | 59.79 | 99.8% |
| Spanish MMLU (5-shot) | 60.25 | 59.92 | 99.4% | |
| Italian MMLU (5-shot) | 59.23 | 59.25 | 100.0% | |
| German MMLU (5-shot) | 58.63 | 58.31 | 99.5% | |
| French MMLU (5-shot) | 59.65 | 59.57 | 99.9% | |
| Hindi MMLU (5-shot) | 50.10 | 49.97 | 99.7% | |
| Thai MMLU (5-shot) | 49.12 | 49.09 | 99.9% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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.w8a16",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 auto