Lambda Labs GPU 云
用于机器学习训练和推理的预留及按需 GPU 云实例。当您需要具有简单 SSH 访问权限、持久文件系统或用于大规模训练的高性能多节点集群的专用 GPU 实例时,请使用此服务。
技能元数据
| 来源 | 可选 — 使用 hermes skills install official/mlops/lambda-labs 安装 |
| 路径 | optional-skills/mlops/lambda-labs |
| 版本 | 1.0.0 |
| 作者 | Orchestra Research |
| 许可证 | MIT |
| 依赖项 | lambda-cloud-client>=1.0.0 |
| 标签 | Infrastructure, GPU Cloud, Training, Inference, Lambda Labs |
参考:完整 SKILL.md
信息
以下是 Hermes 在触发此技能时加载的完整技能定义。这是技能激活时代理看到的指令。
Lambda Labs GPU 云
在 Lambda Labs GPU 云上使用按需实例和一键式集群(1-Click Clusters)运行机器学习工作负载的综合指南。
何时使用 Lambda Labs
在以下情况下使用 Lambda Labs:
- 需要具有完整 SSH 访问权限的专用 GPU 实例
- 运行长时间的训练任务(数小时至数天)
- 希望定价简单且无出站流量费用
- 需要在会话之间保持持久存储
- 需要高性能多节点集群(16-512 个 GPU)
- 希望使用预安装的机器学习栈(包含 PyTorch、CUDA、NCCL 的 Lambda Stack)
主要功能:
- GPU 多样性:B200、H100、GH200、A100、A10、A6000、V100
- Lambda Stack:预安装 PyTorch、TensorFlow、CUDA、cuDNN、NCCL
- 持久文件系统:在实例重启后保留数据
- 一键式集群:配备 InfiniBand 的 16-512 GPU Slurm 集群
- 简单定价:按分钟付费,无出站流量费用
- 全球区域:全球 12+ 个区域
改用其他替代方案:
- Modal:适用于无服务器、自动伸缩的工作负载
- SkyPilot:适用于多云编排和成本优化
- RunPod:适用于更便宜的竞价实例和无服务器端点
- Vast.ai:适用于价格最低的 GPU 市场
快速入门
账户设置
- 在 https://lambda.ai 创建账户
- 添加支付方式
- 从仪表板生成 API 密钥
- 添加 SSH 密钥(启动实例前必需)
通过控制台启动
- 访问 https://cloud.lambda.ai/instances
- 点击“Launch instance”(启动实例)
- 选择 GPU 类型和区域
- 选择 SSH 密钥
- (可选)附加文件系统
- 启动并等待 3-15 分钟
通过 SSH 连接
# Get instance IP from console
ssh ubuntu@<INSTANCE-IP>
# Or with specific key
ssh -i ~/.ssh/lambda_key ubuntu@<INSTANCE-IP>
GPU 实例
可用 GPU
| GPU | 显存 (VRAM) | 每 GPU 每小时价格 | 最佳用途 |
|---|---|---|---|
| B200 SXM6 | 180 GB | $4.99 | 最大模型,最快训练速度 |
| H100 SXM | 80 GB | $2.99-3.29 | 大型模型训练 |
| H100 PCIe | 80 GB | $2.49 | 高性价比 H100 |
| GH200 | 96 GB | $1.49 | 单 GPU 大型模型 |
| A100 80GB | 80 GB | $1.79 | 生产环境训练 |
| A100 40GB | 40 GB | $1.29 | 标准训练 |
| A10 | 24 GB | $0.75 | 推理,微调 |
| A6000 | 48 GB | $0.80 | 良好的显存/价格比 |
| V100 | 16 GB | $0.55 | 预算有限训练 |
实例配置
8x GPU: Best for distributed training (DDP, FSDP)
4x GPU: Large models, multi-GPU training
2x GPU: Medium workloads
1x GPU: Fine-tuning, inference, development
启动时间
- 单 GPU:3-5 分钟
- 多 GPU:10-15 分钟
Lambda Stack
所有实例均预安装了 Lambda Stack:
# Included software
- Ubuntu 22.04 LTS
- NVIDIA drivers (latest)
- CUDA 12.x
- cuDNN 8.x
- NCCL (for multi-GPU)
- PyTorch (latest)
- TensorFlow (latest)
- JAX
- JupyterLab
验证安装
# Check GPU
nvidia-smi
# Check PyTorch
python -c "import torch; print(torch.cuda.is_available())"
# Check CUDA version
nvcc --version
Python API
安装
pip install lambda-cloud-client
身份验证
import os
import lambda_cloud_client
# Configure with API key
configuration = lambda_cloud_client.Configuration(
host="https://cloud.lambdalabs.com/api/v1",
access_token=os.environ["LAMBDA_API_KEY"]
)
列出可用实例
with lambda_cloud_client.ApiClient(configuration) as api_client:
api = lambda_cloud_client.DefaultApi(api_client)
# Get available instance types
types = api.instance_types()
for name, info in types.data.items():
print(f"{name}: {info.instance_type.description}")
启动实例
from lambda_cloud_client.models import LaunchInstanceRequest
request = LaunchInstanceRequest(
region_name="us-west-1",
instance_type_name="gpu_1x_h100_sxm5",
ssh_key_names=["my-ssh-key"],
file_system_names=["my-filesystem"], # Optional
name="training-job"
)
response = api.launch_instance(request)
instance_id = response.data.instance_ids[0]
print(f"Launched: {instance_id}")
列出正在运行的实例
instances = api.list_instances()
for instance in instances.data:
print(f"{instance.name}: {instance.ip} ({instance.status})")
终止实例
from lambda_cloud_client.models import TerminateInstanceRequest
request = TerminateInstanceRequest(
instance_ids=[instance_id]
)
api.terminate_instance(request)
SSH 密钥管理
from lambda_cloud_client.models import AddSshKeyRequest
# Add SSH key
request = AddSshKeyRequest(
name="my-key",
public_key="ssh-rsa AAAA..."
)
api.add_ssh_key(request)
# List keys
keys = api.list_ssh_keys()
# Delete key
api.delete_ssh_key(key_id)
使用 curl 的 CLI
列出实例类型
curl -u $LAMBDA_API_KEY: \
https://cloud.lambdalabs.com/api/v1/instance-types | jq
启动实例
curl -u $LAMBDA_API_KEY: \
-X POST https://cloud.lambdalabs.com/api/v1/instance-operations/launch \
-H "Content-Type: application/json" \
-d '{
"region_name": "us-west-1",
"instance_type_name": "gpu_1x_h100_sxm5",
"ssh_key_names": ["my-key"]
}' | jq
终止实例
curl -u $LAMBDA_API_KEY: \
-X POST https://cloud.lambdalabs.com/api/v1/instance-operations/terminate \
-H "Content-Type: application/json" \
-d '{"instance_ids": ["<INSTANCE-ID>"]}' | jq
持久存储
文件系统
文件系统在实例重启后保留数据:
# Mount location
/lambda/nfs/<FILESYSTEM_NAME>
# Example: save checkpoints
python train.py --checkpoint-dir /lambda/nfs/my-storage/checkpoints
创建文件系统
- 在 Lambda 控制台中进入 Storage(存储)
- 点击“Create filesystem”(创建文件系统)
- 选择区域(必须与实例区域匹配)
- 命名并创建
附加到实例
文件系统必须在实例启动时附加:
- 通过控制台:启动时选择文件系统
- 通过 API:在启动请求中包含
file_system_names
最佳实践
# Store on filesystem (persists)
/lambda/nfs/storage/
├── datasets/
├── checkpoints/
├── models/
└── outputs/
# Local SSD (faster, ephemeral)
/home/ubuntu/
└── working/ # Temporary files
SSH 配置
添加 SSH 密钥
# Generate key locally
ssh-keygen -t ed25519 -f ~/.ssh/lambda_key
# Add public key to Lambda console
# Or via API
多个密钥
# On instance, add more keys
echo 'ssh-rsa AAAA...' >> ~/.ssh/authorized_keys
从 GitHub 导入
# On instance
ssh-import-id gh:username
SSH 隧道
# Forward Jupyter
ssh -L 8888:localhost:8888 ubuntu@<IP>
# Forward TensorBoard
ssh -L 6006:localhost:6006 ubuntu@<IP>
# Multiple ports
ssh -L 8888:localhost:8888 -L 6006:localhost:6006 ubuntu@<IP>
JupyterLab
从控制台启动
- 进入 Instances(实例)页面
- 点击 Cloud IDE 列中的“Launch”(启动)
- JupyterLab 将在浏览器中打开
手动访问
# On instance
jupyter lab --ip=0.0.0.0 --port=8888
# From local machine with tunnel
ssh -L 8888:localhost:8888 ubuntu@<IP>
# Open http://localhost:8888
训练工作流
单 GPU 训练
# SSH to instance
ssh ubuntu@<IP>
# Clone repo
git clone https://github.com/user/project
cd project
# Install dependencies
pip install -r requirements.txt
# Train
python train.py --epochs 100 --checkpoint-dir /lambda/nfs/storage/checkpoints
多 GPU 训练(单节点)
# train_ddp.py
import torch
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
def main():
dist.init_process_group("nccl")
rank = dist.get_rank()
device = rank % torch.cuda.device_count()
model = MyModel().to(device)
model = DDP(model, device_ids=[device])
# Training loop...
if __name__ == "__main__":
main()
# Launch with torchrun (8 GPUs)
torchrun --nproc_per_node=8 train_ddp.py
将检查点保存至文件系统
import os
checkpoint_dir = "/lambda/nfs/my-storage/checkpoints"
os.makedirs(checkpoint_dir, exist_ok=True)
# Save checkpoint
torch.save({
'epoch': epoch,
'model_state_dict': model.state_dict(),
'optimizer_state_dict': optimizer.state_dict(),
'loss': loss,
}, f"{checkpoint_dir}/checkpoint_{epoch}.pt")
一键式集群
概述
高性能 Slurm 集群,具备以下特性:
- 16-512 块 NVIDIA H100 或 B200 GPU
- NVIDIA Quantum-2 400 Gb/s InfiniBand
- GPUDirect RDMA,带宽高达 3200 Gb/s
- 预安装分布式机器学习栈
包含的软件
- Ubuntu 22.04 LTS + Lambda Stack
- NCCL, Open MPI
- 支持 DDP 和 FSDP 的 PyTorch
- TensorFlow
- OFED 驱动程序
存储
- 每个计算节点配备 24 TB NVMe(临时存储)
- 用于持久化数据的 Lambda 文件系统
多节点训练
# On Slurm cluster
srun --nodes=4 --ntasks-per-node=8 --gpus-per-node=8 \
torchrun --nnodes=4 --nproc_per_node=8 \
--rdzv_backend=c10d --rdzv_endpoint=$MASTER_ADDR:29500 \
train.py
网络
带宽
- 实例间通信(同一区域):最高 200 Gbps
- 互联网出站流量:最高 20 Gbps
防火墙
- 默认设置:仅开放端口 22 (SSH)
- 在 Lambda 控制台中配置其他端口
- 默认允许 ICMP 流量
私有 IP
# Find private IP
ip addr show | grep 'inet '
常见工作流
工作流 1:大语言模型微调
# 1. Launch 8x H100 instance with filesystem
# 2. SSH and setup
ssh ubuntu@<IP>
pip install transformers accelerate peft
# 3. Download model to filesystem
python -c "
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-hf')
model.save_pretrained('/lambda/nfs/storage/models/llama-2-7b')
"
# 4. Fine-tune with checkpoints on filesystem
accelerate launch --num_processes 8 train.py \
--model_path /lambda/nfs/storage/models/llama-2-7b \
--output_dir /lambda/nfs/storage/outputs \
--checkpoint_dir /lambda/nfs/storage/checkpoints
工作流 2:批量推理
# 1. Launch A10 instance (cost-effective for inference)
# 2. Run inference
python inference.py \
--model /lambda/nfs/storage/models/fine-tuned \
--input /lambda/nfs/storage/data/inputs.jsonl \
--output /lambda/nfs/storage/data/outputs.jsonl
成本优化
选择合适的 GPU
| 任务 | 推荐 GPU |
|---|---|
| 大语言模型微调 (7B) | A100 40GB |
| 大语言模型微调 (70B) | 8x H100 |
| 推理 | A10, A6000 |
| 开发 | V100, A10 |
| 极致性能 | B200 |
降低成本
- 使用文件系统:避免重新下载数据
- 频繁保存检查点:恢复中断的训练
- 合理配置规模:不要过度配置 GPU
- 终止空闲实例:无自动停止功能,需手动终止
监控使用情况
- 仪表板显示实时 GPU 利用率
- 提供 API 用于程序化监控
常见问题
| 问题 | 解决方案 |
|---|---|
| 实例无法启动 | 检查区域可用性,尝试更换 GPU 类型 |
| SSH 连接被拒绝 | 等待实例初始化完成(3-15 分钟) |
| 终止后数据丢失 | 使用持久化文件系统 |
| 数据传输缓慢 | 使用同一区域内的文件系统 |
| 未检测到 GPU | 重启实例,检查驱动程序 |