Views
No views yet
1python -m sglang.launch_server --model-path JamAndTeaStudios/DeepSeek-R1-Distill-Qwen-32B-FP8-Dynamic \
2--port 30000 --host 0.0.0.01from transformers import AutoModelForCausalLM, AutoTokenizer
2
3from llmcompressor.modifiers.quantization import QuantizationModifier
4from llmcompressor.transformers import oneshot
5
6MODEL_ID = "google/gemma-2-27b-it"
7
8# 1) Load model.
9model = AutoModelForCausalLM.from_pretrained(
10 MODEL_ID, device_map="auto", torch_dtype="auto"
11)
12tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
13
14# 2) Configure the quantization algorithm and scheme.
15# In this case, we:
16# * quantize the weights to fp8 with per channel via ptq
17# * quantize the activations to fp8 with dynamic per token
18recipe = QuantizationModifier(
19 targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"]
20)
21
22# 3) Apply quantization and save in compressed-tensors format.
23OUTPUT_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
24oneshot(
25 model=model,
26 recipe=recipe,
27 tokenizer=tokenizer,
28 output_dir=OUTPUT_DIR,
29)
30
31# Confirm generations of the quantized model look sane.
32print("========== SAMPLE GENERATION ==============")
33input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to("cuda")
34output = model.generate(input_ids, max_new_tokens=20)
35print(tokenizer.decode(output[0]))
36print("==========================================")