fix(CRITICAL): launch_server.py覆盖所有vllm文件+运行xformers patch
varlen_fwd()崩溃是因为xformers patch只打到了corex-3.2.3/lib64路径, 但runtime加载的是corex/lib/python3路径(PYTHONPATH优先级更高)。 launch_server.py现在覆盖所有关键文件到每个vllm安装: - qwen3_5.py, paged_attn.py, model_runner.py等 - 12个prebuilt .so - 运行patch_xformers_sdpa_seq.py等源码patch脚本
This commit is contained in:
@@ -12,31 +12,88 @@ def _force_patch():
|
|||||||
patched = set()
|
patched = set()
|
||||||
|
|
||||||
for p in sys.path:
|
for p in sys.path:
|
||||||
api = os.path.join(p, "vllm", "entrypoints", "openai", "api_server.py")
|
vllm_root = os.path.join(p, "vllm")
|
||||||
if os.path.isfile(api) and api not in patched:
|
api = os.path.join(vllm_root, "entrypoints", "openai", "api_server.py")
|
||||||
for f in ["api_server.py", "cli_args.py", "serving_chat.py",
|
if not os.path.isfile(api) or api in patched:
|
||||||
"protocol.py", "serving_tokenization.py"]:
|
continue
|
||||||
src = os.path.join(src_dir, f)
|
|
||||||
dst = os.path.join(p, "vllm", "entrypoints", "openai", f)
|
# --- Entrypoints ---
|
||||||
if os.path.isfile(src):
|
for f in ["api_server.py", "cli_args.py", "serving_chat.py",
|
||||||
shutil.copy2(src, dst)
|
"protocol.py", "serving_tokenization.py"]:
|
||||||
# chat_utils
|
src = os.path.join(src_dir, f)
|
||||||
cu_src = os.path.join(src_dir, "chat_utils.py")
|
dst = os.path.join(vllm_root, "entrypoints", "openai", f)
|
||||||
cu_dst = os.path.join(p, "vllm", "entrypoints", "chat_utils.py")
|
if os.path.isfile(src):
|
||||||
if os.path.isfile(cu_src):
|
shutil.copy2(src, dst)
|
||||||
shutil.copy2(cu_src, cu_dst)
|
# chat_utils
|
||||||
# reasoning
|
cu_src = os.path.join(src_dir, "chat_utils.py")
|
||||||
reason_src = os.path.join(src_dir, "reasoning")
|
cu_dst = os.path.join(vllm_root, "entrypoints", "chat_utils.py")
|
||||||
reason_dst = os.path.join(p, "vllm", "reasoning")
|
if os.path.isfile(cu_src):
|
||||||
if os.path.isdir(reason_src):
|
shutil.copy2(cu_src, cu_dst)
|
||||||
shutil.copytree(reason_src, reason_dst, dirs_exist_ok=True)
|
# reasoning
|
||||||
# tool parser
|
reason_src = os.path.join(src_dir, "reasoning")
|
||||||
tp_src = os.path.join(src_dir, "qwen3coder_tool_parser.py")
|
reason_dst = os.path.join(vllm_root, "reasoning")
|
||||||
tp_dst = os.path.join(p, "vllm", "entrypoints", "openai",
|
if os.path.isdir(reason_src):
|
||||||
"tool_parsers", "qwen3coder_tool_parser.py")
|
shutil.copytree(reason_src, reason_dst, dirs_exist_ok=True)
|
||||||
if os.path.isfile(tp_src) and os.path.isdir(os.path.dirname(tp_dst)):
|
# tool parser
|
||||||
shutil.copy2(tp_src, tp_dst)
|
tp_src = os.path.join(src_dir, "qwen3coder_tool_parser.py")
|
||||||
patched.add(api)
|
tp_dst = os.path.join(vllm_root, "entrypoints", "openai",
|
||||||
|
"tool_parsers", "qwen3coder_tool_parser.py")
|
||||||
|
if os.path.isfile(tp_src) and os.path.isdir(os.path.dirname(tp_dst)):
|
||||||
|
shutil.copy2(tp_src, tp_dst)
|
||||||
|
|
||||||
|
# --- Model, attention, engine files (critical for runtime) ---
|
||||||
|
model_dir = os.path.join(vllm_root, "model_executor", "models")
|
||||||
|
attn_dir = os.path.join(vllm_root, "attention", "ops")
|
||||||
|
core_dir = os.path.join(vllm_root, "core")
|
||||||
|
for fname, dst_dir in [
|
||||||
|
("qwen3_5.py", model_dir),
|
||||||
|
("mamba_cache.py", model_dir),
|
||||||
|
("registry.py", model_dir),
|
||||||
|
("_custom_ops.py", vllm_root),
|
||||||
|
("paged_attn.py", attn_dir),
|
||||||
|
("sequence.py", vllm_root),
|
||||||
|
("scheduler.py", core_dir),
|
||||||
|
("model_runner.py", os.path.join(vllm_root, "worker")),
|
||||||
|
("bi100_env.py", vllm_root),
|
||||||
|
("bi100_profile.py", vllm_root),
|
||||||
|
("block_major_kv_cache.py", vllm_root),
|
||||||
|
("gdn_prefix.py", vllm_root),
|
||||||
|
("logits_processor.py", os.path.join(vllm_root, "model_executor", "layers")),
|
||||||
|
("sampler.py", os.path.join(vllm_root, "model_executor", "layers")),
|
||||||
|
]:
|
||||||
|
src = os.path.join(src_dir, fname)
|
||||||
|
if os.path.isfile(src) and os.path.isdir(dst_dir):
|
||||||
|
shutil.copy2(src, os.path.join(dst_dir, fname))
|
||||||
|
|
||||||
|
# --- Prebuilt .so files ---
|
||||||
|
prebuilt_dir = os.path.join(src_dir, "prebuilt", "corex-3.2.3-ivcore10")
|
||||||
|
if os.path.isdir(prebuilt_dir):
|
||||||
|
for so_file in os.listdir(prebuilt_dir):
|
||||||
|
if so_file.endswith(".so"):
|
||||||
|
src_so = os.path.join(prebuilt_dir, so_file)
|
||||||
|
dst_so = os.path.join(vllm_root, so_file)
|
||||||
|
if not os.path.isfile(dst_so):
|
||||||
|
shutil.copy2(src_so, dst_so)
|
||||||
|
|
||||||
|
# --- Run Python source patches on this vllm install ---
|
||||||
|
for patch_script in [
|
||||||
|
"patch_xformers_sdpa_seq.py",
|
||||||
|
"patch_xformers_profile.py",
|
||||||
|
"patch_model_runner.py",
|
||||||
|
"patch_vllm_qwen3_5.py",
|
||||||
|
"patch_corex_swap_blocks.py",
|
||||||
|
]:
|
||||||
|
script_path = os.path.join(src_dir, patch_script)
|
||||||
|
if os.path.isfile(script_path):
|
||||||
|
try:
|
||||||
|
import subprocess
|
||||||
|
subprocess.run([sys.executable, script_path],
|
||||||
|
cwd=src_dir, timeout=30,
|
||||||
|
capture_output=True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
patched.add(api)
|
||||||
|
|
||||||
if patched:
|
if patched:
|
||||||
print(f"[launch] Force-patched {len(patched)} vllm installs", file=sys.stderr)
|
print(f"[launch] Force-patched {len(patched)} vllm installs", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user