Agent Skills › ninehills/colab-unlimited-svg › colab-unlimited-svg

colab-unlimited-svg

GitHub

将百度Unlimited-SVG图像转SVG模型部署至Google Colab GPU会话,提供FastAPI后端、Web UI及自动保活机制。用于服务的部署、更新、恢复与验证,支持云端隧道暴露。

Trigger Scenarios

在Colab上部署Unlimited-SVG服务 更新或恢复Colab中的SVG模型服务 验证Colab上的Unlimited-SVG运行状态

Install

npx skills add ninehills/colab-unlimited-svg --skill colab-unlimited-svg -g -y
More Options

Use without installing

npx skills use ninehills/colab-unlimited-svg@colab-unlimited-svg

指定 Agent (Claude Code)

npx skills add ninehills/colab-unlimited-svg --skill colab-unlimited-svg -a claude-code -g -y

安装 repo 全部 skill

npx skills add ninehills/colab-unlimited-svg --all -g -y

预览 repo 内 skill

npx skills add ninehills/colab-unlimited-svg --list

SKILL.md

Frontmatter
{
    "name": "colab-unlimited-svg",
    "description": "Deploy and operate baidu\/Unlimited-SVG (Image-to-SVG) on a pre-existing Google Colab GPU session (L4\/A100) via google-colab-cli, including Google Drive model weight persistence, a server-side access-code gated FastAPI + vLLM backend with real-time SSE\/polling partial-SVG streaming, a studio Web UI with live animated cursor drawing and replay, Cloudflare Quick Tunnel public exposure, and local macOS three-layer zero-SSH keepalive. Use when the user asks to deploy, update, recover, or verify an Unlimited-SVG service on Colab. Not for Text-to-SVG models or general unrelated Colab workloads (use the colab skill or google-colab-cli directly)."
}

Colab Unlimited-SVG 部署与运维 Skill

本 skill 将 baidu/Unlimited-SVG(基于 DeepSeek-OCR MoE 架构的 Image-to-SVG 模型)封装为可在任意预建 Google Colab GPU 会话(推荐 L4 24GB 或 A100)上复用的端到端部署与运维流程。

相关参考文档:

目录布局

路径 用途
./scripts/deploy.sh 本地参数化部署编排器(支持 full / app-only / restart / status / stop 与 --dry-run)
./scripts/keepalive.py 零 SSH 三层保活脚本(Token 原子续期 + TFE keep-alive + 静默 Kernel 心跳)
./scripts/install_launchd.sh 安装并加载 macOS 10 分钟定时保活 LaunchAgent(支持 --dry-run)
./scripts/uninstall_launchd.sh 卸载并移除指定会话的 LaunchAgent
./scripts/status_keepalive.sh 查看 LaunchAgent 加载状态与最近保活日志
./assets/backend/ 远端后端与运维资产:server.py、svg_utils.py、samples.py、restore_weights.py、bootstrap_env.sh、start_services.sh、stop_services.sh、smoke_test.py、requirements.txt
./assets/frontend/ 零构建、零外部 CDN 静态前端:index.html、css/studio.css 及 js/(含实时光标绘制引擎 draw-animator.js、SSE/轮询看门狗与重播/描摹底稿)

前置条件与操作红线

执行前须先确认以下条件满足:

  1. 本地 google-colab-cli 已完成 OAuth2 授权:通过 colab --auth=oauth2 whoami 与 colab --auth=oauth2 sessions 核对目标会话在线。
  2. 预建 GPU 会话并已挂载 Google Drive:目标会话(如 l4)须由人工预先创建并完成 /content/drive/MyDrive 挂载(colab drivemount 需要交互式终端授权,不可在无交互代理中直接调用),且 Drive 剩余空间 ≥ 10 GiB。
  3. 遵守 Colab 共享会话红线:
    • 统一使用默认 colab --auth=oauth2 配置,严禁传入 --config。
    • 严禁调用 colab new、colab run、colab stop、colab drivemount、colab auth 或裸 colab ssh。
    • 全部远端操作均通过 ./scripts/deploy.sh 的隔离式 SSH(ControlMaster=no、ControlPath=none、root@<session>-isolated)单次批量下发,禁止并发开启多条 SSH 连接(规避 HTTP 429)。
  4. 访问码安全要求:严禁在前端源码或仓库文件中硬编码真实访问码;./assets/backend/server.py 与 ./assets/backend/start_services.sh 在 ACCESS_CODE 未设置或为空时会直接拒绝启动。

