Upload download_gn_parser_for_vllm.py with huggingface_hub
Browse files
download_gn_parser_for_vllm.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import vllm
|
| 4 |
+
|
| 5 |
+
# Get vllm reasoning directory
|
| 6 |
+
vllm_path = os.path.dirname(vllm.__file__)
|
| 7 |
+
reasoning_dir = os.path.join(vllm_path, "reasoning")
|
| 8 |
+
init_file = os.path.join(reasoning_dir, "__init__.py")
|
| 9 |
+
parser_file = os.path.join(reasoning_dir, "greenmind_14b_r1_reasoning_parser.py")
|
| 10 |
+
|
| 11 |
+
# Download the GreenMind parser
|
| 12 |
+
url = "https://huggingface.co/GreenNode/GreenMind-Medium-14B-R1/resolve/main/greenmind_14b_r1_reasoning_parser.py"
|
| 13 |
+
subprocess.run(["wget", "-O", parser_file, url], check=True)
|
| 14 |
+
|
| 15 |
+
# Read __init__.py
|
| 16 |
+
with open(init_file, "r") as f:
|
| 17 |
+
lines = f.readlines()
|
| 18 |
+
|
| 19 |
+
# Ensure import is present
|
| 20 |
+
import_line = "from .greenmind_14b_r1_reasoning_parser import GreenMind14bR1ReasoningParser\n"
|
| 21 |
+
if import_line not in lines:
|
| 22 |
+
last_import_idx = None
|
| 23 |
+
for i, line in enumerate(lines):
|
| 24 |
+
if line.startswith("from ."):
|
| 25 |
+
last_import_idx = i
|
| 26 |
+
if last_import_idx is not None:
|
| 27 |
+
lines.insert(last_import_idx + 1, import_line)
|
| 28 |
+
|
| 29 |
+
# Ensure __all__ contains the parser
|
| 30 |
+
all_entry = ' "GreenMind14bR1ReasoningParser",\n'
|
| 31 |
+
if all_entry not in lines:
|
| 32 |
+
for i, line in enumerate(lines):
|
| 33 |
+
if line.strip().startswith("__all__"):
|
| 34 |
+
# find the next line with a string entry inside __all__
|
| 35 |
+
for j in range(i + 1, len(lines)):
|
| 36 |
+
if lines[j].strip().startswith('"') or lines[j].strip().startswith("'"):
|
| 37 |
+
lines.insert(j, all_entry)
|
| 38 |
+
break
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
# Write back updated file
|
| 42 |
+
with open(init_file, "w") as f:
|
| 43 |
+
f.writelines(lines)
|
| 44 |
+
|
| 45 |
+
print("✅ GreenMind14bR1ReasoningParser successfully added to vLLM.")
|