> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 安装与设置

> 准备使用 AITraining CLI

# 安装与设置

安装 `aitraining` 包时会包含 AITraining CLI。

## 安装

### 使用 pip

```bash theme={null}
pip install aitraining torch torchvision torchaudio
```

### 使用 uv（推荐）

```bash theme={null}
uv pip install aitraining torch torchvision torchaudio
```

## 验证安装

检查 CLI 是否正常工作：

```bash theme={null}
aitraining --version
```

您应该会看到版本号。

## 首次运行

不带参数运行 `aitraining` 会启动交互式向导：

```bash theme={null}
aitraining
```

这将显示 Monostate 横幅并启动配置向导。

## GPU 设置

对于 GPU 训练，请确保已安装 CUDA 且 PyTorch 可以检测到您的 GPU：

```python theme={null}
import torch
print(torch.cuda.is_available())  # Should print True
print(torch.cuda.device_count())  # Number of GPUs
```

### Apple Silicon (M1/M2/M3)

在 Apple Silicon Mac 上，MPS 会自动使用：

```python theme={null}
import torch
print(torch.backends.mps.is_available())  # Should print True
```

## 环境变量

常见环境变量：

| 变量                     | 描述                             |
| ---------------------- | ------------------------------ |
| `HF_TOKEN`             | Hugging Face token，用于私有模型/数据集  |
| `WANDB_API_KEY`        | Weights & Biases API 密钥，用于日志记录 |
| `CUDA_VISIBLE_DEVICES` | 指定要使用的 GPU                     |

在运行训练之前设置这些变量：

```bash theme={null}
export HF_TOKEN="your_token_here"
export WANDB_API_KEY="your_key_here"
```

## 下一步

<CardGroup cols={2}>
  <Card title="命令结构" href="/cli/command-structure">
    学习 CLI 命令语法
  </Card>

  <Card title="LLM 训练" href="/cli/llm-training">
    训练语言模型
  </Card>
</CardGroup>
