Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w8a8"
5number_gpus = 8
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 load_dataset
3from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5from llmcompressor.transformers.compression.helpers import custom_offload_device_map
6
7model_id = "meta-llama/Meta-Llama-3.1-405B-Instruct"
8
9num_samples = 512
10max_seq_len = 4096
11num_gpus = 8
12max_memory_per_gpu = "20GB"
13
14tokenizer = AutoTokenizer.from_pretrained(model_id)
15
16def preprocess_fn(example):
17 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
18
19ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
20ds = ds.shuffle().select(range(num_samples))
21ds = ds.map(preprocess_fn)
22
23recipe = GPTQModifier(
24 sequential=True,
25 targets="Linear",
26 scheme="W8A8",
27 ignore=["lm_head"],
28 dampening_frac=0.01,
29 observer="mse"
30)
31
32device_map = custom_offload_device_map(
33 model_id,
34 max_memory_per_gpu=max_memory_per_gpu,
35 num_gpus=num_gpus,
36 torch_dtype="auto",
37)
38
39model = SparseAutoModelForCausalLM.from_pretrained(
40 model_id,
41 device_map="auto",
42)
43
44oneshot(
45 model=model,
46 dataset=ds,
47 recipe=recipe,
48 max_seq_length=max_seq_len,
49 num_calibration_samples=num_samples,
50)
51
52model.save_pretrained("Meta-Llama-3.1-405B-Instruct-quantized.w8a8")| Benchmark | Meta-Llama-3.1-405B-Instruct | Meta-Llama-3.1-405B-Instruct-quantized.w8a8 (this model) | Recovery |
| Arena Hard | 67.4 (67.3 / 67.5) | 64.6 (64.3 / 64.8) | 95.8% |
| OpenLLM v1 | |||
| MMLU (5-shot) | 87.4 | 87.1 | 99.6% |
| ARC Challenge (0-shot) | 95.0 | 94.4 | 99.4% |
| GSM-8K (CoT, 8-shot, strict-match) | 96.4 | 95.5 | 99.0% |
| Hellaswag (10-shot) | 88.3 | 88.2 | 99.8% |
| Winogrande (5-shot) | 87.2 | 86.1 | 98.7% |
| TruthfulQA (0-shot) | 64.6 | 64.4 | 99.6% |
| Average | 86.8 | 86.2 | 99.3% |
| OpenLLM v2 | |||
| MMLU-Pro (5-shot) | 59.7 | 58.4 | 97.8% |
| IFEval (0-shot) | 87.7 | 87.0 | 99.2% |
| BBH (3-shot) | 67.0 | 66.7 | 99.6% |
| Math-lvl-5 (4-shot) | 39.0 | 35.8 | 91.9% |
| GPQA (0-shot) | 19.5 | 20.4 | 104.5% |
| MuSR (0-shot) | 19.5 | 19.2 | 98.8% |
| Average | 48.7 | 47.9 | 98.4% |
| Coding | |||
| HumanEval pass@1 | 86.8 | 86.9 | 100.1% |
| HumanEval+ pass@1 | 80.1 | 80.4 | 100.4% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=8 \
--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-405B-Instruct-quantized.w8a8",dtype=auto,max_model_len=4064,max_gen_toks=1024,tensor_parallel_size=8 \
--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-405B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3940,max_gen_toks=100,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.w8a8",dtype=auto,max_model_len=4096,max_gen_toks=1024,tensor_parallel_size=8 \
--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-405B-Instruct-quantized.w8a8",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.w8a8",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.w8a8",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.w8a8",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.w8a8 \
--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.w8a8_vllm_temp_0.2evalplus.evaluate \
--dataset humaneval \
--samples humaneval/neuralmagic--Meta-Llama-3.1-405B-Instruct-quantized.w8a8_vllm_temp_0.2-sanitized