Views
No views yet
1# pip install amd-quark
2
3from transformers import AutoTokenizer, AutoModelForCausalLM
4from quark.torch import ModelQuantizer, export_safetensors
5from quark.torch.quantization import FP8E4M3PerTensorSpec
6from quark.torch.quantization.config.config import Config, QuantizationConfig
7
8ckpt_path = "Qwen/Qwen3-30B-A3B-Thinking-2507"
9exclude_layers = ["lm_head", "*mlp.gate"]
10output_dir = ckpt_path.rstrip("/").split("/")[-1] + "-FP8"
11
12# Load the original floating-point model
13model = AutoModelForCausalLM.from_pretrained(ckpt_path, device_map="auto", torch_dtype="auto", trust_remote_code=True)
14model.eval()
15tokenizer = AutoTokenizer.from_pretrained(ckpt_path)
16
17# Set the quantization configuration
18FP8_PER_TENSOR_SPEC = FP8E4M3PerTensorSpec(is_dynamic=False).to_quantization_spec()
19W_FP8_A_FP8_PER_TENSOR_CONFIG = QuantizationConfig(input_tensors=FP8_PER_TENSOR_SPEC, weight=FP8_PER_TENSOR_SPEC)
20quant_config = Config(global_quant_config=W_FP8_A_FP8_PER_TENSOR_CONFIG, exclude=exclude_layers)
21
22# Apply quantization
23quantizer = ModelQuantizer(quant_config)
24model = quantizer.quantize_model(model)
25
26# Export quantized model
27model = quantizer.freeze(model)
28export_safetensors(model, output_dir)
29tokenizer.save_pretrained(output_dir)| Benchmark | Qwen3-30B-A3B-Thinking-2507 (BF16) | Qwen3-30B-A3B-Thinking-2507-FP8 (this model) |
| GSM8K (5-shot, 1319 questions) | 0.836 | 0.872 |
1# Start the vLLM server
2vllm serve amd/Qwen3-30B-A3B-Thinking-2507-FP8 \
3 --max-model-len 4096 \
4 --trust-remote-code
5
6# Run the GSM8K evaluation (from the vLLM repo)
7python tests/evals/gsm8k/gsm8k_eval.py \
8 --num-shots 5 \
9 --num-questions 1319 \
10 --max-tokens 1024