Run Continuous Integration (CI) Tests on Modal
Modal provides building blocks for continuous integration (CI): Functions, Sandboxes, GPUs, and Volumes.
modal.Sandbox based CI
Modal Sandboxes start with sub-second latency and can be spawned hundreds of times per second, making them ideal stateless infrastructure for compilation and test execution.
modal-projects/runner-modal demonstrates how you can run self-hosted GitHub Actions runners on Modal Sandboxes.
Best practices
- If you need Docker in your runners or other advanced features, use
runtime="vm". If you want to run exclusively on fast hardware, adopt performance-sensitive sandboxes. - Configure low CPU and memory requests (e.g.
cpu=0.15, memory=256) and allow your test executor sandboxes to burst. This will be cheaper and faster than setting request equal to limit (eg.cpu=(4,4)).
Users
imbue-ai/offloadruns its Rust and Python CI tests in Modal Sandboxes. GitHub Actions starts thecargo-modalandpytest-modaljobs, and Offload callsmodal.Sandbox.create()followed bysandbox.exec()to run the test commands inside the Sandbox.- Deepspeed: The
modal-torch-latestworkflow callsSandbox.create()and runs test commands throughsandbox.exec().
modal.Function based CI
This example repo is a
demonstration of one pattern for running tests on Modal: bring your existing
package and test suite (here my_pkg and tests) and add a Modal App
(my_pkg.ci) with a Function (pytest) that runs pytest.
That’s as straightforward as writing the following 5 lines of code.
# my_pkg/ci.py
@app.function(gpu="any")
def pytest():
import subprocess
subprocess.run(["pytest", "-vs"], check=True, cwd="/root")Setup
- Create a Python virtual environment
uv pip install modal- That’s it 😎
Usage
All commands below are run from the root of the repository.
Run tests remotely on Modal
modal run -m my_pkg.ciOn the first execution, the container image for your application will be built.
This image will be cached on Modal and only rebuilt if one of its dependencies,
like the requirements.txt file, changes.
Run tests on Modal from GitHub Actions
The same command can be executed from inside a CI runner on another platform.
We provide a sample GitHub Actions workflow in .github/workflows/ci.yml.
To run these tests on GitHub Actions, fork this repo and create a new GitHub Actions secret that contains your MODAL_TOKEN_ID and MODAL_TOKEN_SECRET.
You can find this info in the .modal.toml file in your home directory.
Now you can manually trigger the tests to run on GitHub Actions or trigger them by making a change on our fork and pushing to main or making a pull request.
Debug tests running remotely
To debug the tests, you can open a shell in the exact same environment that the tests are run in:
modal shell -m my_pkg.ciWe used the shell feature heavily while developing this pattern!
Note: On the Modal worker, the pytest command is run from the home directory, /root,
which contains the tests folder, but the modal shell command will
drop you at the top of the filesystem, /.
Users
- PrimeIntellect-ai/prime-rl uses Modal Functions: Each pytest group runs as a GPU
@app.functioninvoked throughremote.aio(). - linkedin/Liger-Kernel uses Modal Functions. Its NVIDIA CI workflow uses
modal runto invoke H100 and B200 test functions.