日期:2026-08-14 | 分类:AI工具教程
Cerebras提供基于Wafer-Scale Engine(WSE)的超快AI推理服务,Llama-4模型推理速度达每秒2000+Token,比GPU快10-100倍。API兼容OpenAI格式。
# 1. 访问 cloud.cerebras.ai 注册
# 2. 创建API Key
# 3. 设置环境变量
export CEREBRAS_API_KEY="csk-your-key"
pip install cerebras_cloud_ai
from cerebras.cloud.sdk import Cerebras
client = Cerebras(api_key="csk-your-key")
response = client.chat.completions.create(
model="llama-4-70b-instruct",
messages=[{"role": "user", "content": "解释一下MoE架构"}],
max_tokens=1024
)
print(response.choices[0].message.content)
stream = client.chat.completions.create(
model="llama-4-70b-instruct",
messages=[{"role": "user", "content": "写一个Python Web服务器"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取天气",
"parameters": {"city": {"type": "string"}}
}
}]
response = client.chat.completions.create(
model="llama-4-70b-instruct",
messages=[{"role": "user", "content": "北京天气怎么样"}],
tools=tools
)
| 平台 | 模型 | Token/s |
|---|---|---|
| Cerebras WSE-3 | Llama-4-70B | ~2000 |
| A100 GPU | Llama-4-70B | ~150 |
| vLLM 4090 | Llama-4-70B | ~80 |
Cerebras提供基于Wafer-Scale Engine(WSE)的超快AI推理服务,Llama-4模型推理速度达每秒2000+Token,比GPU快10-100倍。API兼容OpenAI格式。
Llama-4-70B:$0.85/1M token