Files
wangdongyun 8173863f48 feat: 天数智芯 mrv-100 tokenizer 自动修复镜像(vLLM 0.8.3)
- fix_tokenizer.py:候选策略 + 真实试加载兜底,覆盖 extra_special_tokens 为 list /
  tokenizer_class 非法 / from_slow 误用 tokenizer.json / auto_map 远程代码四类问题
- vllm_wrapper.sh:拦 serve,修复失败、超时或路径非法时原样启动,尊重调用方 --tokenizer
- install_patch.sh:构建期定位 vllm、改名 *_real、装 wrapper 并烘焙真实路径与解释器
- selftest_fix_tokenizer.py:离线自测(不需要 transformers / GPU)
2026-11-10 06:39:43 +00:00

39 lines
1.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 构建期脚本:把 PATH 上的 vllm 换成 wrapper,原二进制改名成 *_real。
#
# 用法(在 Dockerfile 里):bash install_patch.sh /tmp
# /tmp/fix_tokenizer.py 修复脚本
# /tmp/vllm_wrapper.sh wrapper 模板(含 @@VLLM_REAL@@ / @@FIX_PYTHON@@ 占位)
#
# 为什么要现场解析路径:不同加速卡镜像把 vllm 装在不同位置(有的在 /usr/local/bin,
# 有的在 dist-packages/bin),写死路径会打错对象。wrapper 需要落在 vllm 原来的位置上,
# 这样调用方 `--entrypoint vllm` 才会命中。
set -euo pipefail
SRC_DIR="${1:-/tmp}"
FIXER_DEST=/usr/local/bin/fix_tokenizer.py
# 1) 找到 vllm 的真实路径
VLLM_BIN="$(command -v vllm || true)"
[ -n "$VLLM_BIN" ] || { echo "ERROR: vllm not found on PATH" >&2; exit 1; }
# 2) 解释器:优先用原 vllm 脚本的 shebang,保证和 vllm 同一个 python
PY="$(head -n 1 "$VLLM_BIN" \
| sed -e 's/^#!//' -e 's|^/usr/bin/env[[:space:]]*||' -e 's|^/bin/env[[:space:]]*||' \
-e 's/[[:space:]].*//')"
if [ -z "$PY" ] || [ ! -x "$PY" ]; then
PY="$(command -v python3 || true)"
fi
[ -n "$PY" ] || { echo "ERROR: python3 not found" >&2; exit 1; }
# 3) 装修复脚本,原 vllm 改名,wrapper 顶上
install -m 0644 "$SRC_DIR/fix_tokenizer.py" "$FIXER_DEST"
mv "$VLLM_BIN" "${VLLM_BIN}_real"
sed -e "s|@@VLLM_REAL@@|${VLLM_BIN}_real|g" \
-e "s|@@FIX_PYTHON@@|${PY}|g" \
"$SRC_DIR/vllm_wrapper.sh" > "$VLLM_BIN"
chmod 0755 "$VLLM_BIN"
echo "patched: $VLLM_BIN -> ${VLLM_BIN}_real (python: $PY)"