k-l-lambda commited on
Commit
c7ab596
·
verified ·
1 Parent(s): 4a758e7

Upload patch_vllm.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. patch_vllm.py +58 -0
patch_vllm.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Patch 1: speculative.py
2
+ spec_path = "/usr/local/lib/python3.12/dist-packages/vllm/config/speculative.py"
3
+ with open(spec_path) as f:
4
+ c = f.read()
5
+ old = '"deepseek_v3", "deepseek_v32", "glm_moe_dsa"'
6
+ new = '"deepseek_v3", "deepseek_v32", "glm_moe_dsa", "kimi_k25"'
7
+ if old in c and "kimi_k25" not in c:
8
+ c = c.replace(old, new)
9
+ with open(spec_path, "w") as f: f.write(c)
10
+ print("speculative.py PATCHED")
11
+ else:
12
+ print("speculative.py already patched")
13
+
14
+ # Patch 2: kimi_k25.py
15
+ k25_path = "/usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/kimi_k25.py"
16
+ with open(k25_path) as f:
17
+ c = f.read()
18
+ if '"model.layers.": "language_model.model.layers."' not in c:
19
+ c = c.replace(
20
+ '"language_model.layers.": "language_model.model.layers.",',
21
+ '"language_model.layers.": "language_model.model.layers.",\n "model.layers.": "language_model.model.layers.",')
22
+ with open(k25_path, "w") as f: f.write(c)
23
+ print("kimi_k25.py PATCHED")
24
+ else:
25
+ print("kimi_k25.py already patched")
26
+
27
+ # Patch 3: deepseek_mtp.py - add text_config extraction everywhere config is read
28
+ mtp_path = "/usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/deepseek_mtp.py"
29
+ with open(mtp_path) as f:
30
+ c = f.read()
31
+
32
+ # Replace ALL occurrences of "vllm_config.model_config.hf_config" in this file
33
+ # to add text_config fallback
34
+ if "text_config" not in c:
35
+ # Strategy: add a helper function at the top, then use it
36
+ import_marker = "from .utils import maybe_prefix"
37
+ helper = '''from .utils import maybe_prefix
38
+
39
+ def _get_text_config(hf_config):
40
+ """Extract text_config from VLM configs (e.g. KimiK25Config)."""
41
+ return getattr(hf_config, 'text_config', hf_config)'''
42
+ c = c.replace(import_marker, helper)
43
+
44
+ # Replace all config reads
45
+ c = c.replace(
46
+ "config = vllm_config.model_config.hf_config\n self.mtp_start_layer_idx",
47
+ "config = _get_text_config(vllm_config.model_config.hf_config)\n self.mtp_start_layer_idx")
48
+ c = c.replace(
49
+ "self.config = vllm_config.model_config.hf_config\n self.model = DeepSeekMultiTokenPredictor",
50
+ "self.config = _get_text_config(vllm_config.model_config.hf_config)\n self.model = DeepSeekMultiTokenPredictor")
51
+ c = c.replace(
52
+ "config = vllm_config.speculative_config.draft_model_config.hf_config\n self.config = config",
53
+ "config = _get_text_config(vllm_config.speculative_config.draft_model_config.hf_config)\n self.config = config")
54
+
55
+ with open(mtp_path, "w") as f: f.write(c)
56
+ print("deepseek_mtp.py PATCHED (all config reads)")
57
+ else:
58
+ print("deepseek_mtp.py already patched")