k-l-lambda commited on
Commit
db50a98
·
verified ·
1 Parent(s): 52aa95f

Upload patch_vllm.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. patch_vllm.py +15 -9
patch_vllm.py CHANGED
@@ -24,15 +24,11 @@ if '"model.layers.": "language_model.model.layers."' not in c:
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
 
@@ -40,8 +36,6 @@ 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")
@@ -51,8 +45,20 @@ def _get_text_config(hf_config):
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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  else:
25
  print("kimi_k25.py already patched")
26
 
27
+ # Patch 3: deepseek_mtp.py - extract text_config
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
  if "text_config" not in c:
 
32
  import_marker = "from .utils import maybe_prefix"
33
  helper = '''from .utils import maybe_prefix
34
 
 
36
  """Extract text_config from VLM configs (e.g. KimiK25Config)."""
37
  return getattr(hf_config, 'text_config', hf_config)'''
38
  c = c.replace(import_marker, helper)
 
 
39
  c = c.replace(
40
  "config = vllm_config.model_config.hf_config\n self.mtp_start_layer_idx",
41
  "config = _get_text_config(vllm_config.model_config.hf_config)\n self.mtp_start_layer_idx")
 
45
  c = c.replace(
46
  "config = vllm_config.speculative_config.draft_model_config.hf_config\n self.config = config",
47
  "config = _get_text_config(vllm_config.speculative_config.draft_model_config.hf_config)\n self.config = config")
 
48
  with open(mtp_path, "w") as f: f.write(c)
49
+ print("deepseek_mtp.py PATCHED")
50
  else:
51
  print("deepseek_mtp.py already patched")
52
+
53
+ # Patch 4: eagle.py - handle KimiK25Config missing image_token_index
54
+ eagle_path = "/usr/local/lib/python3.12/dist-packages/vllm/v1/spec_decode/eagle.py"
55
+ with open(eagle_path) as f:
56
+ c = f.read()
57
+ old_eagle = " self.model.config.image_token_index = (\n target_model.config.image_token_index\n )"
58
+ new_eagle = " self.model.config.image_token_index = getattr(\n target_model.config, 'image_token_index',\n getattr(target_model.config, 'media_placeholder_token_id', 0)\n )"
59
+ if "media_placeholder_token_id" not in c:
60
+ c = c.replace(old_eagle, new_eagle)
61
+ with open(eagle_path, "w") as f: f.write(c)
62
+ print("eagle.py PATCHED (KimiK25 image_token_index fallback)")
63
+ else:
64
+ print("eagle.py already patched")