Home Knowledge Base Modal

Modal is the serverless cloud platform for Python that enables running GPU-accelerated AI workloads in the cloud by defining infrastructure requirements directly in Python code — eliminating Docker file complexity, environment management, and idle GPU costs by running containers on-demand and billing only for actual compute time.

What Is Modal?

Why Modal Matters for AI Workloads

Core Modal Concepts

Defining Environments: import modal

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

Define container image as Python code

image = ( modal.Image.debian_slim(python_version="3.11") .pip_install("torch", "transformers", "vllm", "accelerate") .env({"HF_HOME": "/cache"}) )

GPU Functions: @app.function( image=image, gpu="A100", # Request A100 GPU memory=65536, # 64GB RAM timeout=7200, # 2-hour timeout volumes={"/cache": modal.Volume.from_name("model-cache")} # Persistent storage ) def fine_tune(dataset_path: str, output_path: str): # This code runs on A100 in the cloud from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3-8B") # ... fine-tuning code ... model.save_pretrained(output_path)

Run from local terminal — transparently executes on A100

with app.run(): fine_tune.remote("s3://bucket/dataset.jsonl", "/cache/model-v2")

Parallel Batch Processing: @app.function(image=image, gpu="L4", concurrency_limit=20) def embed_document(text: str) -> list[float]: return embedding_model.encode(text)

with app.run(): # Automatically parallelizes across up to 20 containers embeddings = list(embed_document.map(documents, order_outputs=True))

Web Endpoints: @app.function(image=image, gpu="A10G") @modal.web_endpoint(method="POST") async def generate(request: dict) -> dict: return {"response": model.generate(request["prompt"])}

Deploy: modal deploy my_app.py

Endpoint URL returned — autoscales from 0 to N based on traffic

Modal Storage

Modal Volumes: Persistent filesystem shared across function invocations — store model weights, datasets, checkpoints.

Modal Secrets: Encrypted key-value store for API keys, HuggingFace tokens, database credentials — referenced in function definitions without hardcoding.

modal.Secret.from_name("openai-api-key") # Injected as environment variable

Modal vs Alternatives

PlatformStrengthWeakness
ModalPython-first, serverless, fast iterationNewer, smaller community
RunPodCheaper for long jobs, flexibleLess developer-friendly API
Lambda LabsCheapest H100s, simpleNo serverless; always-on billing
AWS SageMakerEnterprise features, ecosystemComplex, expensive, heavy
Google ColabFree tier, JupyterLimited compute time, not production

Modal is the platform that makes cloud GPU computing feel like local development — by collapsing the gap between writing code on a laptop and executing it on a 8×H100 cluster to a single Python decorator, Modal dramatically accelerates the iteration speed of AI research and production deployment workflows.

modalserverless

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.