Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/SmolLM-360M-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-360M-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-360M-Instruct-quantized.w8a8")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/SmolLM-360M-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-360M-Instruct-quantized | SmolLM-360M-Instruct-quantized.w8a8 (this model) | Recovery |
| MMLU (5-shot) | 25.69 | 25.77 | 100.3% |
| ARC Challenge (25-shot) | 37.46 | 38.05 | 101.6% |
| GSM-8K (5-shot, strict-match) | 2.05 | 1.44 | 70.4% |
| Hellaswag (10-shot) | 51.72 | 52.02 | 100.6% |
| Winogrande (5-shot) | 55.25 | 55.41 | 100.3% |
| TruthfulQA (0-shot) | 38.76 | 40.22 | 103.8% |
| Average | 35.15 | 35.49 | 101.6% |