Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)51k · #3499

modal

Skill này làm gì

Modal là nền tảng đám mây cho phép bạn chạy mã Python, đặc biệt cho các tác vụ AI và học máy, bằng máy tính mạnh (kể cả GPU) mà không cần quản lý máy chủ.

Khi nào nên dùng

  • ✓Khi bạn cần huấn luyện hoặc chạy mô hình AI bằng GPU mạnh.
  • ✓Để tạo dịch vụ trực tuyến phản hồi yêu cầu, như một trang web hoặc ứng dụng.
  • ✓Để tự động hóa các tác vụ lặp lại cần chạy định kỳ trên đám mây.

Liên kết skill

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/modal/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/modal/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tôi muốn huấn luyện mô hình AI gợi ý phim bằng GPU Nvidia H100 và lưu kết quả vào bộ nhớ bền vững.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn viết mã Python và dùng công cụ của Modal để chỉ định tài nguyên cần thiết (như GPU hoặc bộ nhớ). Modal chịu trách nhiệm chạy mã trên máy chủ đám mây và tự động mở rộng khi cần.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Modal

Overview

Modal is a cloud platform for running Python code serverlessly, with a focus on AI/ML workloads. Key capabilities:

  • GPU compute on demand (including H100, H200, B200 and B300)
  • Serverless functions with autoscaling from zero to thousands of containers
  • Custom container images built entirely in Python code
  • Persistent storage via Volumes for model weights and datasets
  • Web endpoints for serving models and APIs
  • Scheduled jobs via cron or fixed intervals
  • Container reuse and warm pools to reduce cold starts (model loading still takes time)

Modal Apps and Images are defined in Python; existing Dockerfiles are also supported.

When to Use This Skill

Use this skill when:

  • Deploy or serve AI/ML models in the cloud
  • Run GPU-accelerated computations (training, inference, fine-tuning)
  • Create serverless web APIs or endpoints
  • Scale batch processing jobs in parallel
  • Schedule recurring tasks (data pipelines, retraining, scraping)
  • Need persistent cloud storage for model weights or datasets
  • Want to run code in custom container environments
  • Build job queues or async task processing systems

Installation and Authentication

Install

uv pip install "modal==1.6.0"

Reviewed against SDK 1.6.0 and current release notes. Local SDK construction and selected handlers were tested; remote builds, deployments, GPU inference and cloud limits were not executed. Snippets using model/data placeholders or third-party workloads are illustrative and require their stated dependencies.

Authenticate

Prefer existing credentials before creating new ones. Only the two Modal-specific variables below are relevant — do not read, load, or expose any other environment variables or .env file contents:

  1. Reuse an existing Modal profile, or check whether both MODAL_TOKEN_ID and MODAL_TOKEN_SECRET are set; report presence only.
  2. If not, look up only those two keys in a local .env file (ignore all other entries) and load them if appropriate for the workflow.
  3. Only fall back to interactive modal setup if no usable profile or token pair exists. The SDK supports profiles in .modal.toml; environment tokens are optional when a profile authenticates.
modal setup

This opens a browser for authentication. For CI/CD or headless environments, use environment variables:

export MODAL_TOKEN_ID=<your-token-id>
export MODAL_TOKEN_SECRET=<your-token-secret>

If neither an existing profile nor a token pair is available, create credentials at https://modal.com/settings

Check current pricing and workspace quotas before sizing a run. GPU use requires a payment method even when credits remain.

Reference: See references/getting-started.md for detailed setup and first app walkthrough.

Core Concepts

App and Functions

A Modal App groups related functions. Functions decorated with @app.function() run remotely in the cloud:

import modal

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

@app.function()
def square(x):
    return x ** 2

@app.local_entrypoint()
def main():
    # .remote() runs in the cloud
    print(square.remote(42))

Run with modal run script.py. Deploy with modal deploy script.py.

Reference: See references/functions.md for lifecycle hooks, classes, .map(), .spawn(), and more.

Container Images

Modal builds container images from Python code. The recommended package installer is uv:

image = (
    modal.Image.debian_slim(python_version="3.11")
    .uv_pip_install("torch==2.12.0", "transformers==5.9.0", "accelerate==1.13.0")
    .apt_install("git")
)

@app.function(image=image, gpu="L40S")
def inference(prompt):
    from transformers import pipeline
    pipe = pipeline("text-generation", model="openai-community/gpt2", device=0)
    return pipe(prompt)

Key image methods:

  • .uv_pip_install() — Install Python packages with uv (recommended)
  • .pip_install() — Install with pip (fallback)
  • .apt_install() — Install system packages
  • .run_commands() — Run shell commands during build
  • .run_function() — Run Python during build (e.g., download model weights)
  • .add_local_python_source() — Add local modules
  • .env() — Set environment variables

Reference: See references/images.md for Dockerfiles, micromamba, caching, GPU build steps.

GPU Compute

Request GPUs via the gpu parameter:


…
Câu hỏi thường gặp

Làm sao để thiết lập Modal?

Bạn có thể cài Modal bằng `uv pip install "modal==1.6.0"`, sau đó xác thực bằng `modal setup` trong terminal, lệnh này sẽ mở trình duyệt, hoặc thiết lập biến môi trường với token của bạn.

“Serverless functions” là gì?

Đây là các đoạn mã mà Modal chạy trên đám mây khi cần. Bạn không phải lo bật hoặc tắt máy chủ, Modal tự làm điều đó khi mã cần chạy.

Tôi có thể dùng container Docker riêng không?

Có. Modal cho phép bạn dùng container Docker của riêng mình hoặc tạo mới trực tiếp trong mã Python, giúp dễ dàng thiết lập môi trường cho ứng dụng.

Chi tiết

Mô tả gốc của tác giả

Modal is a serverless cloud platform for running Python on demand, including on-demand GPUs. Use when deploying or serving AI/ML models, running GPU-accelerated workloads (training, fine-tuning, inference), serving web endpoints, scheduling batch jobs, or scaling Python code to cloud containers with the Modal SDK.

repo: K-Dense-AI/scientific-agent-skills

Độ phổ biến

Sao GitHub
51k
Vị trí xếp hạng
#3499
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự