--- base_model: Qwen/Qwen4-35B-A3B base_model_relation: quantized library_name: transformers license: apache-2.0 pipeline_tag: image-text-to-text quantized_by: OpenTensorLab tags: - autoround - rtn - gptq - w4a16 - moe - qwen4 - vllm --- # Qwen4-35B-A3B-GPTQ (W4A16 RTN) This repository contains a **W4A16 (4-bit weight, 16-bit activation)** RTN (Round-To-Nearest) GPTQ-formatted quantization of **[Qwen/Qwen4-35B-A3B](https://huggingface.co/Qwen/Qwen4-35B-A3B)**, generated using **[Intel AutoRound](https://github.com/intel/auto-round)** without multi-iteration SignRound fine-tuning. > [!IMPORTANT] > **vLLM Compatibility Notice:** You **must** use the `vllm/vllm-openai:qwen4` Docker image (or a vLLM build containing the Qwen4 MoE + QSA + PLE integration) to serve this model right now. Standard stable vLLM releases do not yet include `Qwen4MoeForConditionalGeneration` / `Qwen4Exp` support. --- ## Quantization Details * **Base Model:** [`Qwen/Qwen4-35B-A3B`](https://huggingface.co/Qwen/Qwen4-35B-A3B) (35B total parameters, 3B active per token, plus 20B N-gram PLE embedding and 2B MTP layer) * **Method:** **RTN / Fast W4A16** (`iters=1` via [Intel AutoRound](https://github.com/intel/auto-round) `0.18.0.dev355` without multi-iteration SignRound optimization) * **Scheme & Format:** `W4A16` (`auto_gptq` layout, `group_size=128`, `sym=True`) * **Calibration:** `NeelNanda/pile-10k` (`nsamples=256`, `seqlen=2048`) * **Quantized Modules (30,760 / 31,434 linear layers):** * All 40 MoE layers' routed experts (`256` experts per layer: `gate_proj`, `up_proj`, `down_proj`) * All 10 Qwen Sparse Attention (QSA) layers (`q_proj`, `k_proj`, `v_proj`, `o_proj`) * **Preserved in `BF16` (Unquantized for Precision & Kernel Compatibility):** * Vision encoder (`model.visual.*`) * Gated DeltaNet linear attention layers (`linear_attn.*`) * Shared experts & MoE routers (`mlp.shared_expert.*`, `mlp.shared_expert_gate`, `mlp.gate`) * Manifold-Constrained Hyper-Connections (`attn_hyper_connection`, `mlp_hyper_connection`, `hyper_connection_mixer`) * QSA sparse attention indexers (`self_attn.indexer.index_qk_proj`) * Layer 1 Parameterized Lexical Embedding (`ple.*`, including the 10M-entry N-gram table offloaded to pinned host RAM by vLLM) * Multi-Token Prediction (`mtp.*`) draft head & `lm_head` --- ## Serving with vLLM (`vllm/vllm-openai:qwen4`) ### 1. Launch via Docker > [!NOTE] > **`--dtype bfloat16` is required.** vLLM's Qwen4 Sparse Attention (`Qwen4ExpQSAAttention`) kernel requires `bfloat16` activations and raises `NotImplementedError: Qwen4Exp QSA currently requires BF16` if loaded in `float16`. ```bash docker run --rm -it --gpus all \ --ipc=host \ -p 8000:8000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ vllm/vllm-openai:qwen4 \ OpenTensorLab/Qwen4-35B-A3B-GPTQ \ --dtype bfloat16 \ --trust-remote-code \ --enable-prefix-caching \ --max-model-len 32k \ --disable-flashinfer-autotune \ --gpu-memory-utilization 0.90 \ --kv-cache-dtype fp8 \ --attention-config.indexer_kv_dtype fp8 \ --enable-auto-tool-choice \ --tool-call-parser qwen4 \ --reasoning-parser qwen4 \ --speculative-config '{"method":"mtp","num_speculative_tokens":3,"index_share_for_mtp_iteration":true}' ``` ### 2. Verified Runtime Footprint On a single RTX PRO 600 GPU with `--gpu-memory-utilization 0.90` and `--max-model-len 32k`: * **GPU Weight + Non-Torch Memory:** `25.84 GiB` (N-gram PLE embedding automatically pinned in CPU host RAM) * **Peak Activation + CUDA Graph Memory:** `5.29 GiB` (`3.41 GiB` activation + `1.88 GiB` CUDA graphs) * **Available KV Cache (`fp8`):** `54.24 GiB` (`1,843,200` tokens / `57.60x` concurrency at 32K context) * **MTP Speculative Decoding (`num_speculative_tokens=3`):** Verified mean acceptance length `2.39 – 2.85` tokens per step (~`300 – 400 tok/s` single-stream generation) --- ## API Usage (OpenAI-Compatible) ```bash pip install -U openai export OPENAI_BASE_URL="http://localhost:8000/v1" export OPENAI_API_KEY="EMPTY" ``` ```python from openai import OpenAI client = OpenAI() messages = [ {"role": "user", "content": "Write a Python function to merge two sorted linked lists."}, ] completion = client.chat.completions.create( model="OpenTensorLab/Qwen4-35B-A3B-GPTQ", messages=messages, extra_body={ "chat_template_kwargs": { "preserve_thinking": True, "reasoning_effort": "high", # Supported: "xhigh", "high", "low", "off" }, }, stream=True, stream_options={"include_usage": True}, ) reasoning_content = "" answer_content = "" is_answering = False for chunk in completion: if not chunk.choices: print("\nUsage:", chunk.usage) continue delta = chunk.choices[0].delta if getattr(delta, "reasoning_content", None): if not is_answering: print(delta.reasoning_content, end="", flush=True) reasoning_content += delta.reasoning_content if getattr(delta, "content", None): if not is_answering: print("\n\n--- Answer ---\n") is_answering = True print(delta.content, end="", flush=True) answer_content += delta.content ``` ### Recommended Sampling Parameters * **Thinking Mode (`reasoning_effort` = `low` / `high` / `xhigh`):** `temperature=1.0`, `top_p=0.95`, `top_k=20`, `min_p=0.0`, `presence_penalty=0.0`, `repetition_penalty=1.0` * **Non-Thinking Mode (`reasoning_effort="off"` or `enable_thinking=False`):** `temperature=0.7`, `top_p=0.80`, `top_k=20`, `min_p=0.0`, `presence_penalty=1.5`, `repetition_penalty=1.0` --- ### 🚀 Deploy on RunPod One-click launch environments pre-configured with PyTorch, CUDA, and dependencies for fine-tuning or quantization. > 🎁 **Need GPU compute?** Sign up via [RunPod](https://runpod.io?ref=iabrlp7z) and get **$5–$500 in free credits** when you add your first $10. #### PyTorch 2.15 | Template | CUDA Version | Docker Image | Template ID | Deploy | | :--- | :--- | :--- | :--- | :--- | | **PyTorch 2.15 (CUDA 13.2)** | 13.2 | `vishva123/cuda-13.2-pytorch-2.15-runpod` | `0rsw686010` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=0rsw686010&ref=iabrlp7z) | | **PyTorch 2.15 (CUDA 13.4)** | 13.4 | `vishva123/cuda-13.4-pytorch-2.15-runpod` | `0s0rhdfaqy` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=0s0rhdfaqy&ref=iabrlp7z) | #### PyTorch 2.14 | Template | CUDA Version | Docker Image | Template ID | Deploy | | :--- | :--- | :--- | :--- | :--- | | **PyTorch 2.14 (CUDA 12.6)** | 12.6 | `vishva123/cuda-12.6-pytorch-2.14-runpod` | `d7lxsa4w9m` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=d7lxsa4w9m&ref=iabrlp7z) | | **PyTorch 2.14 (CUDA 13.0)** | 13.0 | `vishva123/cuda-13.0-pytorch-2.14-runpod` | `yk0y6j6rpg` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=yk0y6j6rpg&ref=iabrlp7z) | | **PyTorch 2.14 (CUDA 13.2)** | 13.2 | `vishva123/cuda-13.2-pytorch-2.14-runpod` | `gsp4gwx0nw` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=gsp4gwx0nw&ref=iabrlp7z) | #### PyTorch 2.13 | Template | CUDA Version | Docker Image | Template ID | Deploy | | :--- | :--- | :--- | :--- | :--- | | **PyTorch 2.13 (CUDA 12.6)** | 12.6 | `vishva123/cuda-12.6-pytorch-2.13-runpod` | `gmlupxnxfk` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=gmlupxnxfk&ref=iabrlp7z) | | **PyTorch 2.13 (CUDA 13.0)** | 13.0 | `vishva123/cuda-13.0-pytorch-2.13-runpod` | `y3j8xvk4f4` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=y3j8xvk4f4&ref=iabrlp7z) | | **PyTorch 2.13 (CUDA 13.2)** | 13.2 | `vishva123/cuda-13.2-pytorch-2.13-runpod` | `vigpissn5w` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=vigpissn5w&ref=iabrlp7z) | #### PyTorch 2.12 | Template | CUDA Version | Docker Image | Template ID | Deploy | | :--- | :--- | :--- | :--- | :--- | | **PyTorch 2.12 (CUDA 12.6)** | 12.6 | `vishva123/cuda-12.6-pytorch-2.12-runpod` | `ctmz86zmf0` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=ctmz86zmf0&ref=iabrlp7z) | | **PyTorch 2.12 (CUDA 13.0)** | 13.0 | `vishva123/cuda-13.0-pytorch-2.12-runpod` | `qjko5yiwzi` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=qjko5yiwzi&ref=iabrlp7z) | | **PyTorch 2.12 (CUDA 13.2)** | 13.2 | `vishva123/cuda-13.2-pytorch-2.12-runpod` | `ifg6xmye0f` | [![Deploy to RunPod](https://img.shields.io/badge/RunPod-Deploy%20Pod-purple?logo=runpod&logoColor=white)](https://runpod.io/console/deploy?template=ifg6xmye0f&ref=iabrlp7z) | --- ## Citation ```bibtex @misc{qwen4-35ba3b, title = {{Qwen4-35B-A3B}}, author = {{Qwen Team}}, month = {December}, year = {2026}, url = {[https://huggingface.co/Qwen/Qwen4-35B-A3B](https://huggingface.co/Qwen/Qwen4-35B-A3B)} } @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} } ```