必需输入(执行前向用户确认)

参数 是否必需 默认值 / 说明
--session <name> 必需 预建且已挂载 Drive 的 Colab 会话名
--access-code <YOUR_ACCESS_CODE> full/app-only/restart 必需 服务端访问码(也可通过 ACCESS_CODE 环境变量传入,服务端采用 hmac.compare_digest 校验)
--drive-model-dir <path> 可选 /content/drive/MyDrive/unlimited-svg/models/Unlimited-SVG
--local-model-dir <path> 可选 /content/models/Unlimited-SVG(推理时仅读本地 SSD,避免直读 Drive FUSE)
--vllm-port / --api-port 可选 10000 / 8000
--gpu-mem-util 可选 0.8(L4 24GB 实测占用约 18.6 GiB)

标准操作流程

以下命令均以本 skill 根目录(<skill_dir>)为工作目录执行。

1. 全量首次部署(--mode full)

先执行 --dry-run 校验参数与同步计划(不发起 SSH),确认无误后再触发远端后台安装与启动:

# 1) 本地干跑预检
./scripts/deploy.sh --session <session> --access-code "<YOUR_ACCESS_CODE>" --mode full --dry-run

# 2) 同步前后端并在远端后台 nohup 执行 bootstrap_env.sh + start_services.sh
ACCESS_CODE="<YOUR_ACCESS_CODE>" ./scripts/deploy.sh --session <session> --mode full

full 模式会自动完成:克隆 baidu/Unlimited-SVG、构建 .venv-svg-vllm(含 ninja 及 deepseek_ocr.py 2048×2048 补丁)、构建 .venv-backend、安装 cloudflared、调用 ./assets/backend/restore_weights.py(优先校验 Drive 清单恢复至本地 SSD;Drive 不存在时从 Hugging Face 下载并以 .tmp + os.replace + sync 原子持久化至 Drive),随后拉起 vLLM、FastAPI 与 Cloudflare Quick Tunnel。

按合理间隔(如 30~60 秒)执行单次只读巡检,直至 vllm、backend、cloudflared 均为 alive=yes、/api/health 返回 "ready":true 并输出公网 https://<random>.trycloudflare.com 地址:

./scripts/deploy.sh --session <session> --mode status

2. 零停机更新前后端(--mode app-only)

仅修改 ./assets/backend/ 或 ./assets/frontend/ 后,使用 app-only 模式同步代码并仅重启 FastAPI/Uvicorn,保留热态 vLLM(免重新加载模型)与现有 Cloudflare Quick Tunnel 公网域名不变:

ACCESS_CODE="<YOUR_ACCESS_CODE>" ./scripts/deploy.sh --session <session> --mode app-only

3. 会话回收后的冷启动恢复

当 Colab 运行时到达 12~24 小时绝对上限被回收后:

  1. 重建同名 GPU 会话 <session> 并人工完成 /content/drive/MyDrive 挂载。
  2. 重新执行 ACCESS_CODE="<YOUR_ACCESS_CODE>" ./scripts/deploy.sh --session <session> --mode full。
  3. ./assets/backend/restore_weights.py 会自动校验 Drive 中 manifest.json 并将全部 19 个权重文件直接恢复至 /content/models/Unlimited-SVG,无需再次从 Hugging Face 下载。
  4. 本地保活脚本会在下次周期自动识别新 endpoint(只要会话名仍为 <session>)。

4. 停止或全量重启远端服务

仅停止远端应用进程(cloudflared -> backend -> vllm),不会销毁 Colab 虚拟机:

./scripts/deploy.sh --session <session> --mode stop
ACCESS_CODE="<YOUR_ACCESS_CODE>" ./scripts/deploy.sh --session <session> --mode restart

5. 配置本地三层自动保活(macOS LaunchAgent,零 SSH)

保活脚本采用三层无干扰架构,直接复用 $HOME/.local/share/uv/tools/google-colab-cli/bin/python(可通过 COLAB_CLI_PYTHON 覆盖),不占用 SSH 隧道、不触发 prune_session:

# 1) 单次手动验证(期望输出:<session> tfe=200 kernel=ok 或 kernel=busy_skip)
"$HOME/.local/share/uv/tools/google-colab-cli/bin/python" ./scripts/keepalive.py --session <session>

# 2) 预览生成的 plist 与命令(不改动 ~/Library/LaunchAgents)
./scripts/install_launchd.sh --dry-run <session>

# 3) 安装并激活每 600 秒执行的 LaunchAgent(RunAtLoad=true,WorkingDirectory=$HOME)
./scripts/install_launchd.sh <session>

# 4) 检查 LaunchAgent 加载状态、退出码与最近保活日志
./scripts/status_keepalive.sh <session>

# 需要停用保活时卸载:
./scripts/uninstall_launchd.sh <session>

日志默认写入 $HOME/.cache/colab-keepalive-<session>/keepalive.log(1 MiB 自动轮转)及 launchd.stderr.log,将运行目录与 stderr 置于 $HOME / ~/.cache 下可规避 macOS xpcproxy 对 ~/Library/CloudStorage 的 EPERM / EX_CONFIG 限制。

验证清单(交付前逐项核对)

获取公网地址 PUBLIC_URL="https://<random>.trycloudflare.com" 后依次验证:

  1. 健康检查与鉴权拦截(curl):
    • curl -sf "$PUBLIC_URL/api/health" 返回 200 且 "ready":true。
    • 未携带 X-Access-Code 或携带错误访问码请求 GET /api/status、POST /api/jobs、GET /api/jobs/probe/stream 均返回 HTTP 401。
    • 携带正确访问码请求 POST /api/auth/verify、GET /api/status、GET /api/samples 返回 200。
  2. 增量 SSE 流与轮询回退:
    • 执行冒烟测试(可在远端或本地指向公网地址): ACCESS_CODE="<YOUR_ACCESS_CODE>" python3 ./assets/backend/smoke_test.py --base-url "$PUBLIC_URL"
    • 确认 GET /api/jobs/{id}/stream 返回 200 text/event-stream 并连续输出有效清洗后 partial <svg> 帧直至 completed,同时 GET /api/jobs/{id}?include_partial=1 返回实时增量 partial_svg。
  3. 浏览器端到端检查:
    • 打开 $PUBLIC_URL:访问码拦截页拦截错误口令,输入 <YOUR_ACCESS_CODE> 后解锁工作台且状态徽章显示就绪。
    • 选择内置示例图或上传图片发起生成:确认推理中途即出现单行悬浮 HUD(实时绘制中)与矢量光标沿路径逐元素描边绘制,生成完成后平滑收敛至最终 SVG(无残留隐藏元素,零控制台/网络错误)。
    • 验证「重播绘制」(1× / 2× / 4×、跳过动画)、「描摹底稿」开关、并排对比视图、XML 源码查看、.svg 与 .png 导出、生成中取消任务及「锁定 / 退出访问」清除凭据。
  4. 权重落盘与保活确认:
    • ./scripts/deploy.sh --session <session> --mode status 确认 Drive 目录存在完整 manifest.json 与 19 个权重文件。
    • ./scripts/status_keepalive.sh <session> 确认 Loaded: yes、run interval = 600 seconds、last exit code = 0、stderr 为空且日志包含 tfe=200 kernel=ok(或 busy_skip)。

Version History

  • 77d1036 Current 2026-12-02 14:05

Metadata

Files
0
Version
77d1036
Hash
c61a5825
Indexed
2026-12-02 14:05

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-12-03 02:56
浙ICP备14020137号-1