Modal Metaflow
A Metaflow extension that runs steps on Modal with the @modal decorator.
import modal as modal_sdk
from metaflow import FlowSpec, modal, step
class ModalFlow(FlowSpec):
@step
def start(self):
self.x = 3
self.next(self.train)
@modal(gpu="H100", image=modal_sdk.Image.debian_slim().pip_install("torch"))
@step
def train(self):
self.y = self.x * 2 # runs on Modal
self.next(self.end)
@step
def end(self):
print(self.y)
if __name__ == "__main__":
ModalFlow()
Install
pip install git+https://github.com/modal-projects/modal-metaflow
@modal steps need an S3 datastore (--datastore=s3) and S3 credentials inside the Modal container, for example via a secret:
@modal(secrets=[modal_sdk.Secret.from_name("aws-credentials")])
Options
| Option | Meaning |
|---|---|
image |
modal.Image to run the step in. |
cpu, memory, gpu |
Resources, as in @app.function. @resources is also honored. |
secrets, volumes |
Modal secrets and volumes to attach. |
timeout |
Step timeout in seconds. Defaults to 24 hours; longer needs mark_reentrant=True. |
retries |
Modal-level retries. Metaflow's @retry also works. |
environment |
Modal environment to run in. |
role_arn |
AWS role to assume via Modal OIDC. |
clustered_size, clustered_rdma |
Run the step on several nodes, see below. |
Each step of a run deploys a Modal app named <flow>-<run_id>-<random>-<step>. It is stopped, best effort, when the run finishes (or the task, on Argo).
Multi-node steps
clustered_size=N runs the step on N nodes, like modal.clustered. Every node runs the same step code; use current.modal_cluster to coordinate:
@modal(gpu="H100:8", clustered_size=2)
@step
def train(self):
from metaflow import current
cluster = current.modal_cluster # node_rank, node_ips, world_size, cluster_id
# e.g. launch torchrun with --node-rank=cluster.node_rank --master-addr=cluster.node_ips[0]
self.next(self.end)
- Only rank 0 saves artifacts for the next step.
- The step fails if any node fails.
- Port 29501 is reserved on rank 0.
clustered_rdma=Truerequests RDMA. On AWS hosts NCCL uses the EFA plugin, which needslibcudart.soin the image (for example annvidia/cudadevel image).
Argo Workflows
@modal steps work in flows deployed with argo-workflows create. The Argo pod launches the step on Modal, so it needs:
- a Kubernetes secret
modal-argo-credswithMODAL_TOKEN_IDandMODAL_TOKEN_SECRET - the launcher image
ghcr.io/modal-projects/modal-metaflow:latest(override withMETAFLOW_DEFAULT_IMAGE)
foreach is not yet supported on Argo.
Development
See DEVELOPMENT.md.
Metadata
Release files for modal_metaflow 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| modal_metaflow-0.1.0.tar.gz | 20.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modal_metaflow-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.0 kB
Release files / modal_metaflow-0.1.0.tar.gz
| Download URL | modal_metaflow-0.1.0.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bf1f967896ba4ee58b50c1471d25e6c79e891b0fd9a6d9d68e6a5b61c16571f
|
|
BLAKE2b-256 checksum How to use checksums |
ee8b004894fe889664cad092aa58e71523c584b3ea33ea72dfff4bd0e483977f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Oracle Linux Server","version":"9.7","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / modal_metaflow-0.1.0-py3-none-any.whl
| Download URL | modal_metaflow-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2d9d780030e54430f29f13c304edd28eb3c729a241cc25f5c62ad291a036e7b0
|
|
BLAKE2b-256 checksum How to use checksums |
47d17fd0fd612e7b5c63caaf7dbd2d31ea61e666ea93ee546630697a2ef94c7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Oracle Linux Server","version":"9.7","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|