Text Generation
Transformers
Safetensors
qwen3_5_moe
image-text-to-text
qwen3.5
Mixture of Experts
pruned
reap
nvfp4
fp4
conversational
compressed-tensors
Instructions to use rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4") model = AutoModelForMultimodalLM.from_pretrained("rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4
- SGLang
How to use rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4 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 "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4" \ --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": "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4" \ --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": "rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4 with Docker Model Runner:
docker model run hf.co/rene98c/Qwen3.5-397B-A17B-REAP-28-NVFP4
Upload 2 files
Browse files- patches/qwen3_5.py.patch.md +56 -0
- patches/qwen3_next.py.patch.md +28 -0
patches/qwen3_5.py.patch.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vLLM Patch: qwen3_5.py — Tensor shape-based expert count in weight loading
|
| 2 |
+
|
| 3 |
+
**File:** `vllm/model_executor/models/qwen3_5.py`
|
| 4 |
+
**Class:** `Qwen3_5Model.load_weights`
|
| 5 |
+
**Tested on:** vLLM 0.16.1rc1.dev188
|
| 6 |
+
|
| 7 |
+
## What it does
|
| 8 |
+
|
| 9 |
+
When loading fused expert weights (`experts.gate_up_proj`, `experts.down_proj`), infers the
|
| 10 |
+
expert count from the tensor's first dimension instead of reading `config.num_experts`.
|
| 11 |
+
This allows loading models where each layer has a different number of experts.
|
| 12 |
+
|
| 13 |
+
## Patch
|
| 14 |
+
|
| 15 |
+
In `Qwen3_5Model.load_weights`, find the fused expert loading block (where
|
| 16 |
+
`is_fused_expert` is True). Replace the hardcoded `num_experts` usage with
|
| 17 |
+
shape-based inference:
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
if is_fused_expert:
|
| 21 |
+
# qwen3.5 no need to transpose
|
| 22 |
+
# Use tensor shape for expert count (supports
|
| 23 |
+
# variable experts per layer, e.g. REAP pruned)
|
| 24 |
+
if "experts.gate_up_proj" in name:
|
| 25 |
+
loaded_weight = loaded_weight.chunk(2, dim=-2)
|
| 26 |
+
n_exp = loaded_weight[0].shape[0]
|
| 27 |
+
success_w1 = self.load_fused_expert_weights(
|
| 28 |
+
name_mapped,
|
| 29 |
+
params_dict,
|
| 30 |
+
loaded_weight[0],
|
| 31 |
+
"w1",
|
| 32 |
+
n_exp,
|
| 33 |
+
)
|
| 34 |
+
success_w3 = self.load_fused_expert_weights(
|
| 35 |
+
name_mapped,
|
| 36 |
+
params_dict,
|
| 37 |
+
loaded_weight[1],
|
| 38 |
+
"w3",
|
| 39 |
+
n_exp,
|
| 40 |
+
)
|
| 41 |
+
success = success_w1 and success_w3
|
| 42 |
+
else:
|
| 43 |
+
# down_proj
|
| 44 |
+
n_exp = loaded_weight.shape[0]
|
| 45 |
+
success = self.load_fused_expert_weights(
|
| 46 |
+
name_mapped,
|
| 47 |
+
params_dict,
|
| 48 |
+
loaded_weight,
|
| 49 |
+
shard_id,
|
| 50 |
+
n_exp,
|
| 51 |
+
)
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
The key change: `n_exp = loaded_weight[0].shape[0]` (or `loaded_weight.shape[0]` for
|
| 55 |
+
down_proj) replaces the fixed `num_experts` parameter. Each layer's tensor carries its
|
| 56 |
+
own expert count.
|
patches/qwen3_next.py.patch.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vLLM Patch: qwen3_next.py — Variable expert count per layer
|
| 2 |
+
|
| 3 |
+
**File:** `vllm/model_executor/models/qwen3_next.py`
|
| 4 |
+
**Class:** `Qwen3NextSparseMoeBlock.__init__`
|
| 5 |
+
**Tested on:** vLLM 0.16.1rc1.dev188
|
| 6 |
+
|
| 7 |
+
## What it does
|
| 8 |
+
|
| 9 |
+
Reads `num_experts_per_layer` (a list) from the model config to support REAP-pruned models
|
| 10 |
+
where each layer has a different number of experts. Falls back to `config.num_experts` for
|
| 11 |
+
standard models.
|
| 12 |
+
|
| 13 |
+
## Patch
|
| 14 |
+
|
| 15 |
+
In `Qwen3NextSparseMoeBlock.__init__`, find where `self.n_routed_experts` is set
|
| 16 |
+
(after `self.ep_size = ...`), and replace the fixed assignment with:
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
# Support variable expert counts per layer (REAP pruned models)
|
| 20 |
+
layer_idx = extract_layer_index(prefix)
|
| 21 |
+
if hasattr(config, 'num_experts_per_layer') and config.num_experts_per_layer:
|
| 22 |
+
num_experts = config.num_experts_per_layer[layer_idx]
|
| 23 |
+
else:
|
| 24 |
+
num_experts = config.num_experts
|
| 25 |
+
self.n_routed_experts = num_experts
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
The `extract_layer_index` function is already imported from `.utils` in the stock file.
|