Views
No views yet
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "neuralmagic/starcoder2-15b-quantized.w8a16"
5number_gpus = 1
6
7sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=256)
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11prompts = ["def print_hello_world():"]
12
13llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
14
15outputs = llm.generate(prompts, sampling_params)
16
17generated_text = outputs[0].outputs[0].text
18print(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 = "bigcode/starcoder2-15b"
8
9num_samples = 256
10max_seq_len = 8192
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14max_token_id = len(tokenizer.get_vocab()) - 1
15input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
16attention_mask = num_samples * [max_seq_len * [1]]
17ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
18
19recipe = GPTQModifier(
20 targets="Linear",
21 scheme="W8A16",
22 ignore=["lm_head"],
23 dampening_frac=0.01,
24)
25
26model = SparseAutoModelForCausalLM.from_pretrained(
27 model_id,
28 device_map="auto",
29 trust_remote_code=True,
30)
31
32oneshot(
33 model=model,
34 dataset=ds,
35 recipe=recipe,
36 max_seq_length=max_seq_len,
37 num_calibration_samples=num_samples,
38)
39model.save_pretrained("starcoder2-15b-quantized.w8a16")python codegen/generate.py \
--model neuralmagic/starcoder2-15b-quantized.w8a16 \
--bs 8 \
--temperature 0.2 \
--n_samples 50 \
--dataset humaneval \
-- root "."
python3 evalplus/sanitize.py humaneval/neuralmagic--starcoder2-15b-quantized.w8a16_vllm_temp_0.2
evalplus.evaluate --dataset humaneval --samples humaneval/neuralmagic--starcoder2-15b-quantized.w8a16_vllm_temp_0.2-sanitized| Benchmark | starcoder2-15b | starcoder2-15b-quantized.w8a16 (this model) | Recovery |
| HumanEval pass@1 | 44.8 | 44.3 | 98.9% |
| HumanEval pass@10 | 62.7 | 62.6 | 99.8% |
| HumanEval+ pass@1 | 38.6 | 37.6 | 97.4% |
| HumanEval+ pass@10 | 54.9 | 54.5 | 99.3% |