Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Qwen2-7B-Instruct-FP8"
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)1from datasets import load_dataset
2from transformers import AutoTokenizer
3
4from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
5
6pretrained_model_dir = "Qwen/Qwen2-7B-Instruct"
7quantized_model_dir = "Qwen2-7B-Instruct-FP8"
8
9tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
10tokenizer.pad_token = tokenizer.eos_token
11
12ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
13examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
14examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
15
16quantize_config = BaseQuantizeConfig(
17 quant_method="fp8",
18 activation_scheme="static"
19 ignore_patterns=["re:.*lm_head"],
20)
21
22model = AutoFP8ForCausalLM.from_pretrained(
23 pretrained_model_dir, quantize_config=quantize_config
24)
25
26model.quantize(examples)
27model.save_quantized(quantized_model_dir)lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Qwen2-7B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | Qwen2-7B-Instruct | Qwen2-7B-Instruct-FP8(this model) | Recovery |
| MMLU (5-shot) | 70.82 | 70.27 | 99.22% |
| ARC Challenge (25-shot) | 62.37 | 62.03 | 99.45% |
| GSM-8K (5-shot, strict-match) | 68.84 | 69.83 | 101.4% |
| Hellaswag (10-shot) | 81.77 | 81.46 | 99.62% |
| Winogrande (5-shot) | 76.16 | 76.72 | 100.7% |
| TruthfulQA (0-shot) | 57.36 | 56.34 | 98.22% |
| Average | 69.55 | 69.44 | 99.84% |