Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Qwen2-1.5B-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-1.5B-Instruct"
7quantized_model_dir = "Qwen2-1.5B-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-1.5B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | Qwen2-1.5B-Instruct | Qwen2-1.5B-Instruct-FP8(this model) | Recovery |
| MMLU (5-shot) | 55.87 | 55.60 | 99.51% |
| ARC Challenge (25-shot) | 43.09 | 41.81 | 97.02% |
| GSM-8K (5-shot, strict-match) | 57.70 | 56.48 | 97.88% |
| Hellaswag (10-shot) | 67.48 | 67.18 | 99.55% |
| Winogrande (5-shot) | 63.61 | 63.38 | 99.63% |
| TruthfulQA (0-shot) | 43.34 | 43.09 | 99.42% |
| Average | 55.18 | 54.59 | 98.93% |