Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/gemma-2-9b-it-quantized.w8a8"
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": "user", "content": "Who are you? Please respond in pirate speak!"},
12]
13
14prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
15
16llm = LLM(model=model_id)
17
18outputs = llm.generate(prompts, sampling_params)
19
20generated_text = outputs[0].outputs[0].text
21print(generated_text)1from transformers import AutoTokenizer
2from datasets import load_dataset
3from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5
6model_id = "google/gemma-2-9b-it"
7
8num_samples = 256
9max_seq_len = 8192
10
11tokenizer = AutoTokenizer.from_pretrained(model_id)
12
13def preprocess_fn(example):
14 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
15
16ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
17ds = ds.shuffle().select(range(num_samples))
18ds = ds.map(preprocess_fn)
19
20recipe = GPTQModifier(
21 sequential=True,
22 targets="Linear",
23 scheme="W8A8",
24 ignore=["lm_head"],
25 dampening_frac=0.01,
26 observer="mse"
27)
28
29model = SparseAutoModelForCausalLM.from_pretrained(
30 model_id,
31 device_map="auto",
32)
33
34oneshot(
35 model=model,
36 dataset=ds,
37 recipe=recipe,
38 max_seq_length=max_seq_len,
39 num_calibration_samples=num_samples,
40)
41model.save_pretrained("gemma-2-9b-it-quantized.w8a8")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/gemma-2-9b-it-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | gemma-2-9b-it | gemma-2-9b-it-quantized.w8a8 (this model) | Recovery |
| MMLU (5-shot) | 72.29 | 71.90 | 99.5% |
| ARC Challenge (25-shot) | 71.08 | 71.42 | 100.5% |
| GSM-8K (5-shot, strict-match) | 79.30 | 78.85 | 99.4% |
| Hellaswag (10-shot) | 81.93 | 81.60 | 99.6 |
| Winogrande (5-shot) | 77.98 | 78.37 | 100.5% |
| TruthfulQA (0-shot) | 60.21 | 60.12 | 99.9% |
| Average | 73.80 | 73.71 | 99.9% |