Metaflow torchrun decorator
Introduction
This repository implements a plugin to run parallel Metaflow tasks as nodes in a torchrun job which can be submitted to AWS Batch or a Kubernetes cluster.
Features
- Automatic torchrun integration: This extension provides a simple and intuitive way to incorporate PyTorch distributed programs in your Metaflow workflows using the
@torchrundecorator - No changes to model code: The
@torchrundecorator exposes a new method on the Metaflow current object, so you can run your existing torch distributed programs inside Metaflow tasks with no changes in the research code. - Run one command: You don't need to log into many nodes and run commands on each. Instead, the
@torchrundecorator will select arguments for the torchrun command based on the requests in Metaflow compute decorators like number of GPUs. Network addresses are automatically discoverable. - No user-facing subprocess calls: At the end of the day,
@torchrunis calling a subprocess inside a Metaflow task. Although many Metaflow users do this, it can make code difficult to read for beginners. One major goal of this plugin is to motivate hardening and automating a pattern for submitting subprocess calls inside Metaflow tasks.
Installation
You can install it with:
pip install metaflow-torchrun
Getting Started
And then you can import it and use in parallel steps:
from metaflow import FlowSpec, step, torchrun
...
class MyGPT(FlowSpec):
@step
def start(self):
self.next(self.torch_multinode, num_parallel=N_NODES)
@kubernetes(cpu=N_CPU, gpu=N_GPU, memory=MEMORY)
@torchrun
@step
def torch_multinode(self):
...
current.torch.run(
entrypoint="main.py", # No changes made to original script.
entrypoint_args = {"main-arg-1": "123", "main-arg-2": "777"},
nproc_per_node=1, # edge case of a torchrun arg user-facing.
)
...
...
Examples
| Directory | torch script description |
|---|---|
| Hello | Each process prints their rank and the world size. |
| Tensor pass | Main process passes a tensor to the workers. |
| Torch DDP | A flow that uses a script from the torchrun tutorials on multi-node DDP. |
| MinGPT | A flow that runs a torchrun GPT demo that simplifies Karpathy's minGPT in a set of parallel Metaflow tasks each contributing their @resources. |
License
metaflow-torchrun is distributed under the Apache License.
Metadata
Release files for metaflow-torchrun 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metaflow_torchrun-0.2.2.tar.gz | 13.9 kB | Without provenance | Details for metaflow_torchrun-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metaflow_torchrun-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for metaflow_torchrun-0.2.2-py3-none-any.whl |
Total release size: 29.5 kB
Release files / metaflow_torchrun-0.2.2.tar.gz
| Download URL | metaflow_torchrun-0.2.2.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b33bcde2e17672b78d784cd9d30594b92103dabd9dc3d88c4475c4785a12efca
|
|
BLAKE2b-256 checksum How to use checksums |
a1ab967e954034aa0f949922511ce17d685e3d5ed6dfbc8d7ce98e208141942d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / metaflow_torchrun-0.2.2-py3-none-any.whl
| Download URL | metaflow_torchrun-0.2.2-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ddc4089ea0a820d193a28736bd4b55fd99899d09982034728be6dc6ff136eeb
|
|
BLAKE2b-256 checksum How to use checksums |
c2f5e82db23ff9c0af348db58af2f3f24a69cd780b755e84b57dbb0f99124539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for metaflow-torchrun 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.