In this tutorial, we walk you through running a GPU-accelerated function to show how Modal makes running code remotely as easy, cost-effective, and performant as possible.

Run a Modal function

Let’s say we have a simple Python function check_gpus that lists the system’s GPUs by running nvidia-smi.

There are just a couple things we do to run this function on Modal:

1. Create a modal.App

2. Wrap a function with @app.function to attach an A10 GPU to your code

3. Call the function from @app.local_entrypoint

In our entrypoint function, we use two methods to call our Modal Function check_gpus from this entrypoint:

  • .local, which executes the function in the same environment as the calling function
  • .remote, which runs the function remotely on Modal

We’ve done these steps for you, so all you need to do is hit the Run button.

🎉 Congratulations, you’ve just run your first function on Modal!


$ modal run get_started.py