Gemma-4-31B-it 模型部署
模型介绍
Gemma 是由 Google DeepMind 构建的一系列开源模型。Gemma 4 模型是多模态的,可处理文本和图像输入(小型模型还支持音频),并生成文本输出。上下文窗口长度为256K,支持140多种语言。同时提供稠密(Dense)架构和混合专家(MOE)架构,分为四种不同规模,E2B、E4B、26B-A4B和31B,官方模型带-it的为指令微调后的模型,不带-it的为基础模型,本文以Gemma4-31B-it-AWQ-4bit为基础模型进行部署。
通过1Panel 下载模型
硬件:Nvidia GB10 * 1;显存128G
效果:4 tokens/s (CherryStudio 测试;Nvidia GB10 128G 单卡速度为:4tokens/s)
模型权重:60G
显存消耗:模型占用60G;启动后共占用87238MiB(gpu-memory-utilization 0.7 - 最大tokens 32,768 )加上KV cache 多模态缓存估计20G+
国内环境建议使用Qwen3.6-27B模型,中文支持更友好

启动命令如下:
/opt/1panel/ai/models/gemma-4-31B-it
--served-model-name gemma-4-31B-it
--max-model-len 32768
--host 0.0.0.0
--port 8000
--tensor-parallel-size 1
--gpu-memory-utilization 0.7
--enable-prefix-caching
--enable-chunked-prefill
--enable-auto-tool-choice
--reasoning-parser gemma4
--tool-call-parser gemma4
--kv-cache-dtype fp8
--mm-processor-cache-type shm
--limit-mm-per-prompt.video 0
--async-scheduling需要编辑一下docker-compose.yml文件内容,添加挂载映射:
networks:
1panel-network:
external: true
services:
gemma-4-31b-it:
command: ${START_COMMAND}
container_name: ${CONTAINER_NAME}
deploy:
resources:
limits:
cpus: ${CPUS}
memory: ${MEMORY_LIMIT}
reservations:
devices:
- capabilities:
- gpu
count: all
driver: nvidia
environment:
HF_ENDPOINT: https://hf-mirror.com
image: ${IMAGE}
ipc: host
networks:
- 1panel-network
ports:
- ${HOST_IP}:${PANEL_APP_PORT_HTTP}:8000
restart: unless-stopped
runtime: nvidia
volumes:
- ./cache/huggingface:/root/.cache/huggingface
- ${MODEL_DIR}/:/models/${MODEL_NAME}
// [!code focus]
- /opt/1panel/ai/models:/opt/1panel/ai/models
通过单并发测试吞吐量
发现token每秒只有4个左右,在使用上体验非常差,需要等很久才能回复一个问题

优化模型思路,可能上下文太大导致缓存和内存压力过大
由原来的32,768最大上下文降低到8192,修改gpu-memory-utilization 值由原来的的0.7上调到0.85,然后重新测试,看下吞吐量是否提高;
可以看到,调整了参数还是只有4token/s,瓶颈基本确定是 31B BF16 权重在 GB10 统一内存上的 decode 带宽瓶颈。

调整之后的显存占用如下:

实测下来的话,在问答情况下, 回复速度较慢,体验欠佳。估计起码需要要200G 显存才能做到10token/s 的效果,目前有结果显示:8*5090 GPU 32 GB * 8 ,部署的这个 google/gemma-4-31B-it 的回复效果还不错。