Files
project_6/qwen3_6_scripts/patch_ops.sh
project6-dev accf9539e6 fix(CRITICAL): CoreXGDN interface mismatch + engine death protection
Three fixes for the three bugs in latest docker log:

1. corex_gdn.py REWRITTEN — interface now matches qwen3_5.py:
   OLD: CoreXGDN(num_heads, head_dim, layer_idx, chunk_size, eps)
   NEW: CoreXGDN(num_v_heads, num_k_heads, head_k_dim, head_v_dim, conv_kernel_size, layer_idx)

   OLD forward: (q, k, v, gate, beta, conv_state, temporal_state, attn_metadata)
   NEW forward: (hidden_states, attn_metadata, conv_state, temporal_state,
                  in_proj_qkv, in_proj_z, in_proj_b, in_proj_a,
                  conv1d_weight, A_log, dt_bias, norm, out_proj)

   Fixes: 'CoreXGDN.__init__() got unexpected keyword argument num_v_heads'

2. serving_chat.py — engine death protection for multimodal:
   When model has no multimodal_config, return 400 instead of passing image data
   to engine (which causes permanent AsyncEngineDeadError).

   Fixes: 'ValueError: You set image=0 but found 1 items'

3. patch_ops.sh — ALWAYS deploy our modules (base image has bugs):
   - qwen3_5.py: ALWAYS deploy (base has NaN)
   - corex_gdn/moe/fa2.py: ALWAYS deploy (base interface mismatch)
   - corex_fa2.py was MISSING from base → now deployed
2026-08-10 09:51:58 +00:00

147 lines
6.9 KiB
Bash
Executable File

#!/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"