[ PROMPT_NODE_22508 ]
Infrastructure Skypilot 高级用法
[ SKILL_DOCUMENTATION ]
# SkyPilot 高级用法指南
## 多云策略
### 云选择模式
yaml
# 按顺序优先选择特定云
resources:
accelerators: A100:8
any_of:
- cloud: gcp
region: us-central1
- cloud: aws
region: us-west-2
- cloud: azure
region: westus2
### 通配符区域
yaml
resources:
cloud: aws
region: us-* # 任何美国区域
accelerators: A100:8
### Kubernetes + 云回退
yaml
resources:
accelerators: A100:8
any_of:
- cloud: kubernetes
- cloud: aws
- cloud: gcp
## 高级资源配置
### 实例类型约束
yaml
resources:
instance_type: p4d.24xlarge # 特定实例
# 或者
cpus: 32+
memory: 128+
accelerators: A100:8
### 磁盘配置
yaml
resources:
disk_size: 500 # GB
disk_tier: best # low, medium, high, ultra, best
### 网络层级
yaml
resources:
network_tier: best # 高性能网络
## 生产环境托管作业
### 作业配置
yaml
name: production-training
resources:
accelerators: H100:8
use_spot: true
spot_recovery: FAILOVER
# 重试配置
max_restarts_on_errors: 3
### 控制器扩缩容
对于大规模部署(数百个作业):
bash
# 增加控制器内存
sky jobs launch --controller-resources memory=32
### 静态凭据
为控制器使用不过期的凭据:
bash
# AWS: 使用 IAM 角色或长期访问密钥
# GCP: 使用服务账号 JSON 密钥
# Azure: 使用服务主体
## 高级文件挂载
### Git 仓库工作目录
yaml
workdir:
url: https://github.com/user/repo.git
ref: main
# 对于私有仓库,设置 GIT_TOKEN 环境变量
### 多存储后端
yaml
file_mounts:
/data/s3:
source: s3://my-bucket/data
mode: MOUNT
/data/gcs:
source: gs://my-bucket/data
mode: MOUNT
/outputs:
name: training-outputs
store: s3
mode: MOUNT_CACHED
### Rsync 排除模式
yaml
workdir: .
# 使用 .skyignore 或 .gitignore 进行排除
创建 `.skyignore`:
__pycache__/
*.pyc
.git/
.env
node_modules/
## 分布式训练模式
### PyTorch DDP
yaml
num_nodes: 4
resources:
accelerators: A100:8
run: |
torchrun
--nnodes=$SKYPILOT_NUM_NODES
--nproc_per_node=$SKYPILOT_NUM_GPUS_PER_NODE
--node_rank=$SKYPILOT_NODE_RANK
--master_addr=$(echo "$SKYPILOT_NODE_IPS" | head -n1)
--master_port=12355