modal-compute

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Modal Compute

Modal 计算

Use the
modal
CLI for serverless GPU workloads. No pod lifecycle to manage — write a decorated Python script and run it.
使用
modal
CLI运行无服务器GPU工作负载。无需管理Pod生命周期——编写一个带装饰器的Python脚本即可运行。

Setup

设置

bash
pip install modal
modal setup
bash
pip install modal
modal setup

Commands

命令

CommandDescription
modal run script.py
Run a script on Modal (ephemeral)
modal run --detach script.py
Run detached (background)
modal deploy script.py
Deploy persistently
modal serve script.py
Serve with hot-reload (dev)
modal shell --gpu a100
Interactive shell with GPU
modal app list
List deployed apps
命令描述
modal run script.py
在Modal上运行脚本(临时执行)
modal run --detach script.py
后台运行(分离模式)
modal deploy script.py
持久化部署
modal serve script.py
热重载服务(开发环境)
modal shell --gpu a100
带GPU的交互式Shell
modal app list
列出已部署的应用

GPU types

GPU型号

T4
,
L4
,
A10G
,
L40S
,
A100
,
A100-80GB
,
H100
,
H200
,
B200
Multi-GPU:
"H100:4"
for 4x H100s.
T4
,
L4
,
A10G
,
L40S
,
A100
,
A100-80GB
,
H100
,
H200
,
B200
多GPU:
"H100:4"
表示4张H100显卡。

Script pattern

脚本模板

python
import modal

app = modal.App("experiment")
image = modal.Image.debian_slim(python_version="3.11").pip_install("torch==2.8.0")

@app.function(gpu="A100", image=image, timeout=600)
def train():
    import torch
    # training code here

@app.local_entrypoint()
def main():
    train.remote()
python
import modal

app = modal.App("experiment")
image = modal.Image.debian_slim(python_version="3.11").pip_install("torch==2.8.0")

@app.function(gpu="A100", image=image, timeout=600)
def train():
    import torch
    # 训练代码写在这里

@app.local_entrypoint()
def main():
    train.remote()

When to use

使用场景

  • Stateless burst GPU jobs (training, inference, benchmarks)
  • No persistent state needed between runs
  • Check availability:
    command -v modal
  • 无状态突发GPU任务(训练、推理、基准测试)
  • 运行之间无需持久化状态
  • 检查可用性:
    command -v modal