Image-Text-to-Text
Transformers
Safetensors
qwen3_5_moe
qwen3.5
Mixture of Experts
gptq
quantized
4-bit precision
vllm
vision
multimodal
mtp
conversational
Instructions to use btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit") model = AutoModelForMultimodalLM.from_pretrained("btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit
- SGLang
How to use btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit with Docker Model Runner:
docker model run hf.co/btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit
Upload folder using huggingface_hub
Browse files- .gitattributes +2 -0
- README.md +163 -0
- chat_template.jinja +154 -0
- config.json +169 -0
- generation_config.json +13 -0
- merges.txt +0 -0
- model-00001-of-00007.safetensors +3 -0
- model-00002-of-00007.safetensors +3 -0
- model-00003-of-00007.safetensors +3 -0
- model-00004-of-00007.safetensors +3 -0
- model-00005-of-00007.safetensors +3 -0
- model-00006-of-00007.safetensors +3 -0
- model-00007-of-00007.safetensors +3 -0
- model.safetensors.index.json +3 -0
- perplexity_results.txt +6 -0
- preprocessor_config.json +21 -0
- quant_log.csv +0 -0
- quantize.py +190 -0
- quantize_config.json +54 -0
- tokenizer.json +3 -0
- tokenizer_config.json +31 -0
- video_preprocessor_config.json +21 -0
- vocab.json +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: Qwen/Qwen3.5-35B-A3B
|
| 3 |
+
library_name: transformers
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- qwen3.5
|
| 7 |
+
- moe
|
| 8 |
+
- gptq
|
| 9 |
+
- quantized
|
| 10 |
+
- 4-bit
|
| 11 |
+
- vllm
|
| 12 |
+
- vision
|
| 13 |
+
- multimodal
|
| 14 |
+
- mtp
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Qwen3.5-35B-A3B GPTQ 4-bit
|
| 18 |
+
|
| 19 |
+
GPTQ 4-bit quantization of [Qwen/Qwen3.5-35B-A3B](https://huggingface.co/Qwen/Qwen3.5-35B-A3B), a 35B-parameter Mixture-of-Experts (MoE) multimodal model with 3B activated parameters per token.
|
| 20 |
+
|
| 21 |
+
Includes full vision encoder and MTP (Multi-Token Prediction) module for image understanding and speculative decoding support.
|
| 22 |
+
|
| 23 |
+
## Model Overview
|
| 24 |
+
|
| 25 |
+
- **Architecture**: Qwen3_5MoeForConditionalGeneration (multimodal: text + vision)
|
| 26 |
+
- **Total parameters**: ~35B
|
| 27 |
+
- **Activated parameters**: ~3B per token (8 of 256 experts selected per token)
|
| 28 |
+
- **Layers**: 40 (30 linear attention + 10 full attention, repeating 3:1 pattern)
|
| 29 |
+
- **Experts**: 256 per layer + 1 shared expert per layer
|
| 30 |
+
- **Context length**: 262,144 tokens
|
| 31 |
+
- **Vision encoder**: 27-block ViT (1152 hidden, 16x16 patches), BF16
|
| 32 |
+
- **MTP module**: 1-layer speculative decoding head, BF16
|
| 33 |
+
|
| 34 |
+
## Quantization Details
|
| 35 |
+
|
| 36 |
+
All 30,720 MoE expert modules (256 experts x 3 projections x 40 layers) are quantized to INT4 using GPTQ. Non-expert modules (including the full vision encoder and MTP module) remain at BF16/FP16 for quality preservation.
|
| 37 |
+
|
| 38 |
+
| Component | Precision | Notes |
|
| 39 |
+
|-----------|-----------|-------|
|
| 40 |
+
| MoE experts (`gate_proj`, `up_proj`, `down_proj`) | INT4 (GPTQ) | 30,720 modules quantized |
|
| 41 |
+
| Full attention (`q_proj`, `k_proj`, `v_proj`, `o_proj`) | FP16 | Every 4th layer |
|
| 42 |
+
| Linear attention (`in_proj_qkv`, `in_proj_z`, `out_proj`) | FP16 | Full precision |
|
| 43 |
+
| Shared experts | FP16 | Full precision |
|
| 44 |
+
| Vision encoder (`model.visual.*`) | BF16 | 333 tensors, full precision |
|
| 45 |
+
| MTP module (`mtp.*`) | BF16 | 785 tensors, full precision |
|
| 46 |
+
| Embeddings, LM head, norms | FP16 | Full precision |
|
| 47 |
+
|
| 48 |
+
**GPTQ configuration:**
|
| 49 |
+
- **Bits**: 4
|
| 50 |
+
- **Group size**: 32
|
| 51 |
+
- **Symmetric**: Yes
|
| 52 |
+
- **desc_act**: No
|
| 53 |
+
- **true_sequential**: Yes
|
| 54 |
+
- **act_group_aware**: Yes
|
| 55 |
+
- **Failsafe**: RTN for poorly-calibrated rare experts (1,350 of 30,720 modules, ~4.4%)
|
| 56 |
+
|
| 57 |
+
### Calibration
|
| 58 |
+
|
| 59 |
+
- **Dataset**: Mixed - evol-codealpaca-v1 (code) + C4 (general text)
|
| 60 |
+
- **Samples**: 2,048
|
| 61 |
+
- **Quantizer**: [GPTQModel](https://github.com/modelcloud/gptqmodel) v5.7.1
|
| 62 |
+
|
| 63 |
+
## Model Size
|
| 64 |
+
|
| 65 |
+
| Version | Size | Compression |
|
| 66 |
+
|---------|------|-------------|
|
| 67 |
+
| BF16 (original) | 67 GB | - |
|
| 68 |
+
| GPTQ 8-bit | 40 GB | 1.7x |
|
| 69 |
+
| GPTQ 4-bit | 25 GB | 2.7x |
|
| 70 |
+
|
| 71 |
+
## Perplexity
|
| 72 |
+
|
| 73 |
+
Evaluated on wikitext-2-raw-v1 (test set), seq_len=2048, stride=512:
|
| 74 |
+
|
| 75 |
+
| Model | Perplexity | Degradation |
|
| 76 |
+
|-------|------------|-------------|
|
| 77 |
+
| BF16 (original) | 6.0695 | - |
|
| 78 |
+
| GPTQ 8-bit | 6.0748 | +0.09% |
|
| 79 |
+
| GPTQ 4-bit | 6.1260 | +0.93% |
|
| 80 |
+
|
| 81 |
+
## Usage
|
| 82 |
+
|
| 83 |
+
### vLLM (Recommended for Serving)
|
| 84 |
+
|
| 85 |
+
```bash
|
| 86 |
+
vllm serve btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit \
|
| 87 |
+
--gpu-memory-utilization 0.95 \
|
| 88 |
+
--max-model-len 256000 \
|
| 89 |
+
--tensor-parallel-size 4 \
|
| 90 |
+
--reasoning-parser qwen3 \
|
| 91 |
+
--enable-auto-tool-choice --tool-call-parser qwen3_coder \
|
| 92 |
+
--dtype float16 \
|
| 93 |
+
--skip-mm-profiling \
|
| 94 |
+
--limit-mm-per-prompt '{"image": 2}'
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
| Parameter | Description |
|
| 98 |
+
|-----------|-------------|
|
| 99 |
+
| `--gpu-memory-utilization 0.95` | Use 95% of GPU VRAM for KV cache + weights |
|
| 100 |
+
| `--max-model-len 256000` | Full 256K context window support |
|
| 101 |
+
| `--tensor-parallel-size 4` | Shard across 4 GPUs (adjust to your setup) |
|
| 102 |
+
| `--reasoning-parser qwen3` | Enable thinking/reasoning token parsing |
|
| 103 |
+
| `--enable-auto-tool-choice --tool-call-parser qwen3_coder` | Enable tool/function calling |
|
| 104 |
+
| `--dtype float16` | Run in FP16 (required for ROCm GPTQ kernels) |
|
| 105 |
+
| `--skip-mm-profiling` | Skip multimodal memory profiling at startup |
|
| 106 |
+
| `--limit-mm-per-prompt '{"image": 2}'` | Allow up to 2 images per request |
|
| 107 |
+
|
| 108 |
+
> **vLLM bug workaround**: vLLM versions up to at least 0.15.2 have a bug in `Qwen3_5MoeTextConfig` where `ignore_keys_at_rope_validation` is defined as a `list` instead of a `set`, causing a `TypeError` during config parsing. Apply this fix before serving:
|
| 109 |
+
>
|
| 110 |
+
> ```python
|
| 111 |
+
> python3 -c "
|
| 112 |
+
> for f in [
|
| 113 |
+
> '/usr/local/lib/python3.12/dist-packages/vllm/transformers_utils/configs/qwen3_5_moe.py',
|
| 114 |
+
> '/usr/local/lib/python3.12/dist-packages/vllm/transformers_utils/configs/qwen3_5.py',
|
| 115 |
+
> ]:
|
| 116 |
+
> t = open(f).read()
|
| 117 |
+
> t = t.replace(
|
| 118 |
+
> 'ignore_keys_at_rope_validation\"] = [\n \"mrope_section\",\n \"mrope_interleaved\",\n ]',
|
| 119 |
+
> 'ignore_keys_at_rope_validation\"] = {\n \"mrope_section\",\n \"mrope_interleaved\",\n }')
|
| 120 |
+
> open(f,'w').write(t)
|
| 121 |
+
> print('Patched', f)
|
| 122 |
+
> "
|
| 123 |
+
> ```
|
| 124 |
+
|
| 125 |
+
### Vision Example (via OpenAI API)
|
| 126 |
+
|
| 127 |
+
```python
|
| 128 |
+
import base64, requests
|
| 129 |
+
|
| 130 |
+
with open("image.png", "rb") as f:
|
| 131 |
+
b64 = base64.b64encode(f.read()).decode()
|
| 132 |
+
|
| 133 |
+
response = requests.post("http://localhost:8000/v1/chat/completions", json={
|
| 134 |
+
"model": "btbtyler09/Qwen3.5-35B-A3B-GPTQ-4bit",
|
| 135 |
+
"messages": [{"role": "user", "content": [
|
| 136 |
+
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}},
|
| 137 |
+
{"type": "text", "text": "Describe what you see in this image."},
|
| 138 |
+
]}],
|
| 139 |
+
"max_tokens": 1024,
|
| 140 |
+
})
|
| 141 |
+
print(response.json()["choices"][0]["message"]["content"])
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
### GPTQModel / transformers
|
| 145 |
+
|
| 146 |
+
> **Note**: Neither GPTQModel nor transformers can currently load this model directly. GPTQModel's `Qwen3_5MoeGPTQ` class expects the text-only weight prefix (`model.layers.*`) and does not support the multimodal architecture (`model.language_model.layers.*`). The transformers GPTQ path delegates to `optimum`, which does not handle the fused-expert architecture. Use **vLLM** for inference.
|
| 147 |
+
|
| 148 |
+
## Technical Notes
|
| 149 |
+
|
| 150 |
+
Qwen3.5-35B-A3B stores MoE expert weights as fused 3D `nn.Parameter` tensors rather than individual `nn.Linear` modules. During quantization, GPTQModel's `MODULE_CONVERTER_MAP` converts these to individual quantizable `nn.Linear` layers. This same conversion must also run during model loading for the quantized kernels to be applied correctly.
|
| 151 |
+
|
| 152 |
+
The vision encoder (27-block ViT) and MTP speculative decoding module are preserved at full BF16 precision from the original model. Only the text model's MoE expert weights are quantized.
|
| 153 |
+
|
| 154 |
+
## Credits
|
| 155 |
+
|
| 156 |
+
- **Base Model**: [Qwen](https://huggingface.co/Qwen) - Qwen3.5-35B-A3B
|
| 157 |
+
- **Quantization**: GPTQ via [GPTQModel](https://github.com/modelcloud/gptqmodel) v5.7.1
|
| 158 |
+
- **Expert Converter**: `convert_qwen3_5_moe_expert_converter` for fused 3D expert weights
|
| 159 |
+
- **Quantized by**: [btbtyler09](https://huggingface.co/btbtyler09)
|
| 160 |
+
|
| 161 |
+
## License
|
| 162 |
+
|
| 163 |
+
This model inherits the [Apache 2.0 license](https://huggingface.co/Qwen/Qwen3.5-35B-A3B/blob/main/LICENSE) from the base model.
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set image_count = namespace(value=0) %}
|
| 2 |
+
{%- set video_count = namespace(value=0) %}
|
| 3 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
+
{%- if content is string %}
|
| 5 |
+
{{- content }}
|
| 6 |
+
{%- elif content is iterable and content is not mapping %}
|
| 7 |
+
{%- for item in content %}
|
| 8 |
+
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
|
| 9 |
+
{%- if is_system_content %}
|
| 10 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 11 |
+
{%- endif %}
|
| 12 |
+
{%- if do_vision_count %}
|
| 13 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- if add_vision_id %}
|
| 16 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 19 |
+
{%- elif 'video' in item or item.type == 'video' %}
|
| 20 |
+
{%- if is_system_content %}
|
| 21 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 22 |
+
{%- endif %}
|
| 23 |
+
{%- if do_vision_count %}
|
| 24 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 25 |
+
{%- endif %}
|
| 26 |
+
{%- if add_vision_id %}
|
| 27 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
+
{%- elif 'text' in item %}
|
| 31 |
+
{{- item.text }}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- elif content is none or content is undefined %}
|
| 37 |
+
{{- '' }}
|
| 38 |
+
{%- else %}
|
| 39 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endmacro %}
|
| 42 |
+
{%- if not messages %}
|
| 43 |
+
{{- raise_exception('No messages provided.') }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 46 |
+
{{- '<|im_start|>system\n' }}
|
| 47 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 48 |
+
{%- for tool in tools %}
|
| 49 |
+
{{- "\n" }}
|
| 50 |
+
{{- tool | tojson }}
|
| 51 |
+
{%- endfor %}
|
| 52 |
+
{{- "\n</tools>" }}
|
| 53 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 54 |
+
{%- if messages[0].role == 'system' %}
|
| 55 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 56 |
+
{%- if content %}
|
| 57 |
+
{{- '\n\n' + content }}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{{- '<|im_end|>\n' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{%- if messages[0].role == 'system' %}
|
| 63 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 64 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 65 |
+
{%- endif %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 68 |
+
{%- for message in messages[::-1] %}
|
| 69 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 70 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 71 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 72 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 73 |
+
{%- set ns.multi_step_tool = false %}
|
| 74 |
+
{%- set ns.last_query_index = index %}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if ns.multi_step_tool %}
|
| 79 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- for message in messages %}
|
| 82 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 83 |
+
{%- if message.role == "system" %}
|
| 84 |
+
{%- if not loop.first %}
|
| 85 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- elif message.role == "user" %}
|
| 88 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 89 |
+
{%- elif message.role == "assistant" %}
|
| 90 |
+
{%- set reasoning_content = '' %}
|
| 91 |
+
{%- if message.reasoning_content is string %}
|
| 92 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 93 |
+
{%- else %}
|
| 94 |
+
{%- if '</think>' in content %}
|
| 95 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 96 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 97 |
+
{%- endif %}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 100 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 101 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 102 |
+
{%- else %}
|
| 103 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 104 |
+
{%- endif %}
|
| 105 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 106 |
+
{%- for tool_call in message.tool_calls %}
|
| 107 |
+
{%- if tool_call.function is defined %}
|
| 108 |
+
{%- set tool_call = tool_call.function %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- if loop.first %}
|
| 111 |
+
{%- if content|trim %}
|
| 112 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 113 |
+
{%- else %}
|
| 114 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 115 |
+
{%- endif %}
|
| 116 |
+
{%- else %}
|
| 117 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 118 |
+
{%- endif %}
|
| 119 |
+
{%- if tool_call.arguments is defined %}
|
| 120 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 121 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 122 |
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 123 |
+
{{- args_value }}
|
| 124 |
+
{{- '\n</parameter>\n' }}
|
| 125 |
+
{%- endfor %}
|
| 126 |
+
{%- endif %}
|
| 127 |
+
{{- '</function>\n</tool_call>' }}
|
| 128 |
+
{%- endfor %}
|
| 129 |
+
{%- endif %}
|
| 130 |
+
{{- '<|im_end|>\n' }}
|
| 131 |
+
{%- elif message.role == "tool" %}
|
| 132 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 133 |
+
{{- '<|im_start|>user' }}
|
| 134 |
+
{%- endif %}
|
| 135 |
+
{{- '\n<tool_response>\n' }}
|
| 136 |
+
{{- content }}
|
| 137 |
+
{{- '\n</tool_response>' }}
|
| 138 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 139 |
+
{{- '<|im_end|>\n' }}
|
| 140 |
+
{%- elif loop.last %}
|
| 141 |
+
{{- '<|im_end|>\n' }}
|
| 142 |
+
{%- endif %}
|
| 143 |
+
{%- else %}
|
| 144 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{%- endfor %}
|
| 147 |
+
{%- if add_generation_prompt %}
|
| 148 |
+
{{- '<|im_start|>assistant\n' }}
|
| 149 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
| 150 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 151 |
+
{%- else %}
|
| 152 |
+
{{- '<think>\n' }}
|
| 153 |
+
{%- endif %}
|
| 154 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Qwen3_5MoeForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"image_token_id": 248056,
|
| 6 |
+
"model_type": "qwen3_5_moe",
|
| 7 |
+
"text_config": {
|
| 8 |
+
"attention_bias": false,
|
| 9 |
+
"attention_dropout": 0.0,
|
| 10 |
+
"attn_output_gate": true,
|
| 11 |
+
"dtype": "bfloat16",
|
| 12 |
+
"eos_token_id": 248044,
|
| 13 |
+
"full_attention_interval": 4,
|
| 14 |
+
"head_dim": 256,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 2048,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"layer_types": [
|
| 19 |
+
"linear_attention",
|
| 20 |
+
"linear_attention",
|
| 21 |
+
"linear_attention",
|
| 22 |
+
"full_attention",
|
| 23 |
+
"linear_attention",
|
| 24 |
+
"linear_attention",
|
| 25 |
+
"linear_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"linear_attention",
|
| 28 |
+
"linear_attention",
|
| 29 |
+
"linear_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"linear_attention",
|
| 32 |
+
"linear_attention",
|
| 33 |
+
"linear_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"linear_attention",
|
| 36 |
+
"linear_attention",
|
| 37 |
+
"linear_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"linear_attention",
|
| 40 |
+
"linear_attention",
|
| 41 |
+
"linear_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"linear_attention",
|
| 44 |
+
"linear_attention",
|
| 45 |
+
"linear_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"linear_attention",
|
| 48 |
+
"linear_attention",
|
| 49 |
+
"linear_attention",
|
| 50 |
+
"full_attention",
|
| 51 |
+
"linear_attention",
|
| 52 |
+
"linear_attention",
|
| 53 |
+
"linear_attention",
|
| 54 |
+
"full_attention",
|
| 55 |
+
"linear_attention",
|
| 56 |
+
"linear_attention",
|
| 57 |
+
"linear_attention",
|
| 58 |
+
"full_attention"
|
| 59 |
+
],
|
| 60 |
+
"linear_conv_kernel_dim": 4,
|
| 61 |
+
"linear_key_head_dim": 128,
|
| 62 |
+
"linear_num_key_heads": 16,
|
| 63 |
+
"linear_num_value_heads": 32,
|
| 64 |
+
"linear_value_head_dim": 128,
|
| 65 |
+
"max_position_embeddings": 262144,
|
| 66 |
+
"mlp_only_layers": [],
|
| 67 |
+
"model_type": "qwen3_5_moe_text",
|
| 68 |
+
"moe_intermediate_size": 512,
|
| 69 |
+
"mtp_num_hidden_layers": 1,
|
| 70 |
+
"mtp_use_dedicated_embeddings": false,
|
| 71 |
+
"num_attention_heads": 16,
|
| 72 |
+
"num_experts": 256,
|
| 73 |
+
"num_experts_per_tok": 8,
|
| 74 |
+
"num_hidden_layers": 40,
|
| 75 |
+
"num_key_value_heads": 2,
|
| 76 |
+
"rms_norm_eps": 1e-06,
|
| 77 |
+
"router_aux_loss_coef": 0.001,
|
| 78 |
+
"shared_expert_intermediate_size": 512,
|
| 79 |
+
"use_cache": true,
|
| 80 |
+
"vocab_size": 248320,
|
| 81 |
+
"mamba_ssm_dtype": "float32",
|
| 82 |
+
"rope_parameters": {
|
| 83 |
+
"mrope_interleaved": true,
|
| 84 |
+
"mrope_section": [
|
| 85 |
+
11,
|
| 86 |
+
11,
|
| 87 |
+
10
|
| 88 |
+
],
|
| 89 |
+
"rope_type": "default",
|
| 90 |
+
"rope_theta": 10000000,
|
| 91 |
+
"partial_rotary_factor": 0.25
|
| 92 |
+
}
|
| 93 |
+
},
|
| 94 |
+
"tie_word_embeddings": false,
|
| 95 |
+
"transformers_version": "4.57.0.dev0",
|
| 96 |
+
"video_token_id": 248057,
|
| 97 |
+
"vision_config": {
|
| 98 |
+
"deepstack_visual_indexes": [],
|
| 99 |
+
"depth": 27,
|
| 100 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 101 |
+
"hidden_size": 1152,
|
| 102 |
+
"in_channels": 3,
|
| 103 |
+
"initializer_range": 0.02,
|
| 104 |
+
"intermediate_size": 4304,
|
| 105 |
+
"model_type": "qwen3_5_moe",
|
| 106 |
+
"num_heads": 16,
|
| 107 |
+
"num_position_embeddings": 2304,
|
| 108 |
+
"out_hidden_size": 2048,
|
| 109 |
+
"patch_size": 16,
|
| 110 |
+
"spatial_merge_size": 2,
|
| 111 |
+
"temporal_patch_size": 2
|
| 112 |
+
},
|
| 113 |
+
"vision_end_token_id": 248054,
|
| 114 |
+
"vision_start_token_id": 248053,
|
| 115 |
+
"quantization_config": {
|
| 116 |
+
"bits": 4,
|
| 117 |
+
"checkpoint_format": "gptq",
|
| 118 |
+
"desc_act": false,
|
| 119 |
+
"dynamic": {
|
| 120 |
+
"-:.*linear_attn\\.in_proj_qkv": {},
|
| 121 |
+
"-:.*linear_attn\\.in_proj_z": {},
|
| 122 |
+
"-:.*linear_attn\\.out_proj": {},
|
| 123 |
+
"-:.*shared_expert\\.down_proj": {},
|
| 124 |
+
"-:.*shared_expert\\.gate_proj": {},
|
| 125 |
+
"-:.*shared_expert\\.up_proj": {}
|
| 126 |
+
},
|
| 127 |
+
"format": "gptq",
|
| 128 |
+
"group_size": 32,
|
| 129 |
+
"lm_head": false,
|
| 130 |
+
"meta": {
|
| 131 |
+
"act_group_aware": true,
|
| 132 |
+
"auto_forward_data_parallel": false,
|
| 133 |
+
"damp_auto_increment": 0.01,
|
| 134 |
+
"damp_percent": 0.05,
|
| 135 |
+
"failsafe": {
|
| 136 |
+
"smooth": {
|
| 137 |
+
"group_size_threshold": 128,
|
| 138 |
+
"k": 2.75,
|
| 139 |
+
"type": "mad"
|
| 140 |
+
},
|
| 141 |
+
"strategy": "rtn",
|
| 142 |
+
"threshold": "0.5%"
|
| 143 |
+
},
|
| 144 |
+
"gc_mode": "interval",
|
| 145 |
+
"gptaq": null,
|
| 146 |
+
"hessian": {
|
| 147 |
+
"chunk_bytes": null,
|
| 148 |
+
"chunk_size": null,
|
| 149 |
+
"staging_dtype": "float32"
|
| 150 |
+
},
|
| 151 |
+
"mock_quantization": false,
|
| 152 |
+
"mse": 0.0,
|
| 153 |
+
"offload_to_disk": false,
|
| 154 |
+
"offload_to_disk_path": null,
|
| 155 |
+
"pack_impl": "cpu",
|
| 156 |
+
"quantizer": [
|
| 157 |
+
"gptqmodel:5.7.1"
|
| 158 |
+
],
|
| 159 |
+
"static_groups": false,
|
| 160 |
+
"true_sequential": true,
|
| 161 |
+
"uri": "https://github.com/modelcloud/gptqmodel",
|
| 162 |
+
"vram_strategy": "exclusive",
|
| 163 |
+
"wait_for_submodule_finalizers": false
|
| 164 |
+
},
|
| 165 |
+
"pack_dtype": "int32",
|
| 166 |
+
"quant_method": "gptq",
|
| 167 |
+
"sym": true
|
| 168 |
+
}
|
| 169 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 248044,
|
| 3 |
+
"do_sample": true,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
248046,
|
| 6 |
+
248044
|
| 7 |
+
],
|
| 8 |
+
"pad_token_id": 248044,
|
| 9 |
+
"temperature": 1.0,
|
| 10 |
+
"top_k": 20,
|
| 11 |
+
"top_p": 0.95,
|
| 12 |
+
"transformers_version": "5.2.0"
|
| 13 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-00001-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b4358552b46e1a784378cf44b96af2dfacfc8660d97b413518ce9ef6a6edfde
|
| 3 |
+
size 3879674832
|
model-00002-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3621df26f6e63eeaf11420b8e002634e86130bccbaaa8b8bd1a55cff3c1a783c
|
| 3 |
+
size 4297389000
|
model-00003-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5777d1a7a3116a6b95b0c82df8546589ecdc1950de8bdf930a67a7de766c27e6
|
| 3 |
+
size 4298770456
|
model-00004-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:093429512178971d603455090cccf4ccb19899065a1e2051b84260e587fe9749
|
| 3 |
+
size 4298312840
|
model-00005-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7637b2fd3be33fe9160d660498494dda9b58446b46efa402e532c39bcdfb5162
|
| 3 |
+
size 4298769424
|
model-00006-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fd11ea2d7a2d6bb9b09e28d2c9eae432fd66a144bb10e76c0d1f7f84c0b5066a
|
| 3 |
+
size 2652010424
|
model-00007-of-00007.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1249c64ad3a44c3e63d97a666a0e5fa47f023c15357069ab23c916601cc19d7f
|
| 3 |
+
size 2582556456
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f32519b5a8a0e2fa8242ec8271823b102b1327214a20bb21271b8ed20ead4faa
|
| 3 |
+
size 13140672
|
perplexity_results.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Model: ./quant/Qwen3.5-35B-A3B-GPTQ-4bit/
|
| 2 |
+
Dataset: wikitext-2-raw-v1 (test)
|
| 3 |
+
Samples: 2891
|
| 4 |
+
Sequence length: 2048
|
| 5 |
+
Stride: 512
|
| 6 |
+
Perplexity: 6.1260
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"size": {
|
| 3 |
+
"longest_edge": 16777216,
|
| 4 |
+
"shortest_edge": 65536
|
| 5 |
+
},
|
| 6 |
+
"patch_size": 16,
|
| 7 |
+
"temporal_patch_size": 2,
|
| 8 |
+
"merge_size": 2,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.5,
|
| 11 |
+
0.5,
|
| 12 |
+
0.5
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.5,
|
| 16 |
+
0.5,
|
| 17 |
+
0.5
|
| 18 |
+
],
|
| 19 |
+
"processor_class": "Qwen3VLProcessor",
|
| 20 |
+
"image_processor_type": "Qwen2VLImageProcessorFast"
|
| 21 |
+
}
|
quant_log.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
quantize.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Quantize Qwen3.5-35B-A3B (35B MoE multimodal) to GPTQ 4-bit using GPTQModel v5.7.1.
|
| 4 |
+
|
| 5 |
+
Requires:
|
| 6 |
+
- GPTQModel >= 5.7.1 (with Qwen3.5 MoE expert converter support)
|
| 7 |
+
- ~160GB system RAM (model loaded to CPU with offload_to_disk=False)
|
| 8 |
+
- 1+ GPUs with >= 32GB VRAM
|
| 9 |
+
|
| 10 |
+
Quantization strategy:
|
| 11 |
+
- MoE experts (gate_proj, up_proj, down_proj): INT4 GPTQ, group_size=32
|
| 12 |
+
- Everything else (attention, linear_attn, shared_expert, norms, embeddings): FP16
|
| 13 |
+
- Vision encoder and MTP module: untouched (BF16)
|
| 14 |
+
- Mixed calibration: code (evol-codealpaca) + general text (C4)
|
| 15 |
+
- 2048 samples with context length binning for uniform expert coverage
|
| 16 |
+
- RTN failsafe for rare experts with insufficient calibration data
|
| 17 |
+
|
| 18 |
+
Note: GPTQModel currently quantizes only the text model (Qwen3_5MoeForCausalLM).
|
| 19 |
+
The vision encoder and MTP module must be restored separately after quantization.
|
| 20 |
+
See the model card for details.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
import os
|
| 24 |
+
import logging
|
| 25 |
+
import random
|
| 26 |
+
|
| 27 |
+
import torch
|
| 28 |
+
from gptqmodel import GPTQModel
|
| 29 |
+
from gptqmodel.quantization import QuantizeConfig
|
| 30 |
+
from datasets import load_dataset
|
| 31 |
+
from transformers import AutoTokenizer
|
| 32 |
+
|
| 33 |
+
# Configuration
|
| 34 |
+
MODEL_ID = "Qwen/Qwen3.5-35B-A3B"
|
| 35 |
+
OUTPUT_DIR = "./Qwen3.5-35B-A3B-GPTQ-4bit"
|
| 36 |
+
NUM_CALIBRATION_SAMPLES = 2048
|
| 37 |
+
MAX_SEQ_LENGTH = 2048
|
| 38 |
+
BITS = 4
|
| 39 |
+
GROUP_SIZE = 32
|
| 40 |
+
|
| 41 |
+
# Context length bins for uniform distribution
|
| 42 |
+
TOKEN_BINS = [(256, 512), (512, 1024), (1024, 1536), (1536, 2048)]
|
| 43 |
+
|
| 44 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
|
| 45 |
+
logger = logging.getLogger(__name__)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def prepare_calibration_dataset(tokenizer, num_samples, token_bins):
|
| 49 |
+
"""
|
| 50 |
+
Prepare mixed calibration dataset with uniform context length distribution.
|
| 51 |
+
Loads code (evol-codealpaca) and general text (C4), bins by token count,
|
| 52 |
+
and returns a uniform distribution across context length bins.
|
| 53 |
+
"""
|
| 54 |
+
logger.info(f"Target: {num_samples} samples across {len(token_bins)} bins")
|
| 55 |
+
|
| 56 |
+
binned_samples = {i: [] for i in range(len(token_bins))}
|
| 57 |
+
|
| 58 |
+
# Load datasets
|
| 59 |
+
logger.info("Loading code dataset: theblackcat102/evol-codealpaca-v1")
|
| 60 |
+
code_dataset = load_dataset("theblackcat102/evol-codealpaca-v1", split="train")
|
| 61 |
+
|
| 62 |
+
logger.info("Loading general text dataset: allenai/c4")
|
| 63 |
+
c4_dataset = load_dataset(
|
| 64 |
+
"allenai/c4",
|
| 65 |
+
data_files="en/c4-train.00001-of-01024.json.gz",
|
| 66 |
+
split="train"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
def format_code_sample(sample):
|
| 70 |
+
instruction = sample.get("instruction", "")
|
| 71 |
+
output = sample.get("output", "")
|
| 72 |
+
return f"### Instruction:\n{instruction}\n\n### Response:\n{output}"
|
| 73 |
+
|
| 74 |
+
# Pre-tokenize all samples
|
| 75 |
+
all_samples = []
|
| 76 |
+
|
| 77 |
+
for sample in code_dataset:
|
| 78 |
+
text = format_code_sample(sample)
|
| 79 |
+
if len(text) < 50:
|
| 80 |
+
continue
|
| 81 |
+
token_count = len(tokenizer.encode(text, add_special_tokens=False))
|
| 82 |
+
all_samples.append((text, token_count))
|
| 83 |
+
|
| 84 |
+
for idx, sample in enumerate(c4_dataset):
|
| 85 |
+
if idx >= 50000:
|
| 86 |
+
break
|
| 87 |
+
text = sample.get("text", "")
|
| 88 |
+
if len(text) < 50:
|
| 89 |
+
continue
|
| 90 |
+
token_count = len(tokenizer.encode(text, add_special_tokens=False))
|
| 91 |
+
all_samples.append((text, token_count))
|
| 92 |
+
|
| 93 |
+
logger.info(f"Total samples pool: {len(all_samples)}")
|
| 94 |
+
|
| 95 |
+
# Bin samples by token length
|
| 96 |
+
for text, token_count in all_samples:
|
| 97 |
+
for bin_idx, (min_tok, max_tok) in enumerate(token_bins):
|
| 98 |
+
if min_tok <= token_count < max_tok:
|
| 99 |
+
binned_samples[bin_idx].append(text)
|
| 100 |
+
break
|
| 101 |
+
|
| 102 |
+
# Chain short samples for sparse long-context bins
|
| 103 |
+
random.shuffle(all_samples)
|
| 104 |
+
|
| 105 |
+
def create_chained_sample(min_tokens, max_tokens):
|
| 106 |
+
chained_texts, current_tokens, attempts = [], 0, 0
|
| 107 |
+
while current_tokens < min_tokens and attempts < 50:
|
| 108 |
+
text, tok_count = random.choice(all_samples)
|
| 109 |
+
if current_tokens + tok_count > max_tokens:
|
| 110 |
+
attempts += 1
|
| 111 |
+
continue
|
| 112 |
+
chained_texts.append(text)
|
| 113 |
+
current_tokens += tok_count
|
| 114 |
+
attempts = 0
|
| 115 |
+
if min_tokens <= current_tokens < max_tokens:
|
| 116 |
+
return "\n\n---\n\n".join(chained_texts)
|
| 117 |
+
return None
|
| 118 |
+
|
| 119 |
+
samples_per_bin = num_samples // len(token_bins)
|
| 120 |
+
for bin_idx, (min_tok, max_tok) in enumerate(token_bins):
|
| 121 |
+
needed = samples_per_bin + 1 - len(binned_samples[bin_idx])
|
| 122 |
+
if needed > 0:
|
| 123 |
+
for _ in range(needed * 20):
|
| 124 |
+
chained = create_chained_sample(min_tok, max_tok)
|
| 125 |
+
if chained:
|
| 126 |
+
binned_samples[bin_idx].append(chained)
|
| 127 |
+
needed -= 1
|
| 128 |
+
if needed <= 0:
|
| 129 |
+
break
|
| 130 |
+
|
| 131 |
+
for bin_idx, (min_tok, max_tok) in enumerate(token_bins):
|
| 132 |
+
logger.info(f" Bin {bin_idx} ({min_tok}-{max_tok} tokens): {len(binned_samples[bin_idx])} samples")
|
| 133 |
+
|
| 134 |
+
# Sample uniformly from each bin
|
| 135 |
+
remainder = num_samples % len(token_bins)
|
| 136 |
+
final_samples = []
|
| 137 |
+
for bin_idx in range(len(token_bins)):
|
| 138 |
+
target = samples_per_bin + (1 if bin_idx < remainder else 0)
|
| 139 |
+
bin_data = binned_samples[bin_idx]
|
| 140 |
+
if len(bin_data) < target:
|
| 141 |
+
final_samples.extend(bin_data)
|
| 142 |
+
final_samples.extend(random.choices(bin_data, k=target - len(bin_data)))
|
| 143 |
+
else:
|
| 144 |
+
final_samples.extend(random.sample(bin_data, target))
|
| 145 |
+
|
| 146 |
+
random.shuffle(final_samples)
|
| 147 |
+
logger.info(f"Final calibration dataset: {len(final_samples)} samples")
|
| 148 |
+
return final_samples
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# Load tokenizer
|
| 152 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, use_fast=True, trust_remote_code=True)
|
| 153 |
+
|
| 154 |
+
# Prepare calibration data
|
| 155 |
+
calibration_data = prepare_calibration_dataset(tokenizer, NUM_CALIBRATION_SAMPLES, TOKEN_BINS)
|
| 156 |
+
|
| 157 |
+
# Dynamic exclusions: keep these at full precision (FP16)
|
| 158 |
+
dynamic_exclusions = {
|
| 159 |
+
"-:.*linear_attn\\.in_proj_qkv": {},
|
| 160 |
+
"-:.*linear_attn\\.in_proj_z": {},
|
| 161 |
+
"-:.*linear_attn\\.out_proj": {},
|
| 162 |
+
"-:.*shared_expert\\.gate_proj": {},
|
| 163 |
+
"-:.*shared_expert\\.up_proj": {},
|
| 164 |
+
"-:.*shared_expert\\.down_proj": {},
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
# Create quantization config
|
| 168 |
+
quant_config = QuantizeConfig(
|
| 169 |
+
bits=BITS,
|
| 170 |
+
group_size=GROUP_SIZE,
|
| 171 |
+
sym=True,
|
| 172 |
+
desc_act=False,
|
| 173 |
+
true_sequential=True,
|
| 174 |
+
offload_to_disk=False,
|
| 175 |
+
lm_head=False,
|
| 176 |
+
dynamic=dynamic_exclusions,
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Load and quantize
|
| 180 |
+
logger.info(f"Loading {MODEL_ID}...")
|
| 181 |
+
model = GPTQModel.load(MODEL_ID, quant_config, trust_remote_code=True)
|
| 182 |
+
|
| 183 |
+
logger.info("Starting quantization...")
|
| 184 |
+
model.quantize(calibration_data, batch_size=1)
|
| 185 |
+
|
| 186 |
+
logger.info(f"Saving to {OUTPUT_DIR}...")
|
| 187 |
+
model.save(OUTPUT_DIR)
|
| 188 |
+
tokenizer.save_pretrained(OUTPUT_DIR)
|
| 189 |
+
|
| 190 |
+
logger.info("Done!")
|
quantize_config.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bits": 4,
|
| 3 |
+
"dynamic": {
|
| 4 |
+
"-:.*linear_attn\\.in_proj_qkv": {},
|
| 5 |
+
"-:.*linear_attn\\.in_proj_z": {},
|
| 6 |
+
"-:.*linear_attn\\.out_proj": {},
|
| 7 |
+
"-:.*shared_expert\\.gate_proj": {},
|
| 8 |
+
"-:.*shared_expert\\.up_proj": {},
|
| 9 |
+
"-:.*shared_expert\\.down_proj": {}
|
| 10 |
+
},
|
| 11 |
+
"group_size": 32,
|
| 12 |
+
"desc_act": false,
|
| 13 |
+
"lm_head": false,
|
| 14 |
+
"quant_method": "gptq",
|
| 15 |
+
"checkpoint_format": "gptq",
|
| 16 |
+
"pack_dtype": "int32",
|
| 17 |
+
"meta": {
|
| 18 |
+
"quantizer": [
|
| 19 |
+
"gptqmodel:5.7.1"
|
| 20 |
+
],
|
| 21 |
+
"uri": "https://github.com/modelcloud/gptqmodel",
|
| 22 |
+
"damp_percent": 0.05,
|
| 23 |
+
"damp_auto_increment": 0.01,
|
| 24 |
+
"static_groups": false,
|
| 25 |
+
"true_sequential": true,
|
| 26 |
+
"mse": 0.0,
|
| 27 |
+
"gptaq": null,
|
| 28 |
+
"act_group_aware": true,
|
| 29 |
+
"failsafe": {
|
| 30 |
+
"strategy": "rtn",
|
| 31 |
+
"threshold": "0.5%",
|
| 32 |
+
"smooth": {
|
| 33 |
+
"type": "mad",
|
| 34 |
+
"group_size_threshold": 128,
|
| 35 |
+
"k": 2.75
|
| 36 |
+
}
|
| 37 |
+
},
|
| 38 |
+
"offload_to_disk": false,
|
| 39 |
+
"offload_to_disk_path": null,
|
| 40 |
+
"pack_impl": "cpu",
|
| 41 |
+
"mock_quantization": false,
|
| 42 |
+
"gc_mode": "interval",
|
| 43 |
+
"wait_for_submodule_finalizers": false,
|
| 44 |
+
"auto_forward_data_parallel": false,
|
| 45 |
+
"hessian": {
|
| 46 |
+
"chunk_size": null,
|
| 47 |
+
"chunk_bytes": null,
|
| 48 |
+
"staging_dtype": "float32"
|
| 49 |
+
},
|
| 50 |
+
"vram_strategy": "exclusive"
|
| 51 |
+
},
|
| 52 |
+
"sym": true,
|
| 53 |
+
"format": "gptq"
|
| 54 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87a7830d63fcf43bf241c3c5242e96e62dd3fdc29224ca26fed8ea333db72de4
|
| 3 |
+
size 19989343
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": null,
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"errors": "replace",
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": false,
|
| 13 |
+
"model_max_length": 262144,
|
| 14 |
+
"model_specific_special_tokens": {
|
| 15 |
+
"audio_bos_token": "<|audio_start|>",
|
| 16 |
+
"audio_eos_token": "<|audio_end|>",
|
| 17 |
+
"audio_token": "<|audio_pad|>",
|
| 18 |
+
"image_token": "<|image_pad|>",
|
| 19 |
+
"video_token": "<|video_pad|>",
|
| 20 |
+
"vision_bos_token": "<|vision_start|>",
|
| 21 |
+
"vision_eos_token": "<|vision_end|>"
|
| 22 |
+
},
|
| 23 |
+
"pad_token": "<|endoftext|>",
|
| 24 |
+
"pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
|
| 25 |
+
"split_special_tokens": false,
|
| 26 |
+
"tokenizer_class": "TokenizersBackend",
|
| 27 |
+
"unk_token": null,
|
| 28 |
+
"video_token": "<|video_pad|>",
|
| 29 |
+
"vision_bos_token": "<|vision_start|>",
|
| 30 |
+
"vision_eos_token": "<|vision_end|>"
|
| 31 |
+
}
|
video_preprocessor_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"size": {
|
| 3 |
+
"longest_edge": 25165824,
|
| 4 |
+
"shortest_edge": 4096
|
| 5 |
+
},
|
| 6 |
+
"patch_size": 16,
|
| 7 |
+
"temporal_patch_size": 2,
|
| 8 |
+
"merge_size": 2,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.5,
|
| 11 |
+
0.5,
|
| 12 |
+
0.5
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.5,
|
| 16 |
+
0.5,
|
| 17 |
+
0.5
|
| 18 |
+
],
|
| 19 |
+
"processor_class": "Qwen3VLProcessor",
|
| 20 |
+
"video_processor_type": "Qwen3VLVideoProcessor"
|
| 21 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|