Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/gemma-2-2b-it-quantized.w8a16"
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-2b-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 targets="Linear",
22 scheme="W8A16",
23 ignore=["lm_head"],
24 dampening_frac=0.01,
25)
26
27model = SparseAutoModelForCausalLM.from_pretrained(
28 model_id,
29 device_map="auto",
30 trust_remote_code=True,
31)
32
33oneshot(
34 model=model,
35 dataset=ds,
36 recipe=recipe,
37 max_seq_length=max_seq_len,
38 num_calibration_samples=num_samples,
39)
40model.save_pretrained("gemma-2-2b-it-quantized.w8a16")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/gemma-2-2b-it-quantized.w8a16",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | gemma-2-2b-it | gemma-2-2b-it-quantized.w8a16 (this model) | Recovery |
| MMLU (5-shot) | 56.94 | 56.81 | 99.8% |
| ARC Challenge (25-shot) | 58.87 | 58.70 | 99.7% |
| GSM-8K (5-shot, strict-match) | 44.81 | 44.88 | 100.2% |
| Hellaswag (10-shot) | 71.41 | 71.34 | 99.9% |
| Winogrande (5-shot) | 68.82 | 69.46 | 100.9% |
| TruthfulQA (0-shot) | 53.22 | 53.13 | 99.8% |
| Average | 59.01 | 59.05 | 100.1% |