Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/SmolLM-1.7B-Instruct-quantized.w8a8"
5
6sampling_params = SamplingParams(temperature=0.6, top_p=0.92, max_tokens=100)
7
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9
10messages = [
11 {"role": "user", "content": "List the steps to bake a chocolate cake from scratch."},
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 Dataset
3from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5import random
6
7model_id = "HuggingFaceTB/SmolLM-1.7B-Instruct"
8
9num_samples = 1024
10max_seq_len = 2048
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14def preprocess_fn(example):
15 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
16
17ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
18ds = ds.shuffle().select(range(num_samples))
19ds = ds.map(preprocess_fn)
20
21recipe = GPTQModifier(
22 targets="Linear",
23 scheme="W8A8",
24 ignore=["lm_head"],
25 dampening_frac=0.01,
26)
27
28model = SparseAutoModelForCausalLM.from_pretrained(
29 model_id,
30 device_map="auto",
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("SmolLM-1.7B-Instruct-quantized.w8a8")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/SmolLM-1.7B-Instruct-quantized.w8a8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto| Benchmark | SmolLM-1.7B-Instruct-quantized | SmolLM-1.7B-Instruct-quantized.w8a8 (this model) | Recovery |
| MMLU (5-shot) | 28.10 | 27.54 | 98.0% |
| ARC Challenge (25-shot) | 49.06 | 48.98 | 99.8% |
| GSM-8K (5-shot, strict-match) | 4.93 | 3.87 | 78.5% |
| Hellaswag (10-shot) | 66.96 | 66.25 | 98.9% |
| Winogrande (5-shot) | 61.01 | 60.54 | 99.2% |
| TruthfulQA (0-shot) | 40.48 | 40.21 | 99.3% |
| Average | 41.76 | 41.23 | 98.7% |