@pikaa-ai/pikaa 0.3.22 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/brand/orbit-logo-option4-whale.jpg +0 -0
- package/assets/brand/orbit-logo.jpg +0 -0
- package/assets/brand/orbit-logo.png +0 -0
- package/assets/brand/orbit-logo.svg +3 -0
- package/dist/cli.js +448 -181
- package/dist/index.js +22 -2
- package/package.json +1 -2
- package/skills/adaptyv/SKILL.md +0 -240
- package/skills/aeon/SKILL.md +0 -402
- package/skills/analytical-method-validation/SKILL.md +0 -299
- package/skills/anndata/SKILL.md +0 -431
- package/skills/arbor/SKILL.md +0 -152
- package/skills/arboreto/SKILL.md +0 -267
- package/skills/astropy/SKILL.md +0 -353
- package/skills/autoskill/SKILL.md +0 -233
- package/skills/benchling-integration/SKILL.md +0 -229
- package/skills/bgpt-paper-search/SKILL.md +0 -75
- package/skills/bids/SKILL.md +0 -237
- package/skills/biopython/SKILL.md +0 -472
- package/skills/bioservices/SKILL.md +0 -399
- package/skills/bulk-rnaseq/SKILL.md +0 -198
- package/skills/cellxgene-census/SKILL.md +0 -283
- package/skills/cirq/SKILL.md +0 -370
- package/skills/citation-management/SKILL.md +0 -329
- package/skills/clinical-decision-support/SKILL.md +0 -238
- package/skills/clinical-decision-support/references/README.md +0 -62
- package/skills/clinical-reports/SKILL.md +0 -248
- package/skills/clinical-reports/references/README.md +0 -34
- package/skills/cobrapy/SKILL.md +0 -496
- package/skills/consciousness-council/SKILL.md +0 -151
- package/skills/dask/SKILL.md +0 -482
- package/skills/database-lookup/SKILL.md +0 -386
- package/skills/datamol/SKILL.md +0 -200
- package/skills/deepchem/SKILL.md +0 -244
- package/skills/deepspot-m/SKILL.md +0 -175
- package/skills/deeptools/SKILL.md +0 -412
- package/skills/depmap/SKILL.md +0 -301
- package/skills/dhdna-profiler/SKILL.md +0 -184
- package/skills/diffdock/SKILL.md +0 -488
- package/skills/dnanexus-integration/SKILL.md +0 -325
- package/skills/docx/SKILL.md +0 -99
- package/skills/esm/SKILL.md +0 -334
- package/skills/etetoolkit/SKILL.md +0 -327
- package/skills/exa-search/SKILL.md +0 -102
- package/skills/executing-plans/SKILL.md +0 -14
- package/skills/experimental-design/SKILL.md +0 -234
- package/skills/exploratory-data-analysis/SKILL.md +0 -280
- package/skills/flowio/SKILL.md +0 -310
- package/skills/fluidsim/SKILL.md +0 -279
- package/skills/frontend-design/SKILL.md +0 -100
- package/skills/generate-image/SKILL.md +0 -304
- package/skills/geniml/SKILL.md +0 -310
- package/skills/genomic-coordinates/SKILL.md +0 -189
- package/skills/genomic-intelligence/SKILL.md +0 -243
- package/skills/geomaster/README.md +0 -105
- package/skills/geomaster/SKILL.md +0 -366
- package/skills/geopandas/SKILL.md +0 -250
- package/skills/get-available-resources/SKILL.md +0 -260
- package/skills/gget/SKILL.md +0 -153
- package/skills/ginkgo-cloud-lab/SKILL.md +0 -106
- package/skills/glycoengineering/SKILL.md +0 -339
- package/skills/gtars/SKILL.md +0 -282
- package/skills/guardian-rails/SKILL.md +0 -54
- package/skills/histolab/SKILL.md +0 -243
- package/skills/hugging-science/SKILL.md +0 -132
- package/skills/hypogenic/SKILL.md +0 -290
- package/skills/hypothesis-generation/SKILL.md +0 -264
- package/skills/imaging-data-commons/SKILL.md +0 -496
- package/skills/infographics/SKILL.md +0 -315
- package/skills/iso-standards-readiness/SKILL.md +0 -352
- package/skills/lab-hardware-cad/SKILL.md +0 -372
- package/skills/labarchive-integration/SKILL.md +0 -216
- package/skills/lamindb/SKILL.md +0 -408
- package/skills/latchbio-integration/SKILL.md +0 -227
- package/skills/latex-posters/SKILL.md +0 -369
- package/skills/latex-posters/references/README.md +0 -439
- package/skills/liteparse/SKILL.md +0 -295
- package/skills/literature-review/SKILL.md +0 -263
- package/skills/markdown-mermaid-writing/SKILL.md +0 -322
- package/skills/market-research-reports/SKILL.md +0 -337
- package/skills/markitdown/SKILL.md +0 -264
- package/skills/matchms/SKILL.md +0 -276
- package/skills/matlab/SKILL.md +0 -274
- package/skills/matplotlib/SKILL.md +0 -378
- package/skills/medchem/SKILL.md +0 -321
- package/skills/modal/SKILL.md +0 -468
- package/skills/molecular-dynamics/SKILL.md +0 -458
- package/skills/molfeat/SKILL.md +0 -348
- package/skills/ncats-arax/SKILL.md +0 -178
- package/skills/networkx/SKILL.md +0 -440
- package/skills/neurokit2/SKILL.md +0 -323
- package/skills/neuropixels-analysis/SKILL.md +0 -412
- package/skills/nextflow/SKILL.md +0 -195
- package/skills/omero-integration/SKILL.md +0 -222
- package/skills/onekgpd/SKILL.md +0 -371
- package/skills/ontology-term-resolution/SKILL.md +0 -147
- package/skills/open-notebook/SKILL.md +0 -297
- package/skills/openpiv/SKILL.md +0 -469
- package/skills/opentrons-integration/SKILL.md +0 -322
- package/skills/optimize-for-gpu/SKILL.md +0 -176
- package/skills/owasp-top10/SKILL.md +0 -48
- package/skills/pacsomatic/LICENSE +0 -21
- package/skills/pacsomatic/SKILL.md +0 -150
- package/skills/paper-lookup/SKILL.md +0 -263
- package/skills/paperclip/SKILL.md +0 -413
- package/skills/paperzilla/SKILL.md +0 -159
- package/skills/parallel-web/SKILL.md +0 -128
- package/skills/pathml/SKILL.md +0 -222
- package/skills/pathogen-variant-surveillance/SKILL.md +0 -208
- package/skills/pathway-enrichment/SKILL.md +0 -194
- package/skills/pdf/SKILL.md +0 -322
- package/skills/peer-review/SKILL.md +0 -288
- package/skills/penetration-testing/SKILL.md +0 -31
- package/skills/pennylane/SKILL.md +0 -240
- package/skills/phylogenetics/SKILL.md +0 -409
- package/skills/pi-agent/SKILL.md +0 -83
- package/skills/pkpd-modeling/SKILL.md +0 -381
- package/skills/polars/SKILL.md +0 -393
- package/skills/polars-bio/SKILL.md +0 -379
- package/skills/ponytail/SKILL.md +0 -31
- package/skills/ponytail-audit/SKILL.md +0 -18
- package/skills/pptx/SKILL.md +0 -246
- package/skills/pptx-posters/SKILL.md +0 -258
- package/skills/primekg/SKILL.md +0 -99
- package/skills/protocolsio-integration/SKILL.md +0 -236
- package/skills/pufferlib/SKILL.md +0 -328
- package/skills/pydeseq2/SKILL.md +0 -369
- package/skills/pydicom/SKILL.md +0 -381
- package/skills/pyhealth/SKILL.md +0 -124
- package/skills/pylabrobot/SKILL.md +0 -216
- package/skills/pymatgen/SKILL.md +0 -404
- package/skills/pymc/SKILL.md +0 -310
- package/skills/pymoo/SKILL.md +0 -276
- package/skills/pyopenms/SKILL.md +0 -179
- package/skills/pysam/SKILL.md +0 -330
- package/skills/pytdc/SKILL.md +0 -297
- package/skills/pytorch-lightning/SKILL.md +0 -191
- package/skills/pyzotero/SKILL.md +0 -137
- package/skills/qiskit/SKILL.md +0 -259
- package/skills/qutip/SKILL.md +0 -317
- package/skills/rdkit/SKILL.md +0 -94
- package/skills/relsa-severity-assessment/SKILL.md +0 -354
- package/skills/research-grants/SKILL.md +0 -296
- package/skills/research-grants/references/README.md +0 -287
- package/skills/research-lookup/README.md +0 -106
- package/skills/research-lookup/SKILL.md +0 -338
- package/skills/rowan/SKILL.md +0 -398
- package/skills/scanpy/SKILL.md +0 -303
- package/skills/scholar-evaluation/SKILL.md +0 -296
- package/skills/scientific-brainstorming/SKILL.md +0 -282
- package/skills/scientific-critical-thinking/SKILL.md +0 -180
- package/skills/scientific-schematics/SKILL.md +0 -370
- package/skills/scientific-slides/SKILL.md +0 -379
- package/skills/scientific-visualization/SKILL.md +0 -285
- package/skills/scientific-writing/SKILL.md +0 -356
- package/skills/scikit-bio/SKILL.md +0 -470
- package/skills/scikit-learn/SKILL.md +0 -324
- package/skills/scikit-survival/SKILL.md +0 -313
- package/skills/scvelo/SKILL.md +0 -328
- package/skills/scvi-tools/SKILL.md +0 -201
- package/skills/seaborn/SKILL.md +0 -254
- package/skills/security-auditor/SKILL.md +0 -37
- package/skills/shap/SKILL.md +0 -282
- package/skills/simpy/SKILL.md +0 -283
- package/skills/stable-baselines3/SKILL.md +0 -325
- package/skills/statistical-analysis/SKILL.md +0 -446
- package/skills/statistical-power/SKILL.md +0 -200
- package/skills/statsmodels/SKILL.md +0 -238
- package/skills/sympy/SKILL.md +0 -354
- package/skills/systematic-debugging/SKILL.md +0 -35
- package/skills/tamarind/SKILL.md +0 -285
- package/skills/tdd/SKILL.md +0 -26
- package/skills/tiledbvcf/SKILL.md +0 -456
- package/skills/timesfm-forecasting/SKILL.md +0 -408
- package/skills/timesfm-forecasting/examples/global-temperature/README.md +0 -178
- package/skills/torch-geometric/SKILL.md +0 -458
- package/skills/torchdrug/SKILL.md +0 -241
- package/skills/transformers/SKILL.md +0 -195
- package/skills/treatment-plans/SKILL.md +0 -174
- package/skills/treatment-plans/references/README.md +0 -19
- package/skills/umap-learn/SKILL.md +0 -488
- package/skills/uncertainty-and-units/SKILL.md +0 -384
- package/skills/usfiscaldata/SKILL.md +0 -171
- package/skills/vaex/SKILL.md +0 -204
- package/skills/venue-templates/SKILL.md +0 -269
- package/skills/verification-before-completion/SKILL.md +0 -22
- package/skills/waypoint-bio/SKILL.md +0 -273
- package/skills/what-if-oracle/SKILL.md +0 -184
- package/skills/writing-plans/SKILL.md +0 -15
- package/skills/xlsx/SKILL.md +0 -110
- package/skills/zarr-python/SKILL.md +0 -241
package/skills/modal/SKILL.md
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: modal
|
|
3
|
-
description: 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.
|
|
4
|
-
license: Apache-2.0
|
|
5
|
-
metadata:
|
|
6
|
-
version: "1.2"
|
|
7
|
-
skill-author: K-Dense Inc.
|
|
8
|
-
openclaw:
|
|
9
|
-
envVars:
|
|
10
|
-
- name: MODAL_TOKEN_ID
|
|
11
|
-
required: true
|
|
12
|
-
description: Modal token id.
|
|
13
|
-
- name: MODAL_TOKEN_SECRET
|
|
14
|
-
required: true
|
|
15
|
-
description: Modal token secret.
|
|
16
|
-
- name: DATABASE_URL
|
|
17
|
-
required: false
|
|
18
|
-
description: Optional database URL for examples.
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
# Modal
|
|
22
|
-
|
|
23
|
-
## Overview
|
|
24
|
-
|
|
25
|
-
Modal is a cloud platform for running Python code serverlessly, with a focus on AI/ML workloads. Key capabilities:
|
|
26
|
-
- **GPU compute** on demand (T4, L4, A10, L40S, A100, H100, H200, B200)
|
|
27
|
-
- **Serverless functions** with autoscaling from zero to thousands of containers
|
|
28
|
-
- **Custom container images** built entirely in Python code
|
|
29
|
-
- **Persistent storage** via Volumes for model weights and datasets
|
|
30
|
-
- **Web endpoints** for serving models and APIs
|
|
31
|
-
- **Scheduled jobs** via cron or fixed intervals
|
|
32
|
-
- **Sub-second cold starts** for low-latency inference
|
|
33
|
-
|
|
34
|
-
Everything in Modal is defined as code — no YAML, no Dockerfiles required (though both are supported).
|
|
35
|
-
|
|
36
|
-
## When to Use This Skill
|
|
37
|
-
|
|
38
|
-
Use this skill when:
|
|
39
|
-
- Deploy or serve AI/ML models in the cloud
|
|
40
|
-
- Run GPU-accelerated computations (training, inference, fine-tuning)
|
|
41
|
-
- Create serverless web APIs or endpoints
|
|
42
|
-
- Scale batch processing jobs in parallel
|
|
43
|
-
- Schedule recurring tasks (data pipelines, retraining, scraping)
|
|
44
|
-
- Need persistent cloud storage for model weights or datasets
|
|
45
|
-
- Want to run code in custom container environments
|
|
46
|
-
- Build job queues or async task processing systems
|
|
47
|
-
|
|
48
|
-
## Installation and Authentication
|
|
49
|
-
|
|
50
|
-
### Install
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
uv pip install modal
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
The Modal Python SDK supports Python 3.10–3.14. This skill targets the stable `modal>=1.0` API (current release: 1.4.x).
|
|
57
|
-
|
|
58
|
-
### Authenticate
|
|
59
|
-
|
|
60
|
-
Prefer existing credentials before creating new ones. Only the two Modal-specific
|
|
61
|
-
variables below are relevant — do not read, load, or expose any other environment
|
|
62
|
-
variables or `.env` file contents:
|
|
63
|
-
|
|
64
|
-
1. Check whether `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET` are already set in the current environment.
|
|
65
|
-
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.
|
|
66
|
-
3. Only fall back to interactive `modal setup` or generating fresh tokens if neither source already provides those two values.
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
modal setup
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
This opens a browser for authentication. For CI/CD or headless environments, use environment variables:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
export MODAL_TOKEN_ID=<your-token-id>
|
|
76
|
-
export MODAL_TOKEN_SECRET=<your-token-secret>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
If tokens are not already available in the environment or `.env`, generate them at https://modal.com/settings
|
|
80
|
-
|
|
81
|
-
Modal offers a free tier with $30/month in credits.
|
|
82
|
-
|
|
83
|
-
**Reference**: See `references/getting-started.md` for detailed setup and first app walkthrough.
|
|
84
|
-
|
|
85
|
-
## Core Concepts
|
|
86
|
-
|
|
87
|
-
### App and Functions
|
|
88
|
-
|
|
89
|
-
A Modal `App` groups related functions. Functions decorated with `@app.function()` run remotely in the cloud:
|
|
90
|
-
|
|
91
|
-
```python
|
|
92
|
-
import modal
|
|
93
|
-
|
|
94
|
-
app = modal.App("my-app")
|
|
95
|
-
|
|
96
|
-
@app.function()
|
|
97
|
-
def square(x):
|
|
98
|
-
return x ** 2
|
|
99
|
-
|
|
100
|
-
@app.local_entrypoint()
|
|
101
|
-
def main():
|
|
102
|
-
# .remote() runs in the cloud
|
|
103
|
-
print(square.remote(42))
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Run with `modal run script.py`. Deploy with `modal deploy script.py`.
|
|
107
|
-
|
|
108
|
-
**Reference**: See `references/functions.md` for lifecycle hooks, classes, `.map()`, `.spawn()`, and more.
|
|
109
|
-
|
|
110
|
-
### Container Images
|
|
111
|
-
|
|
112
|
-
Modal builds container images from Python code. The recommended package installer is `uv`:
|
|
113
|
-
|
|
114
|
-
```python
|
|
115
|
-
image = (
|
|
116
|
-
modal.Image.debian_slim(python_version="3.11")
|
|
117
|
-
.uv_pip_install("torch==2.12.0", "transformers==5.9.0", "accelerate==1.13.0")
|
|
118
|
-
.apt_install("git")
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
@app.function(image=image)
|
|
122
|
-
def inference(prompt):
|
|
123
|
-
from transformers import pipeline
|
|
124
|
-
pipe = pipeline("text-generation", model="meta-llama/Llama-3-8B")
|
|
125
|
-
return pipe(prompt)
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Key image methods:
|
|
129
|
-
- `.uv_pip_install()` — Install Python packages with uv (recommended)
|
|
130
|
-
- `.pip_install()` — Install with pip (fallback)
|
|
131
|
-
- `.apt_install()` — Install system packages
|
|
132
|
-
- `.run_commands()` — Run shell commands during build
|
|
133
|
-
- `.run_function()` — Run Python during build (e.g., download model weights)
|
|
134
|
-
- `.add_local_python_source()` — Add local modules
|
|
135
|
-
- `.env()` — Set environment variables
|
|
136
|
-
|
|
137
|
-
**Reference**: See `references/images.md` for Dockerfiles, micromamba, caching, GPU build steps.
|
|
138
|
-
|
|
139
|
-
### GPU Compute
|
|
140
|
-
|
|
141
|
-
Request GPUs via the `gpu` parameter:
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
@app.function(gpu="H100")
|
|
145
|
-
def train_model():
|
|
146
|
-
import torch
|
|
147
|
-
device = torch.device("cuda")
|
|
148
|
-
# GPU training code here
|
|
149
|
-
|
|
150
|
-
# Multiple GPUs
|
|
151
|
-
@app.function(gpu="H100:4")
|
|
152
|
-
def distributed_training():
|
|
153
|
-
...
|
|
154
|
-
|
|
155
|
-
# GPU fallback chain
|
|
156
|
-
@app.function(gpu=["H100", "A100-80GB", "A100-40GB"])
|
|
157
|
-
def flexible_inference():
|
|
158
|
-
...
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Available GPUs: T4, L4, A10, L40S, A100-40GB, A100-80GB, RTX-PRO-6000, H100, H200, B200, B200+
|
|
162
|
-
|
|
163
|
-
- GPUs are always specified as **strings** (e.g. `gpu="H100"`, `gpu="H100:4"`). The old `modal.gpu.*` objects are deprecated as of v0.73.31.
|
|
164
|
-
- Up to 8 GPUs per container (except A10: up to 4)
|
|
165
|
-
- L40S is recommended for inference (cost/performance balance, 48 GB VRAM)
|
|
166
|
-
- H100/A100 can be auto-upgraded to H200/A100-80GB at no extra cost
|
|
167
|
-
- Use `gpu="H100!"` to prevent auto-upgrade
|
|
168
|
-
|
|
169
|
-
**Reference**: See `references/gpu.md` for GPU selection guidance and multi-GPU training.
|
|
170
|
-
|
|
171
|
-
### Volumes (Persistent Storage)
|
|
172
|
-
|
|
173
|
-
Volumes provide distributed, persistent file storage:
|
|
174
|
-
|
|
175
|
-
```python
|
|
176
|
-
vol = modal.Volume.from_name("model-weights", create_if_missing=True)
|
|
177
|
-
|
|
178
|
-
@app.function(volumes={"/data": vol})
|
|
179
|
-
def save_model():
|
|
180
|
-
# Write to the mounted path
|
|
181
|
-
with open("/data/model.pt", "wb") as f:
|
|
182
|
-
torch.save(model.state_dict(), f)
|
|
183
|
-
|
|
184
|
-
@app.function(volumes={"/data": vol})
|
|
185
|
-
def load_model():
|
|
186
|
-
model.load_state_dict(torch.load("/data/model.pt"))
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
- Optimized for write-once, read-many workloads (model weights, datasets)
|
|
190
|
-
- CLI access: `modal volume ls`, `modal volume put`, `modal volume get`
|
|
191
|
-
- Background auto-commits every few seconds
|
|
192
|
-
- Mount read-only or limit to a subdirectory with `vol.with_mount_options(read_only=True, sub_path="subset")`
|
|
193
|
-
|
|
194
|
-
**Reference**: See `references/volumes.md` for v2 volumes, concurrent writes, and best practices.
|
|
195
|
-
|
|
196
|
-
### Secrets
|
|
197
|
-
|
|
198
|
-
Securely pass credentials to functions:
|
|
199
|
-
|
|
200
|
-
```python
|
|
201
|
-
@app.function(secrets=[modal.Secret.from_name("my-api-keys")])
|
|
202
|
-
def call_api():
|
|
203
|
-
import os
|
|
204
|
-
api_key = os.environ["API_KEY"]
|
|
205
|
-
# Use the key
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Create secrets via CLI: `modal secret create my-api-keys API_KEY=sk-xxx`
|
|
209
|
-
|
|
210
|
-
Or from a `.env` file: `modal.Secret.from_dotenv()`
|
|
211
|
-
|
|
212
|
-
**Reference**: See `references/secrets.md` for dashboard setup, multiple secrets, and templates.
|
|
213
|
-
|
|
214
|
-
### Web Endpoints
|
|
215
|
-
|
|
216
|
-
Serve models and APIs as web endpoints:
|
|
217
|
-
|
|
218
|
-
```python
|
|
219
|
-
@app.function()
|
|
220
|
-
@modal.fastapi_endpoint()
|
|
221
|
-
def predict(text: str):
|
|
222
|
-
return {"result": model.predict(text)}
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
- `modal serve script.py` — Development with hot reload and temporary URL
|
|
226
|
-
- `modal deploy script.py` — Production deployment with permanent URL
|
|
227
|
-
- Supports FastAPI, ASGI (Starlette, FastHTML), WSGI (Flask, Django), WebSockets
|
|
228
|
-
- Request bodies up to 4 GiB, unlimited response size
|
|
229
|
-
|
|
230
|
-
**Reference**: See `references/web-endpoints.md` for ASGI/WSGI apps, streaming, auth, and WebSockets.
|
|
231
|
-
|
|
232
|
-
### Scheduled Jobs
|
|
233
|
-
|
|
234
|
-
Run functions on a schedule:
|
|
235
|
-
|
|
236
|
-
```python
|
|
237
|
-
@app.function(schedule=modal.Cron("0 9 * * *")) # Daily at 9 AM UTC
|
|
238
|
-
def daily_pipeline():
|
|
239
|
-
# ETL, retraining, scraping, etc.
|
|
240
|
-
...
|
|
241
|
-
|
|
242
|
-
@app.function(schedule=modal.Period(hours=6))
|
|
243
|
-
def periodic_check():
|
|
244
|
-
...
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
Deploy with `modal deploy script.py` to activate the schedule.
|
|
248
|
-
|
|
249
|
-
- `modal.Cron("...")` — Standard cron syntax, stable across deploys
|
|
250
|
-
- `modal.Period(hours=N)` — Fixed interval, resets on redeploy
|
|
251
|
-
- Monitor runs in the Modal dashboard
|
|
252
|
-
|
|
253
|
-
**Reference**: See `references/scheduled-jobs.md` for cron syntax and management.
|
|
254
|
-
|
|
255
|
-
### Scaling and Concurrency
|
|
256
|
-
|
|
257
|
-
Modal autoscales containers automatically. Configure limits:
|
|
258
|
-
|
|
259
|
-
```python
|
|
260
|
-
@app.function(
|
|
261
|
-
max_containers=100, # Upper limit
|
|
262
|
-
min_containers=2, # Keep warm for low latency
|
|
263
|
-
buffer_containers=5, # Reserve capacity
|
|
264
|
-
scaledown_window=300, # Idle seconds before shutdown
|
|
265
|
-
)
|
|
266
|
-
def process(data):
|
|
267
|
-
...
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Process inputs in parallel with `.map()`:
|
|
271
|
-
|
|
272
|
-
```python
|
|
273
|
-
results = list(process.map([item1, item2, item3, ...]))
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
Enable concurrent request handling per container with `@modal.concurrent`. Set
|
|
277
|
-
`target_inputs` (the autoscaler's per-container target) below `max_inputs` (the hard
|
|
278
|
-
cap) to keep headroom while scaling up:
|
|
279
|
-
|
|
280
|
-
```python
|
|
281
|
-
@app.function()
|
|
282
|
-
@modal.concurrent(max_inputs=10, target_inputs=8)
|
|
283
|
-
async def handle_request(req):
|
|
284
|
-
...
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
Reconfigure a deployed Function or Cls at invocation time without redeploying using
|
|
288
|
-
`Function.with_options()` / `Function.with_concurrency()` / `Function.with_batching()`
|
|
289
|
-
(and `Cls.with_options()`):
|
|
290
|
-
|
|
291
|
-
```python
|
|
292
|
-
Model = modal.Cls.from_name("my-app", "Model")
|
|
293
|
-
fast = Model.with_options(gpu="H200", max_containers=20)
|
|
294
|
-
fast().generate.remote(prompt)
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
**Reference**: See `references/scaling.md` for `.map()`, `.starmap()`, `.spawn()`, and limits.
|
|
298
|
-
|
|
299
|
-
### Resource Configuration
|
|
300
|
-
|
|
301
|
-
```python
|
|
302
|
-
@app.function(
|
|
303
|
-
cpu=4.0, # Physical cores (not vCPUs)
|
|
304
|
-
memory=16384, # MiB
|
|
305
|
-
ephemeral_disk=51200, # MiB (up to 3 TiB)
|
|
306
|
-
timeout=3600, # Seconds
|
|
307
|
-
)
|
|
308
|
-
def heavy_computation():
|
|
309
|
-
...
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
Defaults: 0.125 CPU cores, 128 MiB memory. Billed on max(request, usage).
|
|
313
|
-
|
|
314
|
-
**Reference**: See `references/resources.md` for limits and billing details.
|
|
315
|
-
|
|
316
|
-
## Classes with Lifecycle Hooks
|
|
317
|
-
|
|
318
|
-
For stateful workloads (e.g., loading a model once and serving many requests):
|
|
319
|
-
|
|
320
|
-
```python
|
|
321
|
-
@app.cls(gpu="L40S", image=image)
|
|
322
|
-
class Predictor:
|
|
323
|
-
@modal.enter()
|
|
324
|
-
def load_model(self):
|
|
325
|
-
self.model = load_heavy_model() # Runs once on container start
|
|
326
|
-
|
|
327
|
-
@modal.method()
|
|
328
|
-
def predict(self, text: str):
|
|
329
|
-
return self.model(text)
|
|
330
|
-
|
|
331
|
-
@modal.exit()
|
|
332
|
-
def cleanup(self):
|
|
333
|
-
... # Runs on container shutdown
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Call with: `Predictor().predict.remote("hello")`
|
|
337
|
-
|
|
338
|
-
## Sandboxes
|
|
339
|
-
|
|
340
|
-
For running untrusted or dynamically generated code (for example, AI-agent output or a code interpreter), use a `modal.Sandbox` — an isolated container you create and control programmatically rather than a decorated Function:
|
|
341
|
-
|
|
342
|
-
```python
|
|
343
|
-
app = modal.App.lookup("sandbox-demo", create_if_missing=True)
|
|
344
|
-
|
|
345
|
-
# Isolated container; restrict egress for untrusted workloads
|
|
346
|
-
sb = modal.Sandbox.create(
|
|
347
|
-
app=app,
|
|
348
|
-
image=modal.Image.debian_slim(),
|
|
349
|
-
outbound_cidr_allowlist=["10.0.0.0/8"],
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
# Stream files in/out via the filesystem API (beta)
|
|
353
|
-
sb.filesystem.write_text("print(2 ** 10)\n", "/tmp/job.py")
|
|
354
|
-
contents = sb.filesystem.read_text("/tmp/job.py")
|
|
355
|
-
|
|
356
|
-
sb.terminate()
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
- Run commands inside the sandbox with its `exec` method (e.g. run `python /tmp/job.py`) and read stdout from the returned process handle — see `references/api_reference.md`
|
|
360
|
-
- Restrict connectivity with `outbound_cidr_allowlist=[...]` / `inbound_cidr_allowlist=[...]`
|
|
361
|
-
- Snapshot the filesystem with `sb.snapshot_filesystem()` to reuse as a base image
|
|
362
|
-
- Ideal for code interpreters, agent tool execution, and per-user isolation
|
|
363
|
-
|
|
364
|
-
## Common Workflow Patterns
|
|
365
|
-
|
|
366
|
-
### GPU Model Inference Service
|
|
367
|
-
|
|
368
|
-
```python
|
|
369
|
-
import modal
|
|
370
|
-
|
|
371
|
-
app = modal.App("llm-service")
|
|
372
|
-
|
|
373
|
-
image = (
|
|
374
|
-
modal.Image.debian_slim(python_version="3.11")
|
|
375
|
-
.uv_pip_install("vllm")
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
@app.cls(gpu="H100", image=image, min_containers=1)
|
|
379
|
-
class LLMService:
|
|
380
|
-
@modal.enter()
|
|
381
|
-
def load(self):
|
|
382
|
-
from vllm import LLM
|
|
383
|
-
self.llm = LLM(model="meta-llama/Llama-3-70B")
|
|
384
|
-
|
|
385
|
-
@modal.method()
|
|
386
|
-
@modal.fastapi_endpoint(method="POST")
|
|
387
|
-
def generate(self, prompt: str, max_tokens: int = 256):
|
|
388
|
-
outputs = self.llm.generate([prompt], max_tokens=max_tokens)
|
|
389
|
-
return {"text": outputs[0].outputs[0].text}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Batch Processing Pipeline
|
|
393
|
-
|
|
394
|
-
```python
|
|
395
|
-
app = modal.App("batch-pipeline")
|
|
396
|
-
vol = modal.Volume.from_name("pipeline-data", create_if_missing=True)
|
|
397
|
-
|
|
398
|
-
@app.function(volumes={"/data": vol}, cpu=4.0, memory=8192)
|
|
399
|
-
def process_chunk(chunk_id: int):
|
|
400
|
-
import pandas as pd
|
|
401
|
-
df = pd.read_parquet(f"/data/input/chunk_{chunk_id}.parquet")
|
|
402
|
-
result = heavy_transform(df)
|
|
403
|
-
result.to_parquet(f"/data/output/chunk_{chunk_id}.parquet")
|
|
404
|
-
return len(result)
|
|
405
|
-
|
|
406
|
-
@app.local_entrypoint()
|
|
407
|
-
def main():
|
|
408
|
-
chunk_ids = list(range(100))
|
|
409
|
-
results = list(process_chunk.map(chunk_ids))
|
|
410
|
-
print(f"Processed {sum(results)} total rows")
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
### Scheduled Data Pipeline
|
|
414
|
-
|
|
415
|
-
```python
|
|
416
|
-
app = modal.App("etl-pipeline")
|
|
417
|
-
|
|
418
|
-
@app.function(
|
|
419
|
-
schedule=modal.Cron("0 */6 * * *"), # Every 6 hours
|
|
420
|
-
secrets=[modal.Secret.from_name("db-credentials")],
|
|
421
|
-
)
|
|
422
|
-
def etl_job():
|
|
423
|
-
import os
|
|
424
|
-
db_url = os.environ["DATABASE_URL"]
|
|
425
|
-
# Extract, transform, load
|
|
426
|
-
...
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## CLI Reference
|
|
430
|
-
|
|
431
|
-
| Command | Description |
|
|
432
|
-
|---------|-------------|
|
|
433
|
-
| `modal setup` | Authenticate with Modal |
|
|
434
|
-
| `modal run script.py` | Run a script's local entrypoint |
|
|
435
|
-
| `modal serve script.py` | Dev server with hot reload |
|
|
436
|
-
| `modal deploy script.py` | Deploy to production |
|
|
437
|
-
| `modal volume ls <name>` | List files in a volume |
|
|
438
|
-
| `modal volume put <name> <file>` | Upload file to volume |
|
|
439
|
-
| `modal volume get <name> <file>` | Download file from volume |
|
|
440
|
-
| `modal secret create <name> K=V` | Create a secret |
|
|
441
|
-
| `modal secret list` | List secrets |
|
|
442
|
-
| `modal app list` | List deployed apps |
|
|
443
|
-
| `modal app stop <name>` | Stop a deployed app |
|
|
444
|
-
|
|
445
|
-
## Security Notes
|
|
446
|
-
|
|
447
|
-
- **Credentials:** Only `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET` are needed to authenticate. Do not read, log, or forward any other environment variables or `.env` entries.
|
|
448
|
-
- **Subprocess / custom servers:** Some patterns here (multi-GPU training launchers, `@modal.web_server` apps) call `subprocess.run`/`subprocess.Popen` or shell commands during builds. Keep argument lists fixed and hardcoded. Never construct subprocess or shell arguments from unsanitized user input — pass untrusted values as data (files, env vars, stdin), not as command arguments.
|
|
449
|
-
- **Untrusted code:** Run user- or model-generated code inside a `modal.Sandbox` (see above), not a regular Function, and restrict network access with CIDR allowlists.
|
|
450
|
-
|
|
451
|
-
## Reference Files
|
|
452
|
-
|
|
453
|
-
Detailed documentation for each topic:
|
|
454
|
-
|
|
455
|
-
- `references/getting-started.md` — Installation, authentication, first app
|
|
456
|
-
- `references/functions.md` — Functions, classes, lifecycle hooks, remote execution
|
|
457
|
-
- `references/images.md` — Container images, package installation, caching
|
|
458
|
-
- `references/gpu.md` — GPU types, selection, multi-GPU, training
|
|
459
|
-
- `references/volumes.md` — Persistent storage, file management, v2 volumes
|
|
460
|
-
- `references/secrets.md` — Credentials, environment variables, dotenv
|
|
461
|
-
- `references/web-endpoints.md` — FastAPI, ASGI/WSGI, streaming, auth, WebSockets
|
|
462
|
-
- `references/scheduled-jobs.md` — Cron, periodic schedules, management
|
|
463
|
-
- `references/scaling.md` — Autoscaling, concurrency, .map(), limits
|
|
464
|
-
- `references/resources.md` — CPU, memory, disk, timeout configuration
|
|
465
|
-
- `references/examples.md` — Common use cases and patterns
|
|
466
|
-
- `references/api_reference.md` — Key API classes and methods
|
|
467
|
-
|
|
468
|
-
Read these files when detailed information is needed beyond this overview.
|