GLM-4.7-Flash
在 Clore.ai 上部署 Zhipu AI 的 GLM-4.7-Flash(30B MoE)——高效语言模型,SWE-bench 表现达 59.2%
最后更新于
这有帮助吗?
这有帮助吗?
pip install vllm>=0.6.0
# 或 最新版本
pip install git+https://github.com/vllm-project/vllm.gitvllm serve THUDM/glm-4-flash \
--model THUDM/glm-4-flash \
--tensor-parallel-size 1 \
--dtype float16 \
--max-model-len 32768 \
--served-model-name glm-4.7-flash \
--trust-remote-codefrom openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="EMPTY"
)
response = client.chat.completions.create(
model="glm-4.7-flash",
messages=[
{"role": "system", "content": "你是一名资深 Python 开发者。"},
{"role": "user", "content": "编写一个使用异步 SQLAlchemy 和 JWT 认证的 FastAPI 应用"}
],
max_tokens=2048,
temperature=0.7
)
print(response.choices[0].message.content)pip install "sglang[all]>=0.3.0"
# 启动服务器
python -m sglang.launch_server \
--model-path THUDM/glm-4-flash \
--port 30000 \
--host 0.0.0.0 \
--dtype float16 \
--tp-size 1 \
--context-length 32768# 安装 Ollama
curl -fsSL https://ollama.com/install.sh | sh
# 拉取模型(将下载约 18GB)
ollama pull glm4:7b-chat
# 交互运行
ollama run glm4:7b-chat
# API 模式
ollama serveimport requests
response = requests.post('http://localhost:11434/api/generate',
json={
'model': 'glm4:7b-chat',
'prompt': '解释 GLM-4.7-Flash 中的 MoE 架构',
'stream': False
}
)
print(response.json()['response'])FROM nvidia/cuda:12.1-devel-ubuntu22.04
# 安装 Python 3.10
RUN apt-get update && apt-get install -y python3.10 python3-pip curl
# 安装 vLLM
RUN pip install vllm>=0.6.0 transformers
# 预下载模型(可选)
# RUN python3 -c "from transformers import AutoModel; AutoModel.from_pretrained('THUDM/glm-4-flash', trust_remote_code=True)"
EXPOSE 8000
CMD ["vllm", "serve", "THUDM/glm-4-flash", \
"--host", "0.0.0.0", \
"--port", "8000", \
"--tensor-parallel-size", "1", \
"--dtype", "float16", \
"--trust-remote-code"]docker build -t glm-4.7-flash .
docker run --gpus all -p 8000:8000 glm-4.7-flashfrom openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
response = client.chat.completions.create(
model="glm-4.7-flash",
messages=[
{"role": "user",
"content": """为速率限制器创建一个 Python 类,要求:
- 令牌桶算法
- 支持 async/await
- Redis 后端
- 用于函数速率限制的装饰器
- 适当的错误处理"""}
],
max_tokens=2048,
temperature=0.3
)
print(response.choices[0].message.content)