Views
No views yet
1import torch
2from modelscope import AutoModelForCausalLM, AutoTokenizer
3
4model_name = "swift/Qwen3-30B-A3B-AWQ"
5
6# load the tokenizer and the model
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 torch_dtype=torch.float16,
11 device_map="auto"
12)
13
14# prepare the model input
15prompt = "Give me a short introduction to large language model."
16messages = [
17 {"role": "user", "content": prompt}
18]
19text = tokenizer.apply_chat_template(
20 messages,
21 tokenize=False,
22 add_generation_prompt=True,
23 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# conduct text completion
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=32768
31)
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
33
34# parsing thinking content
35try:
36 # rindex finding 151668 (</think>)
37 index = len(output_ids) - output_ids[::-1].index(151668)
38except ValueError:
39 index = 0
40
41thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
42content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
43
44print("thinking content:", thinking_content)
45print("content:", content)linear layers except for gate and lm_head have been quantized.The performance comparison of Qwen3-30B-A3B-AWQ and Qwen3-30B-A3B
| task_type | dataset_name | metric | average_score(AWQ) | average_score(without AWQ) | count |
|---|---|---|---|---|---|
| exam | MMLU-Pro | AverageAccuracy | 0.7655 | 0.7828 | 12032 |
| exam | MMLU-Redux | AverageAccuracy | 0.8746 | 0.8872 | 5700 |
| exam | C-Eval | AverageAccuracy | 0.844 | 0.8722 | 1346 |
| instruction | IFEval | inst_level_strict_acc | 0.8891 | 0.8925 | 541 |
| instruction | IFEval | inst_level_loose_acc | 0.9107 | 0.9174 | 541 |
| instruction | IFEval | prompt_level_loose_acc | 0.8651 | 0.8651 | 541 |
| instruction | IFEval | prompt_level_strict_acc | 0.8373 | 0.8318 | 541 |
| math | MATH-500 | AveragePass@1 | 0.944 | 0.938 | 500 |
| knowledge | GPQA | AveragePass@1 | 0.596 | 0.601 | 198 |
| code | LiveCodeBench | Pass@1 | 0.5275 | 0.5549 | 182 |
| exam | iQuiz | AverageAccuracy | 0.6917 | 0.7417 | 120 |
| math | AIME 2024 | AveragePass@1 | 0.7333 | 0.8333 | 30 |
| math | AIME 2025 | AveragePass@1 | 0.7 | 0.7333 | 30 |
NOTE: For the pass@k metric, considering time cost of evaluation, we uniformly limit the number of generated responses to 1