azar-run-flow 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azar_run_flow-0.4.0/LICENSE +21 -0
- azar_run_flow-0.4.0/PKG-INFO +237 -0
- azar_run_flow-0.4.0/README.md +195 -0
- azar_run_flow-0.4.0/pyproject.toml +69 -0
- azar_run_flow-0.4.0/setup.cfg +4 -0
- azar_run_flow-0.4.0/src/azar_run_flow/__init__.py +18 -0
- azar_run_flow-0.4.0/src/azar_run_flow/cli.py +215 -0
- azar_run_flow-0.4.0/src/azar_run_flow/config.py +99 -0
- azar_run_flow-0.4.0/src/azar_run_flow/provenance.py +80 -0
- azar_run_flow-0.4.0/src/azar_run_flow/runner.py +265 -0
- azar_run_flow-0.4.0/src/azar_run_flow/scheduler.py +515 -0
- azar_run_flow-0.4.0/src/azar_run_flow/seed.py +23 -0
- azar_run_flow-0.4.0/src/azar_run_flow/tracking.py +119 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/PKG-INFO +237 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/SOURCES.txt +22 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/dependency_links.txt +1 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/entry_points.txt +2 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/requires.txt +18 -0
- azar_run_flow-0.4.0/src/azar_run_flow.egg-info/top_level.txt +1 -0
- azar_run_flow-0.4.0/tests/test_cli_ui.py +86 -0
- azar_run_flow-0.4.0/tests/test_core.py +149 -0
- azar_run_flow-0.4.0/tests/test_mlflow_server.py +74 -0
- azar_run_flow-0.4.0/tests/test_robustness.py +187 -0
- azar_run_flow-0.4.0/tests/test_scheduler.py +264 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 azhir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: azar-run-flow
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Robust, reproducible experiment tracking and scheduling for research code (Hydra + MLflow).
|
|
5
|
+
Author: azhir
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/azhir/azar-run-flow
|
|
8
|
+
Project-URL: Source, https://github.com/azhir/azar-run-flow
|
|
9
|
+
Project-URL: Issues, https://github.com/azhir/azar-run-flow/issues
|
|
10
|
+
Keywords: machine learning,research,experiment tracking,mlflow,hydra,reproducibility,gpu,job queue
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: mlflow<4,>=3
|
|
27
|
+
Requires-Dist: numpy>=1.23
|
|
28
|
+
Requires-Dist: psutil>=5.9
|
|
29
|
+
Requires-Dist: nvidia-ml-py>=12
|
|
30
|
+
Requires-Dist: hydra-core<1.4,>=1.3
|
|
31
|
+
Requires-Dist: omegaconf<2.4,>=2.3
|
|
32
|
+
Provides-Extra: zen
|
|
33
|
+
Requires-Dist: hydra-zen<0.17,>=0.16; extra == "zen"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
36
|
+
Requires-Dist: hydra-zen<0.17,>=0.16; extra == "dev"
|
|
37
|
+
Requires-Dist: matplotlib>=3.6; extra == "dev"
|
|
38
|
+
Provides-Extra: notebook
|
|
39
|
+
Requires-Dist: ipykernel>=6; extra == "notebook"
|
|
40
|
+
Requires-Dist: matplotlib>=3.6; extra == "notebook"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# AzarRunFlow
|
|
44
|
+
|
|
45
|
+
A small, robust base for machine-learning research: **Hydra** for configs,
|
|
46
|
+
**MLflow** for tracking and monitoring, and a GPU-aware **job queue** for
|
|
47
|
+
scheduling. It records everything needed to reproduce a run, and guarantees that
|
|
48
|
+
what MLflow shows is true, even when runs crash, time out or are killed.
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
your research repo: train.py (Hydra app) ──run_experiment──► MLflow store ◄── azar ui
|
|
52
|
+
▲ (sqlite file or server)
|
|
53
|
+
azar submit ─► queue ─► azar worker (GPU locks, timeouts, retries, logs)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install azar-run-flow # or: uv add azar-run-flow
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Python 3.10 or newer, on Linux or macOS. This gives you the library
|
|
63
|
+
(`run_experiment`, `azar_run`, `Run`) and the `azar` command (job queue and UI).
|
|
64
|
+
|
|
65
|
+
**Use it in your project**
|
|
66
|
+
|
|
67
|
+
1. Choose where the project's runs live, once per project (in your shell, `.envrc` or
|
|
68
|
+
job script); otherwise they go to `./mlflow.db` and `./.azar` of the directory you
|
|
69
|
+
start in:
|
|
70
|
+
```bash
|
|
71
|
+
export MLFLOW_TRACKING_URI=sqlite:///$HOME/research/myproject/runs/mlflow.db
|
|
72
|
+
export AZAR_HOME=$HOME/research/myproject/runs/azar # job queue and logs
|
|
73
|
+
```
|
|
74
|
+
2. Wrap your training code in `run_experiment` (next section).
|
|
75
|
+
3. Watch the runs: `azar ui` (or `azar ui --tailscale` from another device, see
|
|
76
|
+
[Monitor](#monitor)); queue long runs with `azar submit` ([Schedule](#schedule)).
|
|
77
|
+
|
|
78
|
+
New here? The [quickstart notebook](https://github.com/azhir/azar-run-flow/blob/main/examples/quickstart.ipynb) walks through it
|
|
79
|
+
in a few minutes: two MLP variants trained, compared and watched live in the MLflow UI.
|
|
80
|
+
|
|
81
|
+
## Track an experiment
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import hydra
|
|
85
|
+
from omegaconf import DictConfig
|
|
86
|
+
from azar_run_flow import run_experiment
|
|
87
|
+
|
|
88
|
+
def experiment(run, cfg: dict):
|
|
89
|
+
for step in range(cfg["steps"]):
|
|
90
|
+
loss = ...
|
|
91
|
+
run.metric("loss", loss, step=step)
|
|
92
|
+
run.figure("curve.png", fig) # also: run.array, run.json, run.text,
|
|
93
|
+
run.checkpoint("model.pt") # run.artifact, run.tag, run.metrics
|
|
94
|
+
return {"loss": loss}
|
|
95
|
+
|
|
96
|
+
@hydra.main(config_path="configs", config_name="config", version_base=None)
|
|
97
|
+
def main(cfg: DictConfig):
|
|
98
|
+
run_experiment(experiment, config=cfg, experiment_name=cfg.experiment_name)
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
main()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python train.py # defaults
|
|
106
|
+
python train.py model.depth=8 optim.lr=3e-4 # override anything
|
|
107
|
+
python train.py -m optim.lr=1e-3,3e-4 seed=0,1 # sweep: one MLflow run per combination
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A complete example is in [examples/hydra_app/](https://github.com/azhir/azar-run-flow/blob/main/examples/hydra_app/).
|
|
111
|
+
`azar_run(config=...)` is the context-manager form when you don't want a function.
|
|
112
|
+
|
|
113
|
+
### What every run records
|
|
114
|
+
|
|
115
|
+
| Where in MLflow | What |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| params | every scalar config value (`model.depth`, `optim.lr`, …), searchable |
|
|
118
|
+
| `config/resolved.yaml`, `config/overrides.txt` | the full resolved config and the exact Hydra overrides |
|
|
119
|
+
| tags `git_commit`, `git_branch`, `git_dirty` | code version |
|
|
120
|
+
| `provenance/git_diff.patch`, `git_status.txt` | uncommitted changes, when the tree is dirty |
|
|
121
|
+
| `provenance/provenance.json`, `packages.txt` | command line, seed, host, Python, every installed package |
|
|
122
|
+
| tag `seed` | the seed applied to `random`, NumPy and PyTorch: `seed=` argument, else the config's `seed`, else freshly drawn |
|
|
123
|
+
| metric `runtime_seconds`, `system/*` | duration; CPU, memory and GPU utilisation/memory/power over time |
|
|
124
|
+
| tag `azar.status` + run status | `completed`/FINISHED, `failed`/FAILED (with `failure/traceback.txt`) or `killed`/KILLED |
|
|
125
|
+
|
|
126
|
+
## Monitor
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
uv run azar ui # MLflow UI on ./mlflow.db at http://127.0.0.1:5050
|
|
130
|
+
uv run azar ui --tailscale # the same, for your other devices: http://<machine>:5050
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Opening the UI when the code runs on another machine** (a GPU server, VS Code Remote-SSH):
|
|
134
|
+
|
|
135
|
+
- **Tailscale** (simplest, when the machines are on the same tailnet): start it with
|
|
136
|
+
`azar ui --tailscale` (or `make ui-tailscale`) and open the printed address, e.g.
|
|
137
|
+
`http://gpubox:5050`, from your laptop or phone. The UI has no login, so every
|
|
138
|
+
device on your tailnet can view and delete runs: use this on a tailnet you trust.
|
|
139
|
+
- **VS Code Remote-SSH**: start `azar ui`, open the **Ports** panel, and open the
|
|
140
|
+
*Forwarded Address* of port 5050 (usually `localhost:5050`).
|
|
141
|
+
|
|
142
|
+
Opening the machine's own address without `--tailscale` fails: the UI then listens
|
|
143
|
+
only on 127.0.0.1, and MLflow refuses unknown host names (HTTP 403). The default port
|
|
144
|
+
is 5050, not MLflow's 5000, because macOS uses port 5000 for the AirPlay Receiver.
|
|
145
|
+
|
|
146
|
+
Runs go to `$MLFLOW_TRACKING_URI`, default `sqlite:///mlflow.db` in the directory
|
|
147
|
+
you start from. Set it once per project (e.g. in your shell or `.envrc`) so every
|
|
148
|
+
run lands in the same store:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
export MLFLOW_TRACKING_URI=sqlite:///$HOME/research/myproject/mlflow.db
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
A SQLite store handles one workstation well, including parallel jobs. To watch runs
|
|
155
|
+
from another machine, run an MLflow server on the store and point
|
|
156
|
+
`MLFLOW_TRACKING_URI` at it (`http://host:5000`); nothing else changes.
|
|
157
|
+
|
|
158
|
+
## Schedule
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
azar submit --gpus 1 --timeout 12h -- python train.py model.depth=8 # prints a job id
|
|
162
|
+
azar submit --gpus 1 --retries 2 --name big -- python train.py model.depth=16
|
|
163
|
+
for lr in 1e-3 3e-4 1e-4; do azar submit --gpus 1 -- python train.py optim.lr=$lr; done
|
|
164
|
+
|
|
165
|
+
azar worker --slots 2 # runs jobs, 2 at a time; Ctrl-C stops it (jobs -> interrupted)
|
|
166
|
+
azar status # pending, running and recent jobs
|
|
167
|
+
azar logs JOB -f # follow a job's output (any unique id prefix works)
|
|
168
|
+
azar cancel JOB # pending: removed; running: SIGTERM, then SIGKILL after 30 s
|
|
169
|
+
azar retry JOB # queue a finished job again
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- A job runs exactly as if you had run it at submit time: same directory, same
|
|
173
|
+
environment variables. `CUDA_VISIBLE_DEVICES` is set to the GPUs it was given
|
|
174
|
+
(empty for `--gpus 0`).
|
|
175
|
+
- Jobs start in submission order as soon as the GPUs they need are free. A GPU is
|
|
176
|
+
never given to two jobs, across workers and even after a worker crashes.
|
|
177
|
+
- Each job's MLflow runs carry the tag `azar.job_id`. Its output is in
|
|
178
|
+
`$AZAR_HOME/jobs/<id>/attempt<N>.log`.
|
|
179
|
+
- The queue lives in `$AZAR_HOME` (default `./.azar`). Use the same `AZAR_HOME` for
|
|
180
|
+
`submit` and `worker`; for one queue across projects, `export AZAR_HOME=~/azar`.
|
|
181
|
+
- `azar worker --gpus 0,1` restricts a worker to some GPUs. To keep a worker running
|
|
182
|
+
after you log out, start it in `tmux` (or as a service).
|
|
183
|
+
|
|
184
|
+
## Reproduce a run
|
|
185
|
+
|
|
186
|
+
Everything needed is attached to the run in MLflow:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
git checkout <git_commit tag>
|
|
190
|
+
git apply provenance/git_diff.patch # only if git_dirty is True
|
|
191
|
+
uv sync --locked # the environment, if uv.lock is committed
|
|
192
|
+
python train.py $(cat config/overrides.txt)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The seed comes back with the config (or pass the recorded `seed` tag as
|
|
196
|
+
`seed=<value>`). On the same machine and software this reproduces CPU results
|
|
197
|
+
exactly; GPU kernels can differ slightly between runs unless you also enable
|
|
198
|
+
`torch.use_deterministic_algorithms(True)`. Untracked files are listed in
|
|
199
|
+
`git_status.txt` but not saved, so commit new source files before important runs.
|
|
200
|
+
|
|
201
|
+
## Robustness guarantees
|
|
202
|
+
|
|
203
|
+
Each is covered by a test in `tests/`:
|
|
204
|
+
|
|
205
|
+
- Parallel processes can start using a fresh SQLite store at the same time; without
|
|
206
|
+
the initialisation lock, plain MLflow corrupts the database.
|
|
207
|
+
- A run never stays RUNNING after it ends: Ctrl-C and SIGTERM (timeouts, `kill`,
|
|
208
|
+
cluster schedulers) close it as KILLED, and the scheduler closes runs of jobs that
|
|
209
|
+
were SIGKILLed or died.
|
|
210
|
+
- A tracking error while recording a failure never hides the experiment's own error.
|
|
211
|
+
- Artifacts always live next to their SQLite store (`mlruns/`), not in whatever
|
|
212
|
+
directory a run started in; `hydra.job.chdir=true` does not create a second store.
|
|
213
|
+
- Queue state changes are atomic renames; a crashed worker's job is filed as `lost`
|
|
214
|
+
and never silently re-run; timeouts and cancellation kill the job's whole process
|
|
215
|
+
group, including data-loader workers.
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
To work on azar-run-flow itself:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
git clone https://github.com/azhir/azar-run-flow && cd azar-run-flow
|
|
223
|
+
uv sync --locked --extra dev # isolated Python 3.12 env in .venv (see CLAUDE.md)
|
|
224
|
+
make test # uv run pytest -q, about 2 minutes
|
|
225
|
+
make example # run the example into ./.azar/mlflow.db
|
|
226
|
+
make ui # browse it
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
To use a local checkout from another project while changing it:
|
|
230
|
+
`pip install -e path/to/azar-run-flow` (or `uv add --editable path/to/azar-run-flow`).
|
|
231
|
+
The quickstart notebook needs `uv sync --locked --extra dev --extra notebook`.
|
|
232
|
+
|
|
233
|
+
**Releasing.** Bump `version` in `pyproject.toml`, merge to `main`, then
|
|
234
|
+
`git tag vX.Y.Z && git push origin vX.Y.Z`. The GitHub workflow tests, builds and
|
|
235
|
+
publishes the release to PyPI.
|
|
236
|
+
|
|
237
|
+
Design: [ARCHITECTURE.md](https://github.com/azhir/azar-run-flow/blob/main/ARCHITECTURE.md). Plans: [ROADMAP.md](https://github.com/azhir/azar-run-flow/blob/main/ROADMAP.md).
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# AzarRunFlow
|
|
2
|
+
|
|
3
|
+
A small, robust base for machine-learning research: **Hydra** for configs,
|
|
4
|
+
**MLflow** for tracking and monitoring, and a GPU-aware **job queue** for
|
|
5
|
+
scheduling. It records everything needed to reproduce a run, and guarantees that
|
|
6
|
+
what MLflow shows is true, even when runs crash, time out or are killed.
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
your research repo: train.py (Hydra app) ──run_experiment──► MLflow store ◄── azar ui
|
|
10
|
+
▲ (sqlite file or server)
|
|
11
|
+
azar submit ─► queue ─► azar worker (GPU locks, timeouts, retries, logs)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install azar-run-flow # or: uv add azar-run-flow
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Python 3.10 or newer, on Linux or macOS. This gives you the library
|
|
21
|
+
(`run_experiment`, `azar_run`, `Run`) and the `azar` command (job queue and UI).
|
|
22
|
+
|
|
23
|
+
**Use it in your project**
|
|
24
|
+
|
|
25
|
+
1. Choose where the project's runs live, once per project (in your shell, `.envrc` or
|
|
26
|
+
job script); otherwise they go to `./mlflow.db` and `./.azar` of the directory you
|
|
27
|
+
start in:
|
|
28
|
+
```bash
|
|
29
|
+
export MLFLOW_TRACKING_URI=sqlite:///$HOME/research/myproject/runs/mlflow.db
|
|
30
|
+
export AZAR_HOME=$HOME/research/myproject/runs/azar # job queue and logs
|
|
31
|
+
```
|
|
32
|
+
2. Wrap your training code in `run_experiment` (next section).
|
|
33
|
+
3. Watch the runs: `azar ui` (or `azar ui --tailscale` from another device, see
|
|
34
|
+
[Monitor](#monitor)); queue long runs with `azar submit` ([Schedule](#schedule)).
|
|
35
|
+
|
|
36
|
+
New here? The [quickstart notebook](https://github.com/azhir/azar-run-flow/blob/main/examples/quickstart.ipynb) walks through it
|
|
37
|
+
in a few minutes: two MLP variants trained, compared and watched live in the MLflow UI.
|
|
38
|
+
|
|
39
|
+
## Track an experiment
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import hydra
|
|
43
|
+
from omegaconf import DictConfig
|
|
44
|
+
from azar_run_flow import run_experiment
|
|
45
|
+
|
|
46
|
+
def experiment(run, cfg: dict):
|
|
47
|
+
for step in range(cfg["steps"]):
|
|
48
|
+
loss = ...
|
|
49
|
+
run.metric("loss", loss, step=step)
|
|
50
|
+
run.figure("curve.png", fig) # also: run.array, run.json, run.text,
|
|
51
|
+
run.checkpoint("model.pt") # run.artifact, run.tag, run.metrics
|
|
52
|
+
return {"loss": loss}
|
|
53
|
+
|
|
54
|
+
@hydra.main(config_path="configs", config_name="config", version_base=None)
|
|
55
|
+
def main(cfg: DictConfig):
|
|
56
|
+
run_experiment(experiment, config=cfg, experiment_name=cfg.experiment_name)
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
main()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
python train.py # defaults
|
|
64
|
+
python train.py model.depth=8 optim.lr=3e-4 # override anything
|
|
65
|
+
python train.py -m optim.lr=1e-3,3e-4 seed=0,1 # sweep: one MLflow run per combination
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A complete example is in [examples/hydra_app/](https://github.com/azhir/azar-run-flow/blob/main/examples/hydra_app/).
|
|
69
|
+
`azar_run(config=...)` is the context-manager form when you don't want a function.
|
|
70
|
+
|
|
71
|
+
### What every run records
|
|
72
|
+
|
|
73
|
+
| Where in MLflow | What |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| params | every scalar config value (`model.depth`, `optim.lr`, …), searchable |
|
|
76
|
+
| `config/resolved.yaml`, `config/overrides.txt` | the full resolved config and the exact Hydra overrides |
|
|
77
|
+
| tags `git_commit`, `git_branch`, `git_dirty` | code version |
|
|
78
|
+
| `provenance/git_diff.patch`, `git_status.txt` | uncommitted changes, when the tree is dirty |
|
|
79
|
+
| `provenance/provenance.json`, `packages.txt` | command line, seed, host, Python, every installed package |
|
|
80
|
+
| tag `seed` | the seed applied to `random`, NumPy and PyTorch: `seed=` argument, else the config's `seed`, else freshly drawn |
|
|
81
|
+
| metric `runtime_seconds`, `system/*` | duration; CPU, memory and GPU utilisation/memory/power over time |
|
|
82
|
+
| tag `azar.status` + run status | `completed`/FINISHED, `failed`/FAILED (with `failure/traceback.txt`) or `killed`/KILLED |
|
|
83
|
+
|
|
84
|
+
## Monitor
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
uv run azar ui # MLflow UI on ./mlflow.db at http://127.0.0.1:5050
|
|
88
|
+
uv run azar ui --tailscale # the same, for your other devices: http://<machine>:5050
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Opening the UI when the code runs on another machine** (a GPU server, VS Code Remote-SSH):
|
|
92
|
+
|
|
93
|
+
- **Tailscale** (simplest, when the machines are on the same tailnet): start it with
|
|
94
|
+
`azar ui --tailscale` (or `make ui-tailscale`) and open the printed address, e.g.
|
|
95
|
+
`http://gpubox:5050`, from your laptop or phone. The UI has no login, so every
|
|
96
|
+
device on your tailnet can view and delete runs: use this on a tailnet you trust.
|
|
97
|
+
- **VS Code Remote-SSH**: start `azar ui`, open the **Ports** panel, and open the
|
|
98
|
+
*Forwarded Address* of port 5050 (usually `localhost:5050`).
|
|
99
|
+
|
|
100
|
+
Opening the machine's own address without `--tailscale` fails: the UI then listens
|
|
101
|
+
only on 127.0.0.1, and MLflow refuses unknown host names (HTTP 403). The default port
|
|
102
|
+
is 5050, not MLflow's 5000, because macOS uses port 5000 for the AirPlay Receiver.
|
|
103
|
+
|
|
104
|
+
Runs go to `$MLFLOW_TRACKING_URI`, default `sqlite:///mlflow.db` in the directory
|
|
105
|
+
you start from. Set it once per project (e.g. in your shell or `.envrc`) so every
|
|
106
|
+
run lands in the same store:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
export MLFLOW_TRACKING_URI=sqlite:///$HOME/research/myproject/mlflow.db
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A SQLite store handles one workstation well, including parallel jobs. To watch runs
|
|
113
|
+
from another machine, run an MLflow server on the store and point
|
|
114
|
+
`MLFLOW_TRACKING_URI` at it (`http://host:5000`); nothing else changes.
|
|
115
|
+
|
|
116
|
+
## Schedule
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
azar submit --gpus 1 --timeout 12h -- python train.py model.depth=8 # prints a job id
|
|
120
|
+
azar submit --gpus 1 --retries 2 --name big -- python train.py model.depth=16
|
|
121
|
+
for lr in 1e-3 3e-4 1e-4; do azar submit --gpus 1 -- python train.py optim.lr=$lr; done
|
|
122
|
+
|
|
123
|
+
azar worker --slots 2 # runs jobs, 2 at a time; Ctrl-C stops it (jobs -> interrupted)
|
|
124
|
+
azar status # pending, running and recent jobs
|
|
125
|
+
azar logs JOB -f # follow a job's output (any unique id prefix works)
|
|
126
|
+
azar cancel JOB # pending: removed; running: SIGTERM, then SIGKILL after 30 s
|
|
127
|
+
azar retry JOB # queue a finished job again
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- A job runs exactly as if you had run it at submit time: same directory, same
|
|
131
|
+
environment variables. `CUDA_VISIBLE_DEVICES` is set to the GPUs it was given
|
|
132
|
+
(empty for `--gpus 0`).
|
|
133
|
+
- Jobs start in submission order as soon as the GPUs they need are free. A GPU is
|
|
134
|
+
never given to two jobs, across workers and even after a worker crashes.
|
|
135
|
+
- Each job's MLflow runs carry the tag `azar.job_id`. Its output is in
|
|
136
|
+
`$AZAR_HOME/jobs/<id>/attempt<N>.log`.
|
|
137
|
+
- The queue lives in `$AZAR_HOME` (default `./.azar`). Use the same `AZAR_HOME` for
|
|
138
|
+
`submit` and `worker`; for one queue across projects, `export AZAR_HOME=~/azar`.
|
|
139
|
+
- `azar worker --gpus 0,1` restricts a worker to some GPUs. To keep a worker running
|
|
140
|
+
after you log out, start it in `tmux` (or as a service).
|
|
141
|
+
|
|
142
|
+
## Reproduce a run
|
|
143
|
+
|
|
144
|
+
Everything needed is attached to the run in MLflow:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
git checkout <git_commit tag>
|
|
148
|
+
git apply provenance/git_diff.patch # only if git_dirty is True
|
|
149
|
+
uv sync --locked # the environment, if uv.lock is committed
|
|
150
|
+
python train.py $(cat config/overrides.txt)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The seed comes back with the config (or pass the recorded `seed` tag as
|
|
154
|
+
`seed=<value>`). On the same machine and software this reproduces CPU results
|
|
155
|
+
exactly; GPU kernels can differ slightly between runs unless you also enable
|
|
156
|
+
`torch.use_deterministic_algorithms(True)`. Untracked files are listed in
|
|
157
|
+
`git_status.txt` but not saved, so commit new source files before important runs.
|
|
158
|
+
|
|
159
|
+
## Robustness guarantees
|
|
160
|
+
|
|
161
|
+
Each is covered by a test in `tests/`:
|
|
162
|
+
|
|
163
|
+
- Parallel processes can start using a fresh SQLite store at the same time; without
|
|
164
|
+
the initialisation lock, plain MLflow corrupts the database.
|
|
165
|
+
- A run never stays RUNNING after it ends: Ctrl-C and SIGTERM (timeouts, `kill`,
|
|
166
|
+
cluster schedulers) close it as KILLED, and the scheduler closes runs of jobs that
|
|
167
|
+
were SIGKILLed or died.
|
|
168
|
+
- A tracking error while recording a failure never hides the experiment's own error.
|
|
169
|
+
- Artifacts always live next to their SQLite store (`mlruns/`), not in whatever
|
|
170
|
+
directory a run started in; `hydra.job.chdir=true` does not create a second store.
|
|
171
|
+
- Queue state changes are atomic renames; a crashed worker's job is filed as `lost`
|
|
172
|
+
and never silently re-run; timeouts and cancellation kill the job's whole process
|
|
173
|
+
group, including data-loader workers.
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
To work on azar-run-flow itself:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
git clone https://github.com/azhir/azar-run-flow && cd azar-run-flow
|
|
181
|
+
uv sync --locked --extra dev # isolated Python 3.12 env in .venv (see CLAUDE.md)
|
|
182
|
+
make test # uv run pytest -q, about 2 minutes
|
|
183
|
+
make example # run the example into ./.azar/mlflow.db
|
|
184
|
+
make ui # browse it
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
To use a local checkout from another project while changing it:
|
|
188
|
+
`pip install -e path/to/azar-run-flow` (or `uv add --editable path/to/azar-run-flow`).
|
|
189
|
+
The quickstart notebook needs `uv sync --locked --extra dev --extra notebook`.
|
|
190
|
+
|
|
191
|
+
**Releasing.** Bump `version` in `pyproject.toml`, merge to `main`, then
|
|
192
|
+
`git tag vX.Y.Z && git push origin vX.Y.Z`. The GitHub workflow tests, builds and
|
|
193
|
+
publishes the release to PyPI.
|
|
194
|
+
|
|
195
|
+
Design: [ARCHITECTURE.md](https://github.com/azhir/azar-run-flow/blob/main/ARCHITECTURE.md). Plans: [ROADMAP.md](https://github.com/azhir/azar-run-flow/blob/main/ROADMAP.md).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "azar-run-flow"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "Robust, reproducible experiment tracking and scheduling for research code (Hydra + MLflow)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "azhir" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
keywords = ["machine learning", "research", "experiment tracking", "mlflow", "hydra", "reproducibility", "gpu", "job queue"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
19
|
+
"Operating System :: POSIX :: Linux",
|
|
20
|
+
"Operating System :: MacOS",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Programming Language :: Python :: 3.15",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
dependencies = [
|
|
31
|
+
"mlflow>=3,<4",
|
|
32
|
+
"numpy>=1.23",
|
|
33
|
+
"psutil>=5.9", # MLflow system metrics (CPU, memory, disk, network)
|
|
34
|
+
"nvidia-ml-py>=12", # MLflow system metrics (GPU); harmless without a GPU
|
|
35
|
+
"hydra-core>=1.3,<1.4",
|
|
36
|
+
"omegaconf>=2.3,<2.4",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/azhir/azar-run-flow"
|
|
41
|
+
Source = "https://github.com/azhir/azar-run-flow"
|
|
42
|
+
Issues = "https://github.com/azhir/azar-run-flow/issues"
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
azar = "azar_run_flow.cli:main"
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
zen = [
|
|
49
|
+
"hydra-zen>=0.16,<0.17",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
dev = [
|
|
53
|
+
"pytest>=8",
|
|
54
|
+
"hydra-zen>=0.16,<0.17",
|
|
55
|
+
"matplotlib>=3.6", # examples/hydra_app, used by the tests
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
notebook = [
|
|
59
|
+
"ipykernel>=6", # run examples/quickstart.ipynb with the project's .venv as kernel
|
|
60
|
+
"matplotlib>=3.6",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[tool.setuptools.packages.find]
|
|
64
|
+
where = ["src"]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
addopts = "--basetemp=.azar/pytest"
|
|
69
|
+
markers = ["slow: tests that start servers or long-running subprocesses"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
from .runner import (
|
|
4
|
+
Run,
|
|
5
|
+
azar_run,
|
|
6
|
+
run_experiment,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
__version__ = version("azar-run-flow")
|
|
11
|
+
except PackageNotFoundError: # imported from a source tree that is not installed
|
|
12
|
+
__version__ = "unknown"
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Run",
|
|
16
|
+
"azar_run",
|
|
17
|
+
"run_experiment",
|
|
18
|
+
]
|