File size: 4,929 Bytes
c78e4fd
 
 
 
 
cbccebe
 
 
607ffaa
 
cbccebe
 
 
 
 
607ffaa
 
 
 
cbccebe
 
 
c78e4fd
 
607ffaa
c78e4fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51ecd16
c78e4fd
 
 
 
 
 
 
 
 
 
 
 
 
cbccebe
 
 
 
 
 
 
 
 
607ffaa
cbccebe
 
607ffaa
cbccebe
 
 
 
 
 
 
 
607ffaa
 
 
cbccebe
 
 
607ffaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbccebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
license: apache-2.0
base_model:
- Qwen/Qwen3-Coder-480B-A35B-Instruct
---

## Model Details

This model is a mixed int4 model with group_size 64 and symmetric quantization of [Qwen/Qwen3-Coder-480B-A35B-Instruct](https://huggingface.co/Qwen/Qwen3-Coder-480B-A35B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round) via **RTN** (no algorithm tuning).  
Non expert layers  fallback to 8 bits and group_size 128. mlp.gate layers fallback to 16 bits to ensure runing successfully on vLLM.

Please follow the license of the original model.

## How To Use

**vLLM usage**
~~~bash
vllm serve Intel/Qwen3-Coder-480B-A35B-Instruct-int4-mixed-ar --tensor-parallel-size 4 --max-model-len 65536
~~~
**INT4 Inference on CPU/Intel GPU/CUDA**

~~~python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "Intel/Qwen3-Coder-480B-A35B-Instruct-int4-mixed-ar"

# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)

prompts = [
    "Write a quick sort algorithm.",
    "Write a flappy bird.",
    "Write a llm quantization algorithm.",
]

texts = []
for prompt in prompts:
    messages = [
        {"role": "user", "content": prompt}
    ]
    text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True
    )
    texts.append(text)
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, padding_side="left").to(model.device)

# conduct text completion
outputs = model.generate(
    **inputs,
    max_new_tokens=65536,
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(inputs["input_ids"], outputs)
]

decoded_outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)

for i, prompt in enumerate(prompts):
    input_id = inputs
    print(f"Prompt: {prompt}")
    print(f"Generated: {decoded_outputs[i]}")
    print("-" * 50)


~~~

### Generate the model

Here is the sample command to reproduce the model

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
from auto_round import AutoRound

model_name = "Qwen/Qwen3-Coder-480B-A35B-Instruct"

model = AutoModelForCausalLM.from_pretrained(model_name,
                                             device_map="cpu", torch_dtype="auto")

tokenizer = AutoTokenizer.from_pretrained(model_name)

layer_config = {}
for n, m in model.named_modules():
    if "mlp.gate" in n: ## vllm only support 16 bit for this layer
        layer_config[n] = {"bits": 16}
    elif isinstance(m, torch.nn.Linear) and (not "expert" in n or "shared_experts" in n) and n != "lm_head":
        layer_config[n] = {"bits": 8, "group_size": 128}

autoround = AutoRound(model, tokenizer, iters=0, group_size=64, layer_config=layer_config)
output_dir = "/dataset/Qwen3-Coder-480B-A35B-Instruct-int4-mixed"
autoround.quantize_and_save(output_dir)

## tricky code to handle qkv fusing issue, we will fix it in vllm later
import os
import json

config_path = os.path.join(output_dir, "config.json")

with open(config_path, "r") as file:
    config = json.load(file)
extra_config = config["quantization_config"]["extra_config"]
num_hidden_layers = config["num_hidden_layers"]
for i in range(num_hidden_layers):
    qkv_name = f"model.layers.{str(i)}.self_attn.qkv_proj"
    extra_config[qkv_name] = {"bits": 8, "group_size": 128}
with open(config_path, "w") as file:
    json.dump(config, file, indent=2)
```



## Ethical Considerations and Limitations

The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## Caveats and Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.

Here are a couple of useful links to learn more about Intel's AI software:

- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)

## Disclaimer

The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.

## Cite

@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)