serverless-modal
它能做什么
这个技能在 Modal(一项无服务器云服务)上运行 GPU 代码。适合需要 GPU 算力、又不想设置服务器的人,例如调试 CUDA 代码或运行小型实验。
适用场景
- ✓当你需要 GPU 进行训练、微调或推理,而自己没有本地 GPU 时。
- ✓当你想调试 CUDA 代码或运行简短测试,又不想设置服务器时。
- ✓当代码运行结束后,你希望计费自动停止时。
技能链接
https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/serverless-modal/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我需要一块 GPU 来微调一个小模型,希望直接在 Modal 上运行,不用设置服务器。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会编写一个简短的 Python 文件,声明环境和 GPU 函数,然后用 Modal 命令行运行它。你的代码和结果保留在你的电脑上,只有 GPU 函数在远程运行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Modal Cloud GPU — Training & Inference
Task: $ARGUMENTS
Overview
Modal is a serverless GPU cloud. Key advantages over SSH-based platforms (vast.ai, remote servers):
- Zero config: no SSH, no Docker, no port forwarding. Write Python →
modal run→ done. - Auto scale-to-zero: billing stops the instant your code finishes. No idle instances.
- Local-first: run
modal runfrom your laptop. Code, data, and results stay local; only the GPU function runs remotely. - Reproducible environments: dependencies declared in code via
modal.Image, not system-level packages. Treat themodal.Imagechain as the RENDERED form of the declarative env spec in../shared-references/compute-env-contract.md— same spec fields (base, ordered pip phases, env vars, smoke probes), sameenv:<name>@<specHash>ledger entry in.aris/compute/modal.md, same three-tier validation before a long run.
Best for: Users without a local GPU who need to debug CUDA code, run small-scale tests, or iterate quickly on experiments. The $5 free tier (no card) is enough for code debugging; $30 (with card) covers most small-scale experiment runs.
Trade-off: Modal costs more per GPU-hour than vast.ai or Lightning for some GPU tiers, but eliminates setup time and idle billing, often making it cheaper for short/medium workloads. For long training runs (>4 hours), consider vast.ai for lower $/hr.
Authentication
pip install modal
modal setup # Opens browser login, writes token to ~/.modal.toml
# Verify:
modal run -q 'print("ok")'
- Sign up: https://modal.com (GitHub/Google login)
- Free (no card): $5/month — enough for quick tests
- Free (with card): $30/month — bind a payment method at https://modal.com/settings for the full free tier. Set a workspace spending limit to prevent accidental overcharge (Settings → Usage → Spending Limit)
- Academic: apply for $10k credits | Startups: apply for $25k credits
- Secrets:
modal secret create huggingface-secret HF_TOKEN=hf_xxxxx
Recommended setup: Bind a card to unlock $30/month, then immediately set a spending limit (e.g., $30) so you never exceed the free tier. Modal will pause your workloads when the limit is hit.
SECURITY WARNING: Always bind your card and set spending limits directly on https://modal.com/settings in your browser. NEVER enter payment information, card numbers, or billing details through Claude Code or any CLI tool. Only the official Modal website is safe for payment operations.
Pricing (source: modal.com/pricing, per-second billing)
| GPU | $/sec | ≈$/hr | VRAM | Bandwidth GB/s | Free budget → hours |
|---|---|---|---|---|---|
| T4 | $0.000164 | $0.59 | 16GB | 300 | ~8.5 hr ($5) / 50.8 hr ($30) |
| L4 | $0.000222 | $0.80 | 24GB | 300 | ~6.3 hr / 37.5 hr |
| A10 | $0.000306 | $1.10 | 24GB | 600 | ~4.5 hr / 27.3 hr |
| L40S | $0.000542 | $1.95 | 48GB | 864 | ~2.6 hr / 15.4 hr |
| A100-40GB | $0.000583 | $2.10 | 40GB | 1555 | ~2.4 hr / 14.3 hr |
| A100-80GB | $0.000694 | $2.50 | 80GB | 2039 | ~2.0 hr / 12.0 hr |
| H100 | $0.001097 | $3.95 | 80GB | 3352 | ~1.3 hr / 7.6 hr |
| H200 | $0.001261 | $4.54 | 141GB | 4800 | ~1.1 hr / 6.6 hr |
| B200 | $0.001736 | $6.25 | 192GB | 8000 | ~0.8 hr / 4.8 hr |
CPU: $0.047/core/hr | RAM: $0.008/GiB/hr (GPU typically 90%+ of total cost)
!! Cost Estimation Required !!
Before EVERY run, estimate cost and show to user for confirmation.
Key insights:
- Inference bottleneck is memory bandwidth, not compute → high-bandwidth GPUs are often cheaper overall
- 7-8B BF16 inference needs ~22GB VRAM (weights 15G + KV cache 1G + overhead), T4 (16GB) insufficient
- H100 is often cheaper than L4 for benchmarks (11x faster but only 5x more expensive)
Cost Estimation Template (required before every run)
Cost estimate (Modal):
Model: [name] ([params], [precision])
VRAM: ~[X]GB (weights + KV cache + overhead)
GPU: [type] ([VRAM]GB, $[X]/sec = $[X]/hr, bandwidth [X] GB/s)
Estimate: ~[N] min, ~$[X]
7-8B BF16 Benchmark Cost Comparison
| GPU | Speed tok/s | $/hr | 1000 samples x 200tok cost | Duration |
|---|---|---|---|---|
| H100 | 224 | $3.95 | $0.98 | 15 min |
| A100-40GB | 104 | $2.10 | $1.12 | 32 min |
| L4 | 20 | $0.80 | $2.22 | 167 min |
Workflow
Step 1: Analyze Task → Estimate Cost → Choose GPU
Same analysis as any GPU skill — determine VRAM needs from model size, pick GPU, estimate hours, calculate cost. See
常见问题
我需要 SSH 或 Docker 吗?
不需要。该技能说明 Modal 不需要 SSH,也不需要设置 Docker。
费用是多少?
该技能提到有一个小额免费额度,绑定信用卡后可以使用更多额度。当前价格请查看 Modal 官网。
什么情况下 Modal 不是最佳选择?
对于超过约四小时的长时间训练,该技能建议考虑 Vast.ai。
详情
作者的原始描述
Run GPU workloads on Modal — training, fine-tuning, inference, batch processing. Zero-config serverless: no SSH, no Docker, auto scale-to-zero. Use when user says \"modal run\", \"modal training\", \"modal inference\", \"deploy to modal\", \"need a GPU\", \"run on modal\", \"serverless GPU\", or needs remote GPU compute.
热度
- GitHub 星标
- 18k
- 排名
- #10591
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
ablation-planner
18k帮你的智能体为论文规划消融实验,在主要结果看起来不错之后,选出审稿人很可能会要求的测试。
alphaxiv
18k让你的智能体借助 AlphaXiv 摘要快速阅读一篇研究论文,并以完整文本或 LaTeX 源文件作为备用,只需提供 arXiv 链接或编号。
analyze-results
18k帮你的智能体分析机器学习实验结果,将各次运行与基线进行比较,并把数字整理成清晰的发现和后续步骤。
arxiv
18k让你的智能体在 arXiv 上搜索学术论文、阅读论文详情,并把 PDF 保存到你的文库中,用于某个研究主题。