使用 SGLang 镜像部署
构建一个包含 SGLang 运行时和 Valen 插件的 Docker 镜像,用一张 GPU 提供 HTTP 服务。
镜像基于官方 SGLang 0.5.23 运行环境(lmsysorg/sglang:v0.5.23)构建,包含服务运行环境,模型权重在首次启动时下载。想把插件装进已有的 SGLang 环境,见插件部署。
开始之前
- Linux x86-64、支持 FA3 的 NVIDIA GPU和兼容的 CUDA 驱动。
- 安装了 Buildx 和 NVIDIA Container Toolkit 的 Docker。
- 用于构建镜像的 Valen 源码。
构建镜像
在 Valen 仓库根目录构建 valen-sglang:0.1.0-dev3:
终端
docker buildx build --platform linux/amd64 --load \
-t valen-sglang:0.1.0-dev3 \
-f serving/sglang/docker/Dockerfile .
启动服务
启动容器后等待模型加载完成。示例将 Hugging Face 缓存挂载到宿主机,后续启动可复用权重。
终端
docker run --rm --gpus device=0 --ipc=host \
-p 127.0.0.1:30000:30000 \
-v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
valen-sglang:0.1.0-dev3 \
--model-path Valen-Team/Valen-Decision-1.5-2B \
--served-model-name valen \
--dtype bfloat16 \
--host 0.0.0.0 --port 30000
| 参数 | 默认示例 | 用途 |
|---|---|---|
--model-path | Valen-Team/Valen-Decision-1.5-2B | Hub 模型名或完整模型目录 |
--served-model-name | valen | 请求中的模型名 |
--dtype | bfloat16 | 以 BF16 加载骨干网络,即发布权重的运行精度。不加时骨干可能按 FP32 加载,显存占用翻倍;Valen-Decision-1.5-27B 的 BF16 权重约 54 GB |
| 端口映射 | 127.0.0.1:30000:30000 | 从本机访问服务 |
发送请求
选择 SystemOne 或 Decisions 发送文本请求:
| 协议 | 请求结构 | 示例中的命题概率 |
|---|---|---|
| SystemOne | state + 按 ID 索引的 questions | answers.on_sofa.noul |
| Decisions | input + 问题列表 | answers[0].probability |
请求中的 model 必须与启动时配置的模型名一致。temperature 默认为 1.0,必须是大于零的有限数值。
- Decisions
- SystemOne
终端
curl http://127.0.0.1:30000/v1/decisions \
-H 'Content-Type: application/json' \
-d '{
"model": "valen",
"input": "A cat is on the sofa.",
"questions": [
{
"name": "on_sofa",
"type": "predicate",
"instructions": "The cat is on the sofa."
}
],
"temperature": 1
}'
终端
curl http://127.0.0.1:30000/v1/systemone \
-H 'Content-Type: application/json' \
-d '{
"model": "valen",
"state": "A cat is on the sofa.",
"questions": {
"on_sofa": {
"type": "noul",
"instructions": "The cat is on the sofa."
}
},
"temperature": 1
}'
发送图片请求
在客户端运行 python -m pip install requests,将示例中的 cat.jpg 替换为本地 PNG、JPEG 或 WebP 图片。Python 示例会读取图片,按文件名识别 MIME 类型,并编码为 data URL。
SystemOne 使用 state.messages 中的 image_url 内容块;Decisions 使用 input 中的 input_image 内容块。请求中的模型名均为 valen。
- Decisions
- SystemOne
Python
import base64
import mimetypes
from pathlib import Path
import requests
image_path = Path("cat.jpg")
mime_type = mimetypes.guess_type(image_path.name)[0]
image_b64 = base64.b64encode(image_path.read_bytes()).decode("ascii")
image_url = f"data:{mime_type};base64,{image_b64}"
response = requests.post(
"http://127.0.0.1:30000/v1/decisions",
json={
"model": "valen",
"input": [
{
"role": "user",
"content": [
{
"type": "input_image",
"image_url": image_url
},
{
"type": "input_text",
"text": "Inspect this image."
}
]
}
],
"questions": [
{
"name": "animal",
"type": "choice",
"instructions": "Which animal is visible?",
"choices": [
{
"value": "cat",
"description": "A cat"
},
{
"value": "dog",
"description": "A dog"
}
]
}
],
"temperature": 1
},
timeout=120,
)
response.raise_for_status()
print(response.json()["answers"])
Python
import base64
import mimetypes
from pathlib import Path
import requests
image_path = Path("cat.jpg")
mime_type = mimetypes.guess_type(image_path.name)[0]
image_b64 = base64.b64encode(image_path.read_bytes()).decode("ascii")
image_url = f"data:{mime_type};base64,{image_b64}"
response = requests.post(
"http://127.0.0.1:30000/v1/systemone",
json={
"model": "valen",
"state": {
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": image_url
}
},
{
"type": "text",
"text": "Inspect this image."
}
]
}
]
},
"questions": {
"animal": {
"type": "choice",
"instructions": "Which animal is visible?",
"criteria": {
"cat": "A cat",
"dog": "A dog"
}
}
},
"temperature": 1
},
timeout=120,
)
response.raise_for_status()
print(response.json()["answers"])
支持范围
- 检查点: 完整 Valen Qwen3.5 Mixer 检查点,
shared_state执行,单 GPU,TP=PP=1。 - 问题类型: 支持文本和图片的判断、选择与评分:Choice 为 1–255 个候选,Score 为 2–255 个有序等级。Valen-Decision-1.5 检查点还支持 bbox 定位题,在一张输入图片中定位所描述的对象。
- 视频: 先提取画面帧,再作为图片输入。
- 与原生模型一致: 在 Valen-Decision-1.5 0.8B 和 2B 上,服务返回的结果与原生模型的差异不超过 0.02。
问题与答案结构见 SystemOne 和 Decisions。