Commit 19d9ee6
Add MLflow logging support (#66)
* Add MLflow logging support
- Add mlflow_wrapper.py for optional MLflow imports with error handling
- Add mlflow_tracking_uri, mlflow_experiment_name, mlflow_run_name to TrainingArgs
- Update AsyncStructuredLogger to support MLflow logging
- Add MLflow CLI args to api_train.py and train.py
- Initialize MLflow at start, log params, finish at end of training
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Format code with ruff
* Address PR review comments
- Enable MLflow when any MLflow arg is provided (not just tracking_uri)
- Only init/finish MLflow on global rank 0 to avoid multiple runs in multi-node
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix MLflow logging to use explicit run ID
Store the run ID when initializing MLflow and use it explicitly when
logging params/metrics. This fixes an issue where async logging would
lose the thread-local run context and create a separate MLflow run.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix MLflow logging - don't re-start already active run
The previous fix incorrectly tried to start a run in log_params() when
the run was already active from init(). Now log_params() logs directly
since the run is already active, and log() only resumes the run if
it's not currently active (for async contexts).
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Address PR review nitpicks
- Guard dist.get_rank() when process group isn't initialized in async log()
- Add mlflow as optional dependency in pyproject.toml
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Add explicit environment variable fallback for MLflow configuration
Implement kwarg > env var precedence for mlflow_tracking_uri and
mlflow_experiment_name, matching the behavior of instructlab-training.
The configuration now follows this precedence:
1. Explicit kwargs (highest priority)
2. Environment variables (MLFLOW_TRACKING_URI, MLFLOW_EXPERIMENT_NAME)
3. MLflow defaults (lowest priority)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Add async-safe pattern to log_params for thread-local context handling
Mirror the pattern used in log() to handle cases where thread-local
MLflow context is lost in async contexts.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix MLflow run context handling - don't use context manager for resume
Using `with mlflow.start_run(run_id=...)` as a context manager ends the
run when the block exits, breaking subsequent logging calls. Changed to
call start_run() without context manager to keep the run active.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Format mlflow_wrapper.py with ruff
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* guard against active mlflow runs
* comment
* provide instructions when loggers are not available but user requests it
* messaging
* updates
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent f122c80 commit 19d9ee6
File tree
6 files changed
+273
-27
lines changed- src/mini_trainer
6 files changed
+273
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
157 | 167 | | |
158 | 168 | | |
159 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
70 | | - | |
71 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
72 | 82 | | |
73 | | - | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
76 | 95 | | |
77 | 96 | | |
78 | 97 | | |
79 | 98 | | |
80 | 99 | | |
81 | 100 | | |
82 | 101 | | |
83 | | - | |
| 102 | + | |
84 | 103 | | |
85 | 104 | | |
86 | | - | |
| 105 | + | |
87 | 106 | | |
88 | 107 | | |
89 | 108 | | |
| |||
96 | 115 | | |
97 | 116 | | |
98 | 117 | | |
99 | | - | |
| 118 | + | |
100 | 119 | | |
101 | 120 | | |
102 | | - | |
| 121 | + | |
103 | 122 | | |
104 | 123 | | |
105 | | - | |
| 124 | + | |
106 | 125 | | |
107 | 126 | | |
108 | 127 | | |
109 | 128 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
113 | 132 | | |
114 | 133 | | |
115 | | - | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
121 | | - | |
| 140 | + | |
122 | 141 | | |
123 | 142 | | |
124 | 143 | | |
125 | 144 | | |
126 | | - | |
| 145 | + | |
127 | 146 | | |
128 | | - | |
| 147 | + | |
129 | 148 | | |
130 | 149 | | |
131 | 150 | | |
132 | 151 | | |
133 | 152 | | |
134 | 153 | | |
135 | 154 | | |
136 | | - | |
| 155 | + | |
137 | 156 | | |
138 | 157 | | |
139 | 158 | | |
140 | | - | |
| 159 | + | |
141 | 160 | | |
142 | 161 | | |
143 | 162 | | |
144 | | - | |
| 163 | + | |
145 | 164 | | |
146 | | - | |
| 165 | + | |
147 | 166 | | |
148 | 167 | | |
149 | 168 | | |
150 | 169 | | |
151 | 170 | | |
152 | 171 | | |
153 | | - | |
| 172 | + | |
154 | 173 | | |
155 | 174 | | |
156 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
0 commit comments