script
from the command line. This tutorial will show you best practice for setting up a notebook to parse command line arguments, and be flexible enough to run from the command line or from a βedit modeβ in the UI.
CLI Argument Parsing
In order to keep your code modular and easy to run, it is best to start by defining a function as the entry point. This will allow us to route to the function inedit
or script
mode. For this example, we will be writing a dummy training loop for a model that simply sleeps for a user provided number of epochs.
typer
. The typer
library allows you to add a decorator to your function to turn it into a command line application. It will automagically infer the command names, types and default values from the function signature. The function is now usable from the command line without affecting itβs ability to be used in other parts of your code.
Running As A Script
Marimo makes it easy to detect the execution strategy of the file. Simply add a cell that checks if themo.app_meta().mode
is set to script
.
Running In Edit Mode
It is also nice for development of your scripts to be able to kick off the same function in edit mode. For this, using themo.ui.run_button
is a nice pattern. At the top of your notebook, define a cell with a button in it.
mo.stop
method, simply call the same function we used for the CLI.

Running on Oxen.ai
What if you want to train a model, but donβt have a powerful enough GPU? Oxen.aiβs infrastructure allows you to run these scripts in the cloud on customizable hardware. For example, you may want to write a script to fine-tune a model on an A10G GPU with 8 cpu cores and 8GB of RAM. You could configure this script and kick it off on the command line like so:train.py
file must be committed and pushed to your Oxen.ai remote repository on https://oxen.ai for this command to work.