GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Guide
  • Examples
  • Log in
  • Sign up

This view

  • Original page
  • New address

GeezerVison is showing modal.com — Hello, world!

Featured Getting started Hello, world Simple web scraper Serving Web Functions Large language models (LLMs) Deploy an OpenAI-compatible LLM service with vLLM Cut Ministral 3 cold start times by 10x with snapshots Maximize tokens per second in batch processing with vLLM Serve an ultra-low-latency chatbot with SGLang Deploy Nemotron 3 Serve Inkling-Small with SGLang Serve DeepSeek-V4-Flash Run a multimodal RAG chatbot to answer questions about PDFs Deploy a stateless MCP with FastMCP Images, video, & 3D Edit images with Flux Kontext Fine-tune Wan2.1 video models on your face Run Flux fast with torch.compile Animate images with LTX-Video Generate video clips with LTX-Video Run Stable Diffusion with a CLI, API, and web UI Audio Stream transcripts at the speed of speech using Kyutai STT Make music with ACE-Step Generate speech with Chatterbox Run high throughput batched transcription with Whisper Fine-tune Whisper to recognize new words Real-time communication (WebRTC) Serverless WebRTC WebRTC quickstart with FastRTC Computational biology Design protein binders with ESMFold2 Fold proteins with Chai-1 Build a protein-folding dashboard Fold proteins with Boltz-2 Modal Sandboxes Run Cursor Cloud Agents on Modal Build a scalable AI coding platform Create GIFs from Slack using the Claude Agent SDK Run a LangGraph agent's code in a secure GPU sandbox Watch a computer-use agent work in real-time over VNC Run massively parallel evals on Modal Sandboxes Build a stateful, sandboxed code interpreter Run Node.js, Ruby, and more in a Sandbox Speed up Sandbox starts with warm pools Inject secrets into outbound requests Reinforcement Learning Paint flowers with code Train coding agents Make LLMs better at math Embeddings Serve Liquid AI embeddings with Modal Servers Embed millions of documents with TEI Parallel processing and job scheduling Deploy a Hacker News Slackbot Run a Document OCR job queue Serve a Document OCR web app Training models from scratch Train an SLM with early-stopping grid search over hyperparameters Run long, resumable training jobs Hosting popular libraries YOLO: Fine-tune and serve computer vision models Blender: Build a 3D render farm Streamlit: Run and deploy Streamlit apps SQLite: Publish explorable data with Datasette Algolia: Build docsearch with a crawler Connecting to other APIs Google Sheets: Sync databases and APIs to a Google Sheet OpenAI: Run a RAG Q&A chatbot Tailscale: Add Modal Apps to your VPN Prometheus: Publish custom metrics with Pushgateway Managing data Mount S3 buckets in Modal Apps Build your own data warehouse with DuckDB, dbt, and Modal Miscellaneous

View on GitHub

Hello, world!

This tutorial demonstrates some core features of Modal:

  • You can run functions on Modal just as easily as you run them locally.
  • Running functions in parallel on Modal is simple and fast.
  • Logs and errors show up immediately, even for functions running on Modal.

Importing Modal and setting up 

We start by importing modal and creating a App. We build up this App to define our application.

import sys

import modal

app = modal.App("example-hello-world")

Defining a function 

Modal takes code and runs it in the cloud.

So first we’ve got to write some code.

Let’s write a simple function that takes in an input, prints a log or an error to the console, and then returns an output.

To make this function work with Modal, we just wrap it in a decorator, @app.function.

@app.function()
def f(i):
    if i % 2 == 0:
        print("hello", i)
    else:
        print("world", i, file=sys.stderr)

    return i * i

Running our function locally, remotely, and in parallel 

Now let’s see three different ways we can call that function:

  1. As a regular call on your local machine, with f.local

  2. As a remote call that runs in the cloud, with f.remote

  3. By mapping many copies of f in the cloud over many inputs, with f.map

We call f in each of these ways inside the main function below.

@app.local_entrypoint()
def main():
    # run the function locally
    print(f.local(1000))

    # run the function remotely on Modal
    print(f.remote(1000))

    # run the function in parallel and remotely on Modal
    total = 0
    for ret in f.map(range(200)):
        total += ret

    print(total)

Enter modal run hello_world.py in a shell, and you’ll see a Modal app initialize. You’ll then see the printed logs of the main function and, mixed in with them, all the logs of f as it is run locally, then remotely, and then remotely and in parallel.

That’s all triggered by adding the @app.local_entrypoint decorator on main, which defines it as the function to start from locally when we invoke modal run.

What just happened? 

When we called .remote on f, the function was executed in the cloud, on Modal’s infrastructure, not on the local machine.

In short, we took the function f, put it inside a container, sent it the inputs, and streamed back the logs and outputs.

But why does this matter? 

Try one of these things next to start seeing the full power of Modal!

You can change the code and run it again 

For instance, change the print statement in the function f to print "spam" and "eggs" instead and run the app again. You’ll see that that your new code is run with no extra work from you — and it should even run faster!

Modal’s goal is to make running code in the cloud feel like you’re running code locally. That means no waiting for long image builds when you’ve just moved a comma, no fiddling with container image pushes, and no context-switching to a web UI to inspect logs.

You can map over more data 

Change the map range from 200 to some large number, like 1170. You’ll see Modal create and run even more containers in parallel this time.

And it’ll happen lightning fast!

You can run a more interesting function 

The function f is a bit silly and doesn’t do much, but in its place imagine something that matters to you, like:

  • Running language model inference or fine-tuning
  • Manipulating audio or images
  • Embedding huge text datasets at lightning fast speeds

Modal lets you parallelize that operation effortlessly by running hundreds or thousands of containers in the cloud.

Hello, world!Importing Modal and setting upDefining a functionRunning our function locally, remotely, and in parallelWhat just happened?But why does this matter?You can change the code and run it againYou can map over more dataYou can run a more interesting function

Try this on Modal!

You can run this example on Modal in 60 seconds.

Create account to run

After creating a free account, install the Modal Python package, and create an API token.

$
pip install modal
$
modal setup

Clone the modal-examples repository and run:

$
git clone https://github.com/modal-labs/modal-examples
$
cd modal-examples
$
modal run 01_getting_started/hello_world.py
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.