Metaflow-torchrun is a Python library that provides a `@torchrun` decorator to enable distributed PyTorch training within Metaflow steps. It abstracts away the complexities of launching and managing `torchrun` processes, allowing users to integrate distributed ML workflows seamlessly into their Metaflow flows. The current version is 0.2.1, with relatively frequent updates since its initial release.
pip install metaflow-torchrunVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a basic Metaflow flow using the `@torchrun` decorator. Save this code as a Python file (e.g., `my_flow.py`) and run it from your terminal using `python my_flow.py run`. It will launch 2 parallel processes on the local machine within the `train_distributed` step, each printing its rank information. Ensure `metaflow-torchrun`, `metaflow`, and `torch` are installed in your environment.
Run Metaflow flows decorated with `@torchrun` as a standalone Python script from your terminal: `python your_flow.py run`.
Install `torch` (which includes `torchrun`) in your environment: `pip install torch` (or `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118` for CUDA-enabled versions).
Pass arguments as `args=['--epochs', '10', '--lr', '0.01']` instead of a single string, dictionary, or other types. For example: `@torchrun(args=['--model-name', 'resnet50'])`.
Understand that `metaflow-torchrun` simplifies single-node distributed training. For multi-node setups, more advanced Metaflow features or other orchestrators would be required.