Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16"
5number_gpus = 8
6max_model_len = 4096
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-405B-Instruct"
8
9num_samples = 512
10max_seq_len = 8192
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14preprocess_fn = lambda example: {"text": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n{text}".format_map(example)}
15
16dataset_name = "neuralmagic/LLM_compression_calibration"
17dataset = load_dataset(dataset_name, split="train")
18ds = dataset.shuffle().select(range(num_samples))
19ds = ds.map(preprocess_fn)
20
21recipe = GPTQModifier(
22 targets="Linear",
23 scheme="W4A16",
24 ignore=["lm_head"],
25 dampening_frac=0.01,
26)
27
28model = SparseAutoModelForCausalLM.from_pretrained(
29 model_id,
30 device_map="auto",
31 trust_remote_code=True,
32)
33
34oneshot(
35 model=model,
36 dataset=ds,
37 recipe=recipe,
38 max_seq_length=max_seq_len,
39 num_calibration_samples=num_samples,
40)
41model.save_pretrained("Meta-Llama-3.1-405B-Instruct-quantized.w4a16")| Benchmark | Meta-Llama-3.1-405B-Instruct | Meta-Llama-3.1-405B-Instruct-quantized.w4a16 (this model) | Recovery |
| Arena Hard | 67.4 (67.3 / 67.5) | 66.5 (66.5 / 66.4) | 98.7% |
| OpenLLM v1 | |||
| MMLU (5-shot) | 87.4 | 87.2 | 99.8% |
| ARC Challenge (0-shot) | 95.0 | 95.3 | 100.4% |
| GSM-8K (CoT, 8-shot, strict-match) | 96.4 | 96.3 | 99.8% |
| Hellaswag (10-shot) | 88.3 | 88.3 | 99.9% |
| Winogrande (5-shot) | 87.2 | 87.4 | 100.2% |
| TruthfulQA (0-shot) | 64.6 | 65.3 | 101.0% |
| Average | 86.8 | 86.8 | 100.0% |
| OpenLLM v2 | |||
| MMLU-Pro (5-shot) | 59.7 | 59.4 | 99.3% |
| IFEval (0-shot) | 87.7 | 88.0 | 100.4% |
| BBH (3-shot) | 67.0 | 67.5 | 100.7% |
| Math-|v|-5 (4-shot) | 39.0 | 37.6 | 96.5% |
| GPQA (0-shot) | 19.5 | 17.5 | 89.8% |
| MuSR (0-shot) | 19.5 | 19.4 | 99.5% |
| Average | 48.7 | 48.2 | 99.0% |
| Coding | |||
| HumanEval pass@1 | 86.8 | 85.1 | 98.0% |
| HumanEval+ pass@1 | 80.1 | 78.9 | 98.5% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,max_gen_toks=10,tensor_parallel_size=8 \
--tasks mmlu_llama_3.1_instruct \
--apply_chat_template \
--fewshot_as_multiturn \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=8 \
--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-405B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=8 \
--tasks gsm8k_cot_llama_3.1_instruct \
--apply_chat_template \
--fewshot_as_multiturn \
--num_fewshot 8 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
--tasks hellaswag \
--num_fewshot 10 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
--tasks winogrande \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=8 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16",dtype=auto,max_model_len=4096,tensor_parallel_size=8,enable_chunked_prefill=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size autopython3 codegen/generate.py \
--model neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w4a16 \
--bs 16 \
--temperature 0.2 \
--n_samples 50 \
--root "." \
--dataset humaneval \
--tp 8python3 evalplus/sanitize.py \
humaneval/neuralmagic--Meta-Llama-3.1-405B-Instruct-quantized.w4a16_vllm_temp_0.2evalplus.evaluate \
--dataset humaneval \
--samples humaneval/neuralmagic--Meta-Llama-3.1-405B-Instruct-quantized.w4a16_vllm_temp_0.2-sanitized