A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
examples: GPU notebooks with modal (#3711)
Akshay Agrawal1315b5ba5d5e
diff --git a/examples/cloud/modal/README.md b/examples/cloud/modal/README.mdindex abee3b05da..f73203fac1 100644--- a/examples/cloud/modal/README.md+++ b/examples/cloud/modal/README.md@@ -1,7 +1,26 @@-# Deploying marimo on modal+# Running marimo on Modal-This folder contains examples of how to use marimo notebook on Modal.+This folder contains examples of how to run marimo notebooks on+[Modal](https://modal.com/), making it easy to get access to cloud GPUs. To get+started, first create a modal account and follow their onboarding. You'll also+need to install the [uv package manager](https://docs.astral.sh/uv/).-[modal_app.py](modal_app.py) has an example of how to deploy a read-only marimo notebook as an app on Modal.+## Editable notebooks+[modal_edit.py](modal_edit.py) has an example of how to spin up an editable+marimo notebook that runs on a Modal container. Run with++```bash+uvx -p 3.12 modal run modal_edit.py+```++You can configure your GPU selection by editing `modal_edit`.++## Run as apps++[modal_app.py](modal_app.py) has an example of how to deploy a read-only marimo+notebook as an app on Modal. Run with++```bash+uvx -p 3.12 modal run modal_run.py+```-[modal_edit.py](modal_edit.py) has an example of how to spin up an editable marimo notebook that runs on a Modal container. Run with `modal run modal_edit.py` (requires Modal account and configured credentials).diff --git a/examples/cloud/modal/modal_app.py b/examples/cloud/modal/modal_app.pyindex a30bf0ab3f..d8f955623c 100644--- a/examples/cloud/modal/modal_app.py+++ b/examples/cloud/modal/modal_app.py@@ -5,7 +5,7 @@ from modal import asgi_appimport marimo-server = marimo.create_asgi_app().with_app(path="", root="/marimo/home.py")+server = marimo.create_asgi_app().with_app(path="", root="/marimo/notebook.py")app = modal.App()diff --git a/examples/cloud/modal/modal_edit.py b/examples/cloud/modal/modal_edit.pyindex 8e24c59bb9..a57427286c 100644--- a/examples/cloud/modal/modal_edit.py+++ b/examples/cloud/modal/modal_edit.py@@ -5,15 +5,16 @@ import timeimport modalapp = modal.App(- image=modal.Image.debian_slim().pip_install(- "marimo>=0.9.32", "modal>=0.67.31"- ))+ image=modal.Image.debian_slim()+ .pip_install("marimo>=0.9.32", "modal>=0.67.31")+ .add_local_dir("nbs", remote_path="/root/nbs")+)TOKEN = secrets.token_urlsafe(16)PORT = 2718[email protected](concurrency_limit=1, timeout=1_500)[email protected](concurrency_limit=1, timeout=1_500, gpu="t4")def run_marimo(timeout: int):with modal.forward(PORT) as tunnel:marimo_process = subprocess.Popen(@@ -21,10 +22,13 @@ def run_marimo(timeout: int):"marimo","edit","--headless",- "--host", "0.0.0.0",- "--port", str(PORT),- f"--token-password", TOKEN,- "notebook.py",+ "--host",+ "0.0.0.0",+ "--port",+ str(PORT),+ f"--token-password",+ TOKEN,+ "nbs/notebook.py",],)@@ -34,7 +38,9 @@ def run_marimo(timeout: int):end_time = time.time() + timeoutwhile time.time() < end_time:time.sleep(5)- print(f"Reached end of {timeout} second timeout period. Exiting...")+ print(+ f"Reached end of {timeout} second timeout period. Exiting..."+ )except KeyboardInterrupt:print("Exiting...")finally:diff --git a/examples/cloud/modal/nbs/home.py b/examples/cloud/modal/nbs/notebook.pysimilarity index 65%rename from examples/cloud/modal/nbs/home.pyrename to examples/cloud/modal/nbs/notebook.pyindex 826c80a9e7..8291cd5f51 100644--- a/examples/cloud/modal/nbs/home.py+++ b/examples/cloud/modal/nbs/notebook.py@@ -13,7 +13,15 @@ def __(mo):@app.celldef __():import marimo as mo- return mo,+ return (mo,)+++def __():+ import subprocess++ subprocess.run(["nvidia-smi"])+ return subprocessif __name__ == "__main__":