Int8 quant for optimized performance on Ampere.
1uv venv --python 3.12
2
3uv pip install sglang[all] --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python
4
5uv run python -m sglang.launch_server --model-path nytopop/Qwen3-0.6B.w8a8 --quantization w8a8_int8 --reasoning-parser qwen3
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from datasets import load_dataset
3from llmcompressor import oneshot
4from llmcompressor.modifiers.quantization import GPTQModifier
5from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
6
7model_id = "Qwen/Qwen3-0.6B"
8model_out = "Qwen3-0.6B.w8a8"
9
10num_samples = 256
11max_seq_len = 4096
12
13tokenizer = AutoTokenizer.from_pretrained(model_id)
14
15def preprocess_fn(example):
16 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
17
18ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
19ds = ds.shuffle().select(range(num_samples))
20ds = ds.map(preprocess_fn)
21
22recipe = [
23 SmoothQuantModifier(smoothing_strength=0.7),
24 GPTQModifier(sequential=True,targets="Linear",scheme="W8A8",ignore=["lm_head"],dampening_frac=0.01),
25]
26
27model = AutoModelForCausalLM.from_pretrained(
28 model_id,
29 device_map="auto",
30 torch_dtype="bfloat16",
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 output_dir=model_out,
40)