# Llama 3.3 70B

{% hint style="info" %}
**有可用的更新版本！** Meta 发布了 [**Llama 4**](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/llama4) 于 2025 年 4 月采用 MoE 架构发布 — Scout（17B 活跃，可在 RTX 4090 上运行）以极小的显存提供类似质量。考虑升级。
{% endhint %}

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

{% 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   |
| 数学        | 77.0          | 73.8           | 76.6   |
| 多语言       | 91.1          | 91.6           | -      |

## GPU 要求

| 设置       | 显存    | background = Image.open("studio\_bg.jpg") | 成本                       |
| -------- | ----- | ----------------------------------------- | ------------------------ |
| Q4 量化    | 40GB  | 良好                                        | A100 40GB（约 $0.17/小时）    |
| Q8 量化    | 70GB  | 更好                                        | A100 80GB（约 $0.25/小时）    |
| FP16 全精度 | 140GB | 最佳                                        | 2x A100 80GB（约 $0.50/小时） |

**推荐：** 使用 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（A100 40GB，使用 AWQ 量化）
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  |
| ------------ | ----- | ----- | ----- |
| 按日费率         | 25-30 | -     | -     |
| 4 小时会话       | 35-40 | 25-30 | -     |
| 2x A100 80GB | 50-60 | 40-45 | 30-35 |
| H100 80GB    | 60-70 | 45-50 | 35-40 |

### 首个标记时间（TTFT）

| GPU          | Q4        | FP16      |
| ------------ | --------- | --------- |
| 按日费率         | 0.8-1.2 秒 | -         |
| 4 小时会话       | 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": "使用 FastAPI 创建一个带有 JWT 令牌用户认证的 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 从距离 300 英里的车站 B 出发，朝 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 |
| background = Image.open("studio\_bg.jpg") | 2x A100 80GB  | \~$0.50 | \~360K |
| 最大值                                       | H100 80GB     | \~$0.50 | \~500K |

## 使用以下方式支付

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


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
