Views
No views yet
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-4B-abliterated.w8a8 --quantization w8a8_int8 --reasoning-parser qwen31from 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
6from llmcompressor.transformers.compression.helpers import calculate_offload_device_map
7
8model_id = "mlabonne/Qwen3-4B-abliterated"
9model_out = model_id.split("/")[1] + ".w8a8"
10
11num_samples = 256
12max_seq_len = 4096
13
14tokenizer = AutoTokenizer.from_pretrained(model_id)
15
16def preprocess_fn(example):
17 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
18
19ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
20ds = ds.shuffle().select(range(num_samples))
21ds = ds.map(preprocess_fn)
22
23device_map = calculate_offload_device_map(
24 model_id, reserve_for_hessians=True, num_gpus=1, torch_dtype="bfloat16"
25)
26
27for k, v in device_map.items():
28 if v == 'disk':
29 device_map[k] = 'cpu'
30
31model = AutoModelForCausalLM.from_pretrained(
32 model_id,
33 device_map=device_map,
34 torch_dtype="bfloat16",
35)
36
37recipe = [
38 SmoothQuantModifier(
39 smoothing_strength=0.7,
40 ),
41 GPTQModifier(
42 sequential=True,
43 targets="Linear",
44 scheme="W8A8",
45 ignore=["lm_head", "re:.*mlp.gate$"],
46 dampening_frac=0.01,
47 ),
48]
49
50oneshot(
51 model=model,
52 dataset=ds,
53 recipe=recipe,
54 max_seq_length=max_seq_len,
55 num_calibration_samples=num_samples,
56 output_dir=model_out,
57)