modal
БесплатноБез исполняемых скриптовНе проверенRun Python functions on cloud GPUs and CPUs with Modal, a serverless platform that builds containers from Python code, scales to zero and bills per second…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Modal
Overview
Modal runs ordinary Python functions in containers it builds and schedules for you. You declare the image, GPU, secrets and volumes in Python decorators; modal run executes once, modal deploy keeps an app live, and idle containers scale to zero. Requires a Modal account and authentication with modal setup, which opens a browser. Do not run modal setup on the user's behalf in an unattended session; ask them to authenticate, or use MODAL_TOKEN_ID and MODAL_TOKEN_SECRET created in the dashboard.
Modal 1.0 renamed several parameters. Code written for 0.x fails with a DeprecationError:
| Old (0.x) | Now |
|---|---|
container_idle_timeout= |
scaledown_window= |
concurrency_limit= |
max_containers= |
@modal.web_endpoint |
@modal.fastapi_endpoint (needs fastapi[standard] in the image) |
allow_concurrent_inputs= |
@modal.concurrent(max_inputs=N) |
Instructions
Step 1: Install and authenticate
pip install modal
modal setup # browser login, writes ~/.modal.toml
modal run --help # sanity check
Step 2: Run a function on a GPU
# hello_gpu.py
import modal
app = modal.App("hello-gpu")
@app.function(gpu="T4")
def gpu_info() -> str:
import subprocess
return subprocess.run(["nvidia-smi"], capture_output=True, text=True).stdout
@app.local_entrypoint()
def main():
print(gpu_info.remote())
modal run hello_gpu.py
GPU strings: T4, L4, A10, L40S, A100 (A100-40GB, A100-80GB), RTX-PRO-6000, H100, H200, B200, B300. Add a count with "H100:8", or a fallback list with gpu=["H100", "A100-80GB"].
Step 3: Define the image
image = (
modal.Image.debian_slim(python_version="3.12")
.pip_install("torch", "transformers", "accelerate")
.env({"HF_HOME": "/models"})
)
app = modal.App("ml-inference", image=image)
Pin versions of packages that break often. Import heavy libraries inside the function body, because the local machine does not have them. Image.uv_pip_install is a faster drop-in for pip_install.
Step 4: Cache model weights in a Volume
volume = modal.Volume.from_name("model-cache", create_if_missing=True)
@app.function(gpu="L40S", volumes={"/models": volume}, timeout=900)
def generate(prompt: str) -> str:
from transformers import pipeline
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-7B-Instruct", device_map="auto")
out = pipe(prompt, max_new_tokens=120)[0]["generated_text"]
volume.commit() # persist weights downloaded into /models/hub
return out
With HF_HOME=/models the first call downloads weights to the volume and later containers reuse them. Call volume.commit() after writing; other containers see new files after volume.reload().
Step 5: Serve an endpoint
import modal
image = modal.Image.debian_slim(python_version="3.12").pip_install("vllm", "fastapi[standard]")
app = modal.App("llm-server", image=image)
MODEL = "Qwen/Qwen2.5-7B-Instruct"
@app.cls(gpu="L40S", scaledown_window=300, timeout=600)
@modal.concurrent(max_inputs=8)
class LLMServer:
@modal.enter()
def load_model(self):
from vllm import LLM
self.llm = LLM(model=MODEL)
@modal.fastapi_endpoint(method="POST")
def generate(self, request: dict):
from vllm import SamplingParams
params = SamplingParams(temperature=0.7, max_tokens=request.get("max_tokens", 200))
out = self.llm.generate([request["prompt"]], params)
return {"text": out[0].outputs[0].text}
modal serve serve_model.py # temporary URL with hot reload, stops on Ctrl-C
modal deploy serve_model.py # persistent; prints the *.modal.run URL
@modal.enter() runs once per container start, so weights load once, not per request. Endpoints are public unless you add auth (requires_proxy_auth=True on the decorator, with proxy auth tokens from the dashboard, or check a header against a secret in the function).
Step 6: Batch, schedule, secrets
@app.function(image=image, max_containers=10)
def embed(text: str) -> int:
return len(text)
@app.local_entrypoint()
def main():
results = list(embed.map([f"Ticket {i}: printer offline" for i in range(100)]))
@app.function(schedule=modal.Cron("0 2 * * *"), gpu="A100", timeout=3600) # 02:00 UTC
def nightly_finetune(): ...
@app.function(secrets=[modal.Secret.from_name("huggingface")])
def private_model():
import os; token = os.environ["HF_TOKEN"]
Create secrets from the CLI: modal secret create huggingface HF_TOKEN="$HF_TOKEN". modal deploy is required for a schedule to run; modal run does not start it.
Examples
Example 1: Run a batch embedding job on GPUs
Request: "Embed these 5,000 support tickets on a GPU, in parallel."
import modal
image = modal.Image.debian_slim(python_version="3.12").pip_install("sentence-transformers")
app = modal.App(
Установить modal в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл modal?
Run Python functions on cloud GPUs and CPUs with Modal, a serverless platform that builds containers from Python code, scales to zero and bills per second. Use when a user asks to "run this on a GPU", "deploy a model endpoint", "serve an LLM with vLLM", "run a nightly training job", "fan out a batch job across many containers", or "cache model weights in a volume" without managing servers or Kubernetes.
Как установить скилл modal?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modal запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic