Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w8a16"
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="W8A16",
27 ignore=["lm_head"],
28 dampening_frac=0.01,
29)
30
31device_map = custom_offload_device_map(
32 model_id,
33 max_memory_per_gpu=max_memory_per_gpu,
34 num_gpus=num_gpus,
35 torch_dtype="auto",
36)
37
38model = SparseAutoModelForCausalLM.from_pretrained(
39 model_id,
40 device_map="auto",
41)
42
43oneshot(
44 model=model,
45 dataset=ds,
46 recipe=recipe,
47 max_seq_length=max_seq_len,
48 num_calibration_samples=num_samples,
49)
50
51model.save_pretrained("Meta-Llama-3.1-405B-Instruct-quantized.w8a16")| Benchmark | Meta-Llama-3.1-405B-Instruct | Meta-Llama-3.1-405B-Instruct-quantized.w8a16 (this model) | Recovery |
| MMLU (5-shot) | 87.38 | 87.59 | 100.2% |
| MMLU (CoT, 0-shot) | 88.26 | 88.19 | 99.9% |
| ARC Challenge (0-shot) | 94.97 | 94.80 | 99.8% |
| GSM-8K (CoT, 8-shot, strict-match) | 96.44 | 96.13 | 100.8% |
| Hellaswag (10-shot) | 88.33 | 88.52 | 100.2% |
| Winogrande (5-shot) | 87.21 | 87.92 | 100.8% |
| TruthfulQA (0-shot, mc2) | 64.64 | 65.41 | 101.2% |
| Average | 86.75 | 86.94 | 100.2% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3.1-405B-Instruct-quantized.w8a16",dtype=auto,max_model_len=3850,max_gen_toks=10,enable_chunked_prefill=True,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.w8a16",dtype=auto,max_model_len=4064,max_gen_toks=1024,enable_chunked_prefill=True,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.w8a16",dtype=auto,max_model_len=3940,max_gen_toks=100,enable_chunked_prefill=True,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.w8a16",dtype=auto,max_model_len=4096,max_gen_toks=1024,enable_chunked_prefill=True,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.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,enable_chunked_prefill=True,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.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,enable_chunked_prefill=True,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.w8a16",dtype=auto,add_bos_token=True,max_model_len=4096,enable_chunked_prefill=True,tensor_parallel_size=8 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size auto