Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Mistral-Nemo-Instruct-2407-FP8"
5
6sampling_params = SamplingParams(temperature=0.3, 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, max_model_len=4096)
18
19outputs = llm.generate(prompts, sampling_params)
20
21generated_text = outputs[0].outputs[0].text
22print(generated_text)transformers must be built from source.1from datasets import load_dataset
2from transformers import AutoTokenizer
3
4from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
5
6pretrained_model_dir = "mistralai/Mistral-Nemo-Instruct-2407"
7quantized_model_dir = "Mistral-Nemo-Instruct-2407-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)vllm must be built from source.lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Mistral-Nemo-Instruct-2407-FP8",dtype=auto,gpu_memory_utilization=0.4,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | Mistral-Nemo-Instruct-2407 | Mistral-Nemo-Instruct-2407-FP8(this model) | Recovery |
| MMLU (5-shot) | 68.35 | 68.50 | 100.2% |
| ARC Challenge (25-shot) | 65.53 | 64.68 | 98.70% |
| GSM-8K (5-shot, strict-match) | 74.45 | 73.01 | 98.06% |
| Hellaswag (10-shot) | 84.32 | 84.18 | 99.83% |
| Winogrande (5-shot) | 82.16 | 82.32 | 100.1% |
| TruthfulQA (0-shot) | 54.85 | 54.96 | 100.2% |
| Average | 71.61 | 71.28 | 99.53% |