#!/bin/bash # ========================================================================== # PATCH_OPS.SH — Deploy our engine fixes + serving layer # # BASE IMAGE HAS BUGS (proven by NaN when using base-only): # - GDN layers produce NaN (base corex_gdn.py interface mismatch) # - corex_fa2.py missing from model_executor/models/ # - No multimodal support in model → engine death on image request # # COMP 168 DEPLOYED CUSTOM CODE on top of base image to fix these → 48/52 pass # We must do the same. # ========================================================================== cd "$(dirname "$0")" echo "[patch_ops] START" VLLM="" for P in /usr/local/corex/lib/python3/dist-packages/vllm \ /usr/local/corex/lib64/python3/dist-packages/vllm; do if [ -d "$P" ]; then VLLM="$P" echo "[patch_ops] Found vllm at: $VLLM" break fi done [ -z "$VLLM" ] && echo "[patch_ops] ERROR: vllm not found" && exit 1 # ---- PROBE ---- echo "[probe] === Base image state ===" _QW="$VLLM/model_executor/models/qwen3_5.py" [ -f "$_QW" ] && echo "[probe] qwen3_5.py: $(wc -c < "$_QW") bytes" || echo "[probe] qwen3_5.py: MISSING" for m in corex_gdn.py corex_moe.py corex_fa2.py; do _F="$VLLM/model_executor/models/$m" [ -f "$_F" ] && echo "[probe] $m: $(wc -c < "$_F") bytes" || echo "[probe] $m: MISSING" done ls -la /usr/local/corex/lib64/libcorex_*.so 2>/dev/null || echo "[probe] no libcorex_*.so" echo "[probe] ===========================" # ---- 1. Transformers config ---- TMODELS="" for P in /usr/local/lib/python3.10/site-packages/transformers/models \ /usr/local/corex/lib/python3/dist-packages/transformers/models; do [ -d "$P" ] && TMODELS="$P" && break done if [ -n "$TMODELS" ]; then pip install transformers==4.55.3 -i https://pypi.tuna.tsinghua.edu.cn/simple --timeout 30 2>&1 || true apt-get update -qq && apt-get install -y -qq ninja-build 2>&1 || true cp -r ./qwen3_5 "$TMODELS/" 2>/dev/null || true cp -r ./qwen3_5_moe "$TMODELS/" 2>/dev/null || true python3 ./patch_transformers_qwen3_5.py 2>&1 || true echo "[patch_ops] transformers config deployed" fi # ---- 2. Model layer — deploy OUR fixes over base image ---- # 2a. qwen3_5.py — ALWAYS deploy ours (base image has NaN + no multimodal) cp ./qwen3_5.py "$VLLM/model_executor/models/qwen3_5.py" && \ echo "[patch_ops] qwen3_5.py deployed (fixes NaN + adds multimodal handling)" # 2b. corex modules — ALWAYS deploy ours (base interface mismatch causes fallback) cp /workspace/ex_engine/python/corex_gdn.py "$VLLM/model_executor/models/corex_gdn.py" && \ echo "[patch_ops] corex_gdn.py deployed (interface matches qwen3_5.py)" cp /workspace/ex_engine/python/corex_moe.py "$VLLM/model_executor/models/corex_moe.py" && \ echo "[patch_ops] corex_moe.py deployed" cp /workspace/ex_engine/python/corex_fa2.py "$VLLM/model_executor/models/corex_fa2.py" && \ echo "[patch_ops] corex_fa2.py deployed (was MISSING from base)" # 2c. Registry if grep -q "Qwen3_5ForCausalLM" "$VLLM/model_executor/models/registry.py" 2>/dev/null; then echo "[patch_ops] registry already has Qwen3_5" else cp ./registry.py "$VLLM/model_executor/models/registry.py" 2>/dev/null && \ echo "[patch_ops] registry.py deployed" fi # 2d. XFormers patches (head_dim=256 bypass) python3 ./patch_xformers_sdpa_seq.py 2>&1 || true python3 ./patch_xformers_sdpa_batch.py 2>&1 || true echo "[patch_ops] xformers patches applied" # 2e. model_runner prefix_cache_hit fix python3 ./patch_model_runner.py 2>&1 || true # 2f. mamba_cache (GDN state management) cp ./mamba_cache.py "$VLLM/model_executor/models/mamba_cache.py" 2>/dev/null && \ echo "[patch_ops] mamba_cache.py deployed" # 2g. sequence.py (token count fix) cp ./sequence.py "$VLLM/sequence.py" 2>/dev/null && \ echo "[patch_ops] sequence.py deployed" # 2h. scheduler.py (cache metrics) cp ./scheduler.py "$VLLM/core/scheduler.py" 2>/dev/null && \ echo "[patch_ops] scheduler.py deployed" # ---- 3. Serving layer ---- mkdir -p "$VLLM/entrypoints/openai/tool_parsers" 2>/dev/null || true cp ./qwen3coder_tool_parser.py "$VLLM/entrypoints/openai/tool_parsers/" 2>/dev/null || true cp ./tool_parsers_init.py "$VLLM/entrypoints/openai/tool_parsers/__init__.py" 2>/dev/null || true python3 ./patch_vllm_tool_parser.py 2>&1 || true echo "[patch_ops] tool parser deployed" cp -r ./reasoning "$VLLM/" 2>/dev/null || true echo "[patch_ops] reasoning parser deployed" cp ./protocol.py "$VLLM/entrypoints/openai/protocol.py" 2>/dev/null || true cp ./cli_args.py "$VLLM/entrypoints/openai/cli_args.py" 2>/dev/null || true cp ./serving_chat.py "$VLLM/entrypoints/openai/serving_chat.py" 2>/dev/null || true cp ./api_server.py "$VLLM/entrypoints/openai/api_server.py" 2>/dev/null || true cp ./chat_utils.py "$VLLM/entrypoints/chat_utils.py" 2>/dev/null || true echo "[patch_ops] serving layer deployed" # ---- 4. Mirror to VLLM2 ---- VLLM2="" for P in /usr/local/corex/lib/python3/dist-packages/vllm \ /usr/local/corex/lib64/python3/dist-packages/vllm; do [ -d "$P" ] && [ "$P" != "$VLLM" ] && VLLM2="$P" && break done if [ -n "$VLLM2" ]; then echo "[patch_ops] Mirroring to $VLLM2" cp ./qwen3_5.py "$VLLM2/model_executor/models/qwen3_5.py" 2>/dev/null || true cp /workspace/ex_engine/python/corex_gdn.py "$VLLM2/model_executor/models/corex_gdn.py" 2>/dev/null || true cp /workspace/ex_engine/python/corex_moe.py "$VLLM2/model_executor/models/corex_moe.py" 2>/dev/null || true cp /workspace/ex_engine/python/corex_fa2.py "$VLLM2/model_executor/models/corex_fa2.py" 2>/dev/null || true if ! grep -q "Qwen3_5ForCausalLM" "$VLLM2/model_executor/models/registry.py" 2>/dev/null; then cp ./registry.py "$VLLM2/model_executor/models/registry.py" 2>/dev/null || true fi cp ./mamba_cache.py "$VLLM2/model_executor/models/mamba_cache.py" 2>/dev/null || true cp ./sequence.py "$VLLM2/sequence.py" 2>/dev/null || true cp ./scheduler.py "$VLLM2/core/scheduler.py" 2>/dev/null || true mkdir -p "$VLLM2/entrypoints/openai/tool_parsers" 2>/dev/null || true cp ./qwen3coder_tool_parser.py "$VLLM2/entrypoints/openai/tool_parsers/" 2>/dev/null || true cp ./tool_parsers_init.py "$VLLM2/entrypoints/openai/tool_parsers/__init__.py" 2>/dev/null || true cp -r ./reasoning "$VLLM2/" 2>/dev/null || true cp ./protocol.py "$VLLM2/entrypoints/openai/protocol.py" 2>/dev/null || true cp ./cli_args.py "$VLLM2/entrypoints/openai/cli_args.py" 2>/dev/null || true cp ./serving_chat.py "$VLLM2/entrypoints/openai/serving_chat.py" 2>/dev/null || true cp ./api_server.py "$VLLM2/entrypoints/openai/api_server.py" 2>/dev/null || true cp ./chat_utils.py "$VLLM2/entrypoints/chat_utils.py" 2>/dev/null || true fi # ---- 5. _custom_ops.py (topk_softmax fallback) ---- cp ./_custom_ops.py "$VLLM/_custom_ops.py" 2>/dev/null && \ echo "[patch_ops] _custom_ops.py deployed" || true [ -n "$VLLM2" ] && cp ./_custom_ops.py "$VLLM2/_custom_ops.py" 2>/dev/null || true echo "[patch_ops] DONE"