rene98c commited on
Commit
8d74833
·
verified ·
1 Parent(s): be05968

Upload 2 files

Browse files
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.