Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Llama-3.2-3B-Instruct-quantized.w8a8"
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 load_dataset
3from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier, SmoothQuantModifier
5
6model_id = "meta-llama/Llama-3.2-3B-Instruct"
7
8num_samples = 512
9max_seq_len = 8192
10
11tokenizer = AutoTokenizer.from_pretrained(model_id)
12
13def preprocess_fn(example):
14 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
15
16ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
17ds = ds.shuffle().select(range(num_samples))
18ds = ds.map(preprocess_fn)
19
20recipe = [
21 SmoothQuantModifier(
22 smoothing_strength=0.7,
23 mappings=[
24 [["re:.*q_proj", "re:.*k_proj", "re:.*v_proj"], "re:.*input_layernorm"],
25 [["re:.*gate_proj", "re:.*up_proj"], "re:.*post_attention_layernorm"],
26 [["re:.*down_proj"], "re:.*up_proj"],
27 ],
28 ),
29 GPTQModifier(
30 sequential=True,
31 targets="Linear",
32 scheme="W8A8",
33 ignore=["lm_head"],
34 dampening_frac=0.01,
35 )
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("Llama-3.2-3B-Instruct-quantized.w8a8")| Benchmark | Llama-3.2-3B-Instruct | Llama-3.2-3B-Instruct-quantized.w8a8 (this model) | Recovery |
| MMLU (5-shot) | 62.98 | 62.75 | 99.6% |
| MMLU (CoT, 0-shot) | 65.40 | 65.05 | 99.5% |
| ARC Challenge (0-shot) | 77.13 | 76.45 | 99.1% |
| GSM-8K (CoT, 8-shot, strict-match) | 77.94 | 77.56 | 99.5% |
| Hellaswag (10-shot) | 73.62 | 73.63 | 100.0% |
| Winogrande (5-shot) | 71.11 | 71.90 | 101.1% |
| TruthfulQA (0-shot, mc2) | 51.47 | 51.38 | 98.4% |
| Average | 68.52 | 68.39 | 99.81% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.2-3B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,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/Llama-3.2-3B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,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/Llama-3.2-3B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,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/Llama-3.2-3B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,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/Llama-3.2-3B-Instruct-quantized.w8a8",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/Llama-3.2-3B-Instruct-quantized.w8a8",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/Llama-3.2-3B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size auto