Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Llama-3.2-3B-Instruct-FP8-dynamic"
5
6sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
7
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9
10messages = [
11 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
12 {"role": "user", "content": "Who are you?"},
13]
14
15prompts = tokenizer.apply_chat_template(messages, tokenize=False)
16
17llm = LLM(model=model_id)
18
19outputs = llm.generate(prompts, sampling_params)
20
21generated_text = outputs[0].outputs[0].text
22print(generated_text)1import torch
2
3from transformers import AutoTokenizer
4
5from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
6from llmcompressor.transformers.compression.helpers import ( # noqa
7 calculate_offload_device_map,
8 custom_offload_device_map,
9)
10
11recipe = """
12quant_stage:
13 quant_modifiers:
14 QuantizationModifier:
15 ignore: ["lm_head"]
16 config_groups:
17 group_0:
18 weights:
19 num_bits: 8
20 type: float
21 strategy: channel
22 dynamic: false
23 symmetric: true
24 input_activations:
25 num_bits: 8
26 type: float
27 strategy: token
28 dynamic: true
29 symmetric: true
30 targets: ["Linear"]
31"""
32
33model_stub = "meta-llama/Llama-3.2-3B-Instruct"
34model_name = model_stub.split("/")[-1]
35
36device_map = calculate_offload_device_map(
37 model_stub, reserve_for_hessians=False, num_gpus=1, torch_dtype="auto"
38)
39
40model = SparseAutoModelForCausalLM.from_pretrained(
41 model_stub, torch_dtype="auto", device_map=device_map
42)
43
44output_dir = f"./{model_name}-FP8-dynamic"
45
46oneshot(
47 model=model,
48 recipe=recipe,
49 output_dir=output_dir,
50 save_compressed=True,
51 tokenizer=AutoTokenizer.from_pretrained(model_stub),
52)| Benchmark | Llama-3.2-3B-Instruct | Llama-3.2-3B-Instruct-FP8-dynamic (this model) | Recovery |
| MMLU (5-shot) | 62.98 | 62.95 | 100.0% |
| MMLU-cot (0-shot) | 65.40 | 65.23 | 99.7% |
| ARC Challenge (0-shot) | 77.13 | 76.71 | 99.4% |
| GSM-8K-cot (8-shot, strict-match) | 77.94 | 76.72 | 98.4% |
| Winogrande (5-shot) | 71.11 | 71.11 | 100.0% |
| Hellaswag (10-shot) | 73.62 | 73.54 | 99.9% |
| TruthfulQA (0-shot, mc2) | 51.47 | 51.06 | 99.2% |
| Average | 68.52 | 68.19 | 99.5% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.2-3B-Instruct-FP8-dynamic",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/Llama-3.2-3B-Instruct-FP8-dynamic",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/Llama-3.2-3B-Instruct-FP8-dynamic",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/Llama-3.2-3B-Instruct-FP8-dynamic",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/Llama-3.2-3B-Instruct-FP8-dynamic",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-FP8-dynamic",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-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size auto