Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/Mistral-7B-Instruct-v0.3-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
3import numpy as np
4import torch
5
6from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
7
8MODEL_DIR = "mistralai/Mistral-7B-Instruct-v0.3"
9final_model_dir = MODEL_DIR.split("/")[-1]
10
11CONTEXT_LENGTH = 4096
12NUM_SAMPLES = 512
13NUM_REPEATS = 10
14
15pretrained_model_dir = MODEL_DIR
16tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=CONTEXT_LENGTH)
17tokenizer.pad_token = tokenizer.eos_token
18
19tokenizer_num_tokens = len(list(tokenizer.get_vocab().values()))
20total_token_samples = NUM_REPEATS * tokenizer_num_tokens
21num_random_samp = -(-total_token_samples // CONTEXT_LENGTH)
22
23input_ids = np.tile(np.arange(tokenizer_num_tokens), NUM_REPEATS + 1)[:num_random_samp * CONTEXT_LENGTH]
24np.random.shuffle(input_ids)
25input_ids = input_ids.reshape(num_random_samp, CONTEXT_LENGTH)
26input_ids = torch.tensor(input_ids, dtype=torch.int64).to("cuda")
27
28quantize_config = BaseQuantizeConfig(
29 quant_method="fp8",
30 activation_scheme="static",
31)
32
33examples = input_ids
34
35model = AutoFP8ForCausalLM.from_pretrained(pretrained_model_dir, quantize_config=quantize_config)
36
37model.quantize(examples)
38
39quantized_model_dir = f"{final_model_dir}-FP8"
40model.save_quantized(quantized_model_dir)lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Mistral-7B-Instruct-v0.3-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | Mistral-7B-Instruct-v0.3 | Mistral-7B-Instruct-v0.3-FP8(this model) | Recovery |
| MMLU (5-shot) | 61.84 | 61.63 | 99.66% |
| ARC Challenge (25-shot) | 63.57 | 63.73 | 100.2% |
| GSM-8K (5-shot, strict-match) | 49.05 | 47.54 | 96.92% |
| Hellaswag (10-shot) | 84.76 | 84.52 | 99.71% |
| Winogrande (5-shot) | 79.40 | 78.30 | 98.61% |
| TruthfulQA (0-shot) | 59.37 | 59.40 | 100.0% |
| Average | 66.33 | 65.85 | 99.28% |