> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/llama33.md).

# Llama 3.3 70B

在 Clore.ai GPU 上运行 Meta 的 Llama 3.3 70B 模型

{% hint style="info" %}
**有更新版本可用！** Meta 已发布 [**Llama 4**](/guides/guides_v2-zh/yu-yan-mo-xing/llama4.md) 于 2025 年 4 月发布，采用 MoE 架构——Scout（17B 激活参数，可在 RTX 4090 上运行）在仅需极少显存的情况下提供相近的质量。建议升级。
{% endhint %}

Meta 在 CLORE.AI GPU 上最新且最高效的 70B 模型。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 为什么选择 Llama 3.3？

* **最佳 70B 模型** - 以极低成本匹配 Llama 3.1 405B 的性能
* **多语言** - 原生支持 8 种语言
* **128K 上下文** - 长文档处理
* **开源权重** - 可免费用于商业用途

## 模型概览

| 规格    | 数值                             |
| ----- | ------------------------------ |
| 参数    | 70B                            |
| 上下文长度 | 128K 令牌                        |
| 训练数据  | 15T+ 令牌                        |
| 语言    | EN, DE, FR, IT, PT, HI, ES, TH |
| 许可证   | Llama 3.3 社区许可协议               |

### 性能与其他模型对比

| 基准        | Llama 3.3 70B | Llama 3.1 405B | GPT-4o |
| --------- | ------------- | -------------- | ------ |
| MMLU      | 86.0          | 87.3           | 88.7   |
| HumanEval | 88.4          | 89.0           | 90.2   |
| MATH      | 77.0          | 73.8           | 76.6   |
| 多语言       | 91.1          | 91.6           | -      |

## GPU 要求

{% hint style="warning" %}
**Clore.ai 市场上未列出多 GPU 的 80GB 级机型。** 目前列出的最大配置是 4× RTX PRO 6000 Blackwell（每张 96GB，共 380GB）以及 8–11× RTX 5090（每张 32GB）。A100 / H200 / B200 容量可按 [裸机](https://clore.ai/bare-metal) 需求提供。部署前请查看 [GPU 价格与可用性](/guides/guides_v2-zh/ru-men-zhi-nan/pricing.md) 。
{% endhint %}

| 配置       | 显存    | 性能 | 成本                                               |
| -------- | ----- | -- | ------------------------------------------------ |
| Q4 量化    | 40GB  | 好  | A100 40GB（[裸机](https://clore.ai/bare-metal))     |
| Q8 量化    | 70GB  | 更好 | A100 80GB（[裸机](https://clore.ai/bare-metal))     |
| FP16 全精度 | 140GB | 最佳 | 2x A100 80GB ([裸机](https://clore.ai/bare-metal)) |

**推荐：** 使用带 Q4 量化的 A100 40GB，以获得最佳性价比。

## 在 CLORE.AI 上快速部署

### 使用 Ollama（最简单）

**Docker 镜像：**

```
ollama/ollama
```

**端口：**

```
22/tcp
11434/http
```

**部署后：**

```bash
ollama pull llama3.3
ollama run llama3.3
```

### 使用 vLLM（生产环境）

**Docker 镜像：**

```
vllm/vllm-openai:latest
```

**端口：**

```
22/tcp
8000/http
```

**命令：**

```bash
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.3-70B-Instruct \
    --tensor-parallel-size 1 \\
    --max-model-len 32768 \\
    --host 0.0.0.0
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 安装方法

### 方法 1：Ollama（推荐用于测试）

```bash
# 安装 Ollama
curl -fsSL https://ollama.com/install.sh | sh

# 拉取 Llama 3.3（自动下载 Q4 版本）
ollama pull llama3.3

# 交互式运行
ollama run llama3.3

# 或提供 API 服务
ollama serve
```

**API 用法：**

```bash
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.3",
  "prompt": "用简单的话解释量子计算"
}'
```

### 方法 2：vLLM（生产环境）

```bash
pip install vllm

# 单 GPU（带 AWQ 量化的 A100 40GB）
python -m vllm.entrypoints.openai.api_server \
    --model casperhansen/llama-3.3-70b-instruct-awq \
    --quantization awq \
    --max-model-len 16384 \\
    --host 0.0.0.0

# 多 GPU（2x A100，用于全精度）
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.3-70B-Instruct \
    --tensor-parallel-size 2 \\
    --max-model-len 32768 \\
    --host 0.0.0.0
```

**API 用法（与 OpenAI 兼容）：**

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")

response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "编写一个用于计算斐波那契数列的 Python 函数"}
    ],
    temperature=0.7,
    max_tokens=1024
)

print(response.choices[0].message.content)
```

### 方法 3：Transformers + bitsandbytes

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

# 4 位量化配置
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16
)

model_id = "meta-llama/Llama-3.3-70B-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto"
)

# 生成
messages = [
    {"role": "system", "content": "你是一个乐于助人的代码助手。"},
    {"role": "user", "content": "编写一个使用 BeautifulSoup 的 Python 网页爬虫"}
]

input_ids = tokenizer.apply_chat_template(
    messages,
    return_tensors="pt"
).to("cuda")

outputs = model.generate(
    input_ids,
    max_new_tokens=512,
    temperature=0.7,
    do_sample=True
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

### 方法 4：llama.cpp（CPU+GPU 混合）

```bash
# 克隆并构建
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make LLAMA_CUDA=1

# 下载 GGUF 模型
wget https://huggingface.co/bartowski/Llama-3.3-70B-Instruct-GGUF/resolve/main/Llama-3.3-70B-Instruct-Q4_K_M.gguf

# 运行服务器
./llama-server \\
    -m Llama-3.3-70B-Instruct-Q4_K_M.gguf \
    -c 8192 \
    -ngl 80 \
    --host 0.0.0.0 \\
    --port 8080
```

## 基准

### 吞吐量（令牌/秒）

| GPU          | Q4    | Q8    | FP16  |
| ------------ | ----- | ----- | ----- |
| A100 40GB    | 25-30 | -     | -     |
| A100 80GB    | 35-40 | 25-30 | -     |
| 2x A100 80GB | 50-60 | 40-45 | 30-35 |
| H100 80GB    | 60-70 | 45-50 | 35-40 |

### 首个 token 时间（TTFT）

| GPU          | Q4        | FP16      |
| ------------ | --------- | --------- |
| A100 40GB    | 0.8-1.2 秒 | -         |
| A100 80GB    | 0.6-0.9 秒 | -         |
| 2x A100 80GB | 0.4-0.6 秒 | 0.8-1.0 秒 |

### 上下文长度与显存占用

| 上下文  | Q4 显存 | Q8 显存 |
| ---- | ----- | ----- |
| 4K   | 38GB  | 72GB  |
| 8K   | 40GB  | 75GB  |
| 16K  | 44GB  | 80GB  |
| 32K  | 52GB  | 90GB  |
| 64K  | 68GB  | 110GB |
| 128K | 100GB | 150GB |

## 应用场景

### 代码生成

```python
messages = [
    {"role": "system", "content": "你是一名专家程序员。请编写简洁、高效、文档完善的代码。"},
    {"role": "user", "content": "使用 JWT 令牌在 FastAPI 中创建一个带用户身份验证的 REST API"}
]
```

### 文档分析（长上下文）

```python
# 加载长文档
with open("large_document.txt") as f:
    document = f.read()

messages = [
    {"role": "system", "content": "你是一名文档分析师。请提供详细、准确的分析。"},
    {"role": "user", "content": f"分析这份文档，并提供包含要点的摘要：\n\n{document}"}
]
```

### 多语言任务

```python
messages = [
    {"role": "system", "content": "你是一名多语言助手。"},
    {"role": "user", "content": "将这句话翻译成德语、法语和西班牙语：'The quick brown fox jumps over the lazy dog'"}
]
```

### 推理与分析

```python
messages = [
    {"role": "system", "content": "逐步思考。展示你的推理过程。"},
    {"role": "user", "content": "一列火车于上午 9:00 从 A 站出发，时速 60 英里。另一列火车于上午 10:00 从 B 站出发（相距 300 英里），朝 A 站方向行驶，时速 90 英里。它们何时何地相遇？"}
]
```

## 优化提示

### 内存优化

```python
# 使用内存优化的 vLLM
python -m vllm.entrypoints.openai.api_server \
    --model casperhansen/llama-3.3-70b-instruct-awq \
    --quantization awq \
    --gpu-memory-utilization 0.95 \
    --max-model-len 8192
```

### 速度优化

```python
# 启用 Flash Attention
python -m vllm.entrypoints.openai.api_server \
    --model meta-llama/Llama-3.3-70B-Instruct \
    --tensor-parallel-size 2 \\
    --enable-prefix-caching
```

### 批量处理

```python
# 高效处理多个请求
responses = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct",
    messages=messages,
    n=4,  # 生成 4 个回复
    temperature=0.8
)
```

## 与其他模型对比

| 功能   | Llama 3.3 70B | Llama 3.1 70B | Qwen 2.5 72B | Mixtral 8x22B |
| ---- | ------------- | ------------- | ------------ | ------------- |
| MMLU | 86.0          | 83.6          | 85.3         | 77.8          |
| 编程   | 88.4          | 80.5          | 85.4         | 75.5          |
| 数学   | 77.0          | 68.0          | 80.0         | 60.0          |
| 上下文  | 128K          | 128K          | 128K         | 64K           |
| 语言   | 8             | 8             | 29           | 8             |
| 许可证  | 打开            | 打开            | 打开           | 打开            |

**结论：** Llama 3.3 70B 在同类模型中提供了最佳的整体性能，尤其适合编程和推理任务。

## 故障排查

### 内存不足

```bash
# 使用 AWQ 量化（最节省显存）
--model casperhansen/llama-3.3-70b-instruct-awq --quantization awq

# 缩短上下文长度
--max-model-len 8192

# 使用张量并行
--tensor-parallel-size 2
```

### 首次响应较慢

* 第一次请求会将模型加载到 GPU——需等待 30-60 秒
* 使用 `--enable-prefix-caching` 用于后续更快的请求
* 使用空请求预热

### Hugging Face 访问

```bash
# 登录 HF（门控模型所需）
huggingface-cli login

# 或设置环境变量
export HUGGING_FACE_HUB_TOKEN=hf_xxxxx
```

## 成本估算

| 配置  | GPU           | 美元/小时   | 令牌/美元  |
| --- | ------------- | ------- | ------ |
| 预算  | A100 40GB（Q4） | \~$0.17 | \~530K |
| 均衡  | A100 80GB（Q4） | \~$0.25 | \~500K |
| 性能  | 2x A100 80GB  | \~$0.50 | \~360K |
| 最大值 | H100 80GB     | \~$0.50 | \~500K |

## 下一步

* [vLLM 指南](/guides/guides_v2-zh/yu-yan-mo-xing/vllm.md) - 生产部署
* [Ollama 指南](/guides/guides_v2-zh/yu-yan-mo-xing/ollama.md) - 易于本地部署
* [多 GPU 设置](/guides/guides_v2-zh/gao-ji/multi-gpu-setup.md) - 扩展到更大的模型
* [API 集成](/guides/guides_v2-zh/gao-ji/api-integration.md) - 构建应用程序


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/llama33.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
