Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Qwen2-57B-A14B-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)if re.search(regex_pattern, name): replaced with if re.search(regex_pattern, name) and re.search(regex_pattern + "_proj", name) is None:. This way, the gate_proj layers will not be left unquantized.
Although AutoFP8 was used for this particular model, Neural Magic is transitioning to using llm-compressor which supports several quantization schemes and models not supported by AutoFP8.1from datasets import load_dataset
2from transformers import AutoTokenizer
3
4from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
5
6pretrained_model_dir = "Qwen/Qwen2-57B-A14B-Instruct"
7quantized_model_dir = "Qwen2-57B-A14B-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", "re:.*gate"],
20)
21
22model = AutoFP8ForCausalLM.from_pretrained(
23 pretrained_model_dir, quantize_config=quantize_config
24)
25model.quantize(examples)
26model.save_quantized(quantized_model_dir)lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Qwen2-57B-A14B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | Qwen2-57B-A14B-Instruct | Qwen2-57B-A14B-Instruct-FP8(this model) | Recovery |
| MMLU (5-shot) | 75.76 | 75.49 | 99.64% |
| ARC Challenge (25-shot) | 66.89 | 65.96 | 98.60% |
| GSM-8K (5-shot, strict-match) | 80.59 | 77.10 | 95.66% |
| Hellaswag (10-shot) | 85.96 | 85.71 | 99.70% |
| Winogrande (5-shot) | 78.45 | 78.14 | 99.60% |
| TruthfulQA (0-shot) | 62.11 | 61.80 | 99.50% |
| Average | 74.96 | 74.03 | 98.76% |