ChibuUkachi commited on
Commit
5b66a88
·
verified ·
1 Parent(s): 0a36661

base README.md

Browse files
Files changed (1) hide show
  1. README.md +178 -0
README.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-generation
4
+ tags:
5
+ - INT4
6
+ - quantized
7
+ - llm-compressor
8
+ - compressed-tensors
9
+ - red hat
10
+ base_model:
11
+ - Qwen/Qwen3-Coder-Next
12
+ ---
13
+
14
+
15
+ # Qwen3-Coder-Next.w4a16
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** Qwen3NextForCausalLM
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** INT4
23
+ - **Activation quantization:** FP16
24
+ - **Release Date:**
25
+ - **Version:** 1.0
26
+ - **Model Developers:**: Red Hat
27
+
28
+ Quantized version of [Qwen/Qwen3-Coder-Next](https://huggingface.co/Qwen/Qwen3-Coder-Next).
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights and activations of [Qwen/Qwen3-Coder-Next](https://huggingface.co/Qwen/Qwen3-Coder-Next) to INT4 data type.
33
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
34
+ Only the weights and activations of the linear operators within transformers blocks of the language model are quantized.
35
+
36
+ ## Deployment
37
+
38
+ ### Use with vLLM
39
+
40
+ 1. Initialize vLLM server:
41
+ ```
42
+ vllm serve inference-optimization/Qwen3-Coder-Next.w4a16 --port 8000 --tensor-parallel-size 2 --enable-auto-tool-choice --tool-call-parser qwen3_coder
43
+
44
+ ```
45
+
46
+ 2. Send requests to the server:
47
+
48
+ ```python
49
+ # Your tool implementation
50
+ def square_the_number(num: float) -> dict:
51
+ return num ** 2
52
+
53
+ # Define Tools
54
+ tools=[
55
+ {
56
+ "type":"function",
57
+ "function":{
58
+ "name": "square_the_number",
59
+ "description": "output the square of the number.",
60
+ "parameters": {
61
+ "type": "object",
62
+ "required": ["input_num"],
63
+ "properties": {
64
+ 'input_num': {
65
+ 'type': 'number',
66
+ 'description': 'input_num is a number that will be squared'
67
+ }
68
+ },
69
+ }
70
+ }
71
+ }
72
+ ]
73
+
74
+ from openai import OpenAI
75
+ # Define LLM
76
+ client = OpenAI(
77
+ # Use a custom endpoint compatible with OpenAI API
78
+ base_url='http://localhost:8000/v1', # api_base
79
+ api_key="EMPTY"
80
+ )
81
+
82
+ messages = [{'role': 'user', 'content': 'square the number 1024'}]
83
+
84
+ completion = client.chat.completions.create(
85
+ messages=messages,
86
+ model="RedHatAI/Qwen3-Coder-Next.w4a16",
87
+ max_tokens=65536,
88
+ tools=tools,
89
+ )
90
+
91
+ print(completion.choices[0])
92
+ ```
93
+
94
+
95
+ ## Creation
96
+
97
+ This model was quantized using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as shown below.
98
+
99
+ <details>
100
+ <summary>Creation details</summary>
101
+
102
+ ```python
103
+ from datasets import load_dataset
104
+ from transformers import AutoModelForCausalLM, AutoTokenizer
105
+ from llmcompressor import oneshot
106
+ from llmcompressor.modifiers.quantization import GPTQModifier
107
+
108
+ MODEL_ID = "Qwen/Qwen3-Coder-Next"
109
+
110
+ # Load model.
111
+ model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
112
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
113
+
114
+
115
+ NUM_CALIBRATION_SAMPLES=512
116
+ MAX_SEQUENCE_LENGTH=2048
117
+
118
+ # Load dataset.
119
+ ds = load_dataset("HuggingFaceH4/ultrachat_200k", split=f"train_sft[:{NUM_CALIBRATION_SAMPLES}]")
120
+ ds = ds.shuffle(seed=42)
121
+
122
+ # Preprocess the data into the format the model is trained with.
123
+ def preprocess(example):
124
+ return {"text": tokenizer.apply_chat_template(example["messages"], tokenize=False, )}
125
+
126
+ ds = ds.map(preprocess)
127
+
128
+ # Tokenize the data (be careful with bos tokens - we need add_special_tokens=False since the chat_template already added it).
129
+ def tokenize(sample):
130
+ return tokenizer(sample["text"], padding=False, max_length=MAX_SEQUENCE_LENGTH, truncation=True, add_special_tokens=False)
131
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
132
+
133
+ # Configure the quantization algorithm to run.
134
+ recipe = GPTQModifier(targets="Linear", scheme="W4A16", weight_observer="mse", ignore= ['re:.*lm_head', 're:.*mlp.gate$', 're:.*mlp.shared_expert_gate$', 're:.*linear_attn.*'])
135
+
136
+ # Apply quantization.
137
+ oneshot(
138
+ model=model, dataset=ds,
139
+ recipe=recipe,
140
+ max_seq_length=MAX_SEQUENCE_LENGTH,
141
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
142
+ )
143
+
144
+ # Save to disk compressed.
145
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-W4A16-G128"
146
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
147
+ tokenizer.save_pretrained(SAVE_DIR)
148
+ ```
149
+ </details>
150
+
151
+
152
+ ## Evaluation
153
+
154
+
155
+ The model was evaluated on the OpenLLM leaderboard task, using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness).
156
+ [vLLM](https://docs.vllm.ai/en/stable/) was used for all evaluations.
157
+
158
+ <details>
159
+ <summary>Evaluation details</summary>
160
+
161
+ **Coding Benchmarks **
162
+
163
+ **SWE-Bench**
164
+ ```
165
+ python -m swebench.harness.run_evaluation \
166
+ --dataset_name princeton-nlp/SWE-bench_Lite \
167
+ --predictions_path preds.json \
168
+ --run_id validate-preds
169
+ ```
170
+
171
+ </details>
172
+
173
+
174
+ ## Accuracy
175
+
176
+ | Category | Metric | Qwen3-Coder-Next | Qwen3-Coder-Next.w4a16 | Recovery (%) |
177
+ |----------|--------|-------------|-------------------|--------------|
178
+ | SWE-Bench | Lite | 49.33 | 44 | 89.2 |