← 返回
未分类 Key 中文

modal-gpu

Run Python code on cloud GPUs using Modal serverless platform. Use when you need A100/T4/A10G GPU access for training ML models. Covers Modal app setup, GPU...
使用 Modal 无服务器平台在云 GPU 上运行 Python 代码,适用于需要 A100/T4/A10G GPU 进行机器学习模型训练的场景,包括 Modal 应用部署和 GPU 配置等。
lnj22 lnj22 来源
未分类 clawhub v0.1.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 301
下载
💾 0
安装
1
版本
#latest

概述

Modal GPU Training

Overview

Modal is a serverless platform for running Python code on cloud GPUs. It provides:

  • Serverless GPUs: On-demand access to T4, A10G, A100 GPUs
  • Container Images: Define dependencies declaratively with pip
  • Remote Execution: Run functions on cloud infrastructure
  • Result Handling: Return Python objects from remote functions

Two patterns:

  • Single Function: Simple script with @app.function decorator
  • Multi-Function: Complex workflows with multiple remote calls

Quick Reference

TopicReference
------------------
Basic StructureGetting Started
GPU OptionsGPU Selection
Data HandlingData Download
Results & OutputsResults
TroubleshootingCommon Issues

Installation

pip install modal
modal token set --token-id <id> --token-secret <secret>

Minimal Example

import modal

app = modal.App("my-training-app")

image = modal.Image.debian_slim(python_version="3.11").pip_install(
    "torch",
    "einops",
    "numpy",
)

@app.function(gpu="A100", image=image, timeout=3600)
def train():
    import torch
    device = torch.device("cuda")
    print(f"Using GPU: {torch.cuda.get_device_name(0)}")

    # Training code here
    return {"loss": 0.5}

@app.local_entrypoint()
def main():
    results = train.remote()
    print(results)

Common Imports

import modal
from modal import Image, App

# Inside remote function
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download

When to Use What

ScenarioApproach
--------------------
Quick GPU experimentsgpu="T4" (16GB, cheapest)
Medium training jobsgpu="A10G" (24GB)
Large-scale traininggpu="A100" (40/80GB, fastest)
Long-running jobsSet timeout=3600 or higher
Data from HuggingFaceDownload inside function with hf_hub_download
Return metricsReturn dict from function

Running

# Run script
modal run train_modal.py

# Run in background
modal run --detach train_modal.py

External Resources

  • Modal Documentation: https://modal.com/docs
  • Modal Examples: https://github.com/modal-labs/modal-examples

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-05-07 22:08 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,596
office-efficiency

pdf

lnj22
全面PDF工具,支持文本/表格提取、新PDF创建、合并/拆分文档、表单处理。当Claude需要...
★ 0 📥 487
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 326,480