scientific-skills/modal/references/resources.md
@app.function(cpu=4.0)
def compute():
...
OPENBLAS_NUM_THREADS, OMP_NUM_THREADS, MKL_NUM_THREADS based on your CPU request@app.function(cpu=4.0) # Request 4 cores
def bounded_compute():
...
@app.function(memory=16384) # 16 GiB in MiB
def large_data():
...
Set hard memory limits to OOM-kill containers that exceed them:
@app.function(memory=8192) # 8 GiB request and limit
def bounded_memory():
...
This prevents paying for runaway memory leaks.
For temporary storage within a container's lifetime:
@app.function(ephemeral_disk=102400) # 100 GiB in MiB
def process_dataset():
# Temporary files at /tmp or anywhere in the container filesystem
...
Larger disk requests increase the memory request at a 20:1 ratio for billing purposes.
@app.function(timeout=3600) # 1 hour in seconds
def long_running():
...
You are charged based on whichever is higher: your resource request or actual usage.
| Resource | Billing Basis |
|---|---|
| CPU | max(requested, used) |
| Memory | max(requested, used) |
| GPU | Time GPU is allocated |
| Disk | Increases memory billing at 20:1 ratio |
scaledown_window to minimize idle timemin_containers=0 when cold starts are acceptable.map() instead of individual .remote() calls@app.function(
cpu=8.0, # 8 physical cores
memory=32768, # 32 GiB
gpu="L40S", # L40S GPU
ephemeral_disk=204800, # 200 GiB temp disk
timeout=7200, # 2 hours
max_containers=50,
min_containers=1,
)
def full_pipeline(data_path: str):
...