Commit 9784506
authored
Support MLFlow Handler for single process/multi task enviornment (#5728)
Signed-off-by: Sachidanand Alle <sachidanand.alle@gmail.com>
Current MLFlow Handler fails when you invoke 2 train requests back to
back with different URI. Or multiple train requests within the same
process. This is mainly for using global array where it saves active
experiment, active run and others share the same. This will cause
conflicts between 2 invokes with 2 different URI.
Fixes
------
- Use MLFlow Client to create experiment/runs instead of global
functions.
- Save the current run through the lifecycle of handler. If any handler
has the same experiment name and same run name, the metrics all will be
merged as part of the same run (e.g. train and validation handler).
- If the run name is not provided (fall back on default) then last
active run within the same experiment (sorted based on start time) is
used for adding the metrics.
The above two conditions will help create similar behavior compared to
using `mlflow.active_run()`
Verified
---------
- Running single and multi gpu training on bundles
- spleen_ct_segmentation_v0.1.0
- spleen_deepedit_annotation_v0.1.0
- swin_unetr_btcv_segmentation_v0.1.0
- Running Training workflows for both single and multi gpu in MONAI
Label
- Verified against running shared/single tracking URI (where all the
experiments get saved)
- Verified against individual eval/mlruns per bundle/workflow
> I suggest, original owner of this handler to verify/test all the
behaviors that were currently supported.
Error Description
---------
Error stack when you run two train workflows with in the same process
(simply one after another).
```
[2022-12-13 21:08:11,095] [4047823] [MainThread] [ERROR] (uvicorn.error:369) - Exception in ASGI application
Traceback (most recent call last):
File "/localhome/sachi/.local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 366, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
return await self.app(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/fastapi/applications.py", line 199, in __call__
await super().__call__(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 78, in __call__
await self.app(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/routing.py", line 580, in __call__
await route.handle(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/routing.py", line 241, in handle
await self.app(scope, receive, send)
File "/localhome/sachi/.local/lib/python3.10/site-packages/starlette/routing.py", line 52, in app
response = await func(request)
File "/localhome/sachi/.local/lib/python3.10/site-packages/fastapi/routing.py", line 219, in app
raw_response = await run_endpoint_function(
File "/localhome/sachi/.local/lib/python3.10/site-packages/fastapi/routing.py", line 152, in run_endpoint_function
return await dependant.call(**values)
File "/localhome/sachi/Projects/monailabel/monailabel/endpoints/train.py", line 96, in api_run_model
return run_model(model, params, run_sync, enqueue)
File "/localhome/sachi/Projects/monailabel/monailabel/endpoints/train.py", line 55, in run_model
res, detail = AsyncTask.run("train", request=request, params=params, force_sync=run_sync, enqueue=enqueue)
File "/localhome/sachi/Projects/monailabel/monailabel/utils/async_tasks/task.py", line 43, in run
return instance.train(request), None
File "/localhome/sachi/Projects/monailabel/monailabel/interfaces/app.py", line 422, in train
result = task(request, self.datastore())
File "/localhome/sachi/Projects/monailabel/monailabel/tasks/train/basic_train.py", line 458, in __call__
res = self.train(0, world_size, req, datalist)
File "/localhome/sachi/Projects/monailabel/monailabel/tasks/train/basic_train.py", line 545, in train
context.trainer.run()
File "/localhome/sachi/Projects/MONAI/monai/engines/trainer.py", line 53, in run
super().run()
File "/localhome/sachi/Projects/MONAI/monai/engines/workflow.py", line 281, in run
super().run(data=self.data_loader, max_epochs=self.state.max_epochs)
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 892, in run
return self._internal_run()
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 935, in _internal_run
return next(self._internal_run_generator)
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 993, in _internal_run_as_gen
self._handle_exception(e)
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 636, in _handle_exception
self._fire_event(Events.EXCEPTION_RAISED, e)
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 425, in _fire_event
func(*first, *(event_args + others), **kwargs)
File "/localhome/sachi/Projects/MONAI/monai/handlers/stats_handler.py", line 181, in exception_raised
raise e
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 946, in _internal_run_as_gen
self._fire_event(Events.STARTED)
File "/localhome/sachi/.local/lib/python3.10/site-packages/ignite/engine/engine.py", line 425, in _fire_event
func(*first, *(event_args + others), **kwargs)
File "/localhome/sachi/Projects/MONAI/monai/handlers/mlflow_handler.py", line 183, in start
self._delete_exist_param_in_dict(attrs)
File "/localhome/sachi/Projects/MONAI/monai/handlers/mlflow_handler.py", line 141, in _delete_exist_param_in_dict
log_data = self.client.get_run(cur_run.info.run_id).data
File "/localhome/sachi/.local/lib/python3.10/site-packages/mlflow/tracking/client.py", line 150, in get_run
return self._tracking_client.get_run(run_id)
File "/localhome/sachi/.local/lib/python3.10/site-packages/mlflow/tracking/_tracking_service/client.py", line 72, in get_run
return self.store.get_run(run_id)
File "/localhome/sachi/.local/lib/python3.10/site-packages/mlflow/store/tracking/file_store.py", line 623, in get_run
run_info = self._get_run_info(run_id)
File "/localhome/sachi/.local/lib/python3.10/site-packages/mlflow/store/tracking/file_store.py", line 646, in _get_run_info
raise MlflowException(
mlflow.exceptions.MlflowException: Run '1765aea084a3417586d052d9d8240039' not found
FAILED [ 72%]
```
### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.
Signed-off-by: Sachidanand Alle <sachidanand.alle@gmail.com>1 parent b2359b7 commit 9784506
1 file changed
Lines changed: 59 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
| |||
125 | 123 | | |
126 | 124 | | |
127 | 125 | | |
128 | | - | |
| 126 | + | |
129 | 127 | | |
| 128 | + | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
138 | 141 | | |
139 | | - | |
140 | | - | |
| 142 | + | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
| |||
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
170 | | - | |
171 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
172 | 177 | | |
173 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
174 | 184 | | |
175 | 185 | | |
176 | | - | |
| 186 | + | |
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
180 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
181 | 218 | | |
182 | 219 | | |
183 | 220 | | |
| |||
202 | 239 | | |
203 | 240 | | |
204 | 241 | | |
205 | | - | |
| 242 | + | |
206 | 243 | | |
207 | 244 | | |
208 | | - | |
| 245 | + | |
209 | 246 | | |
210 | 247 | | |
211 | 248 | | |
212 | 249 | | |
213 | 250 | | |
214 | 251 | | |
215 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
216 | 256 | | |
217 | 257 | | |
218 | 258 | | |
| |||
257 | 297 | | |
258 | 298 | | |
259 | 299 | | |
260 | | - | |
| 300 | + | |
261 | 301 | | |
262 | 302 | | |
263 | 303 | | |
264 | | - | |
| 304 | + | |
265 | 305 | | |
266 | 306 | | |
267 | 307 | | |
| |||
281 | 321 | | |
282 | 322 | | |
283 | 323 | | |
284 | | - | |
| 324 | + | |
285 | 325 | | |
286 | 326 | | |
287 | 327 | | |
| |||
291 | 331 | | |
292 | 332 | | |
293 | 333 | | |
294 | | - | |
| 334 | + | |
0 commit comments