Repository navigation
[Feature] ML: compile/warm models at startup, then release them (preload without pinning) #33710
Replies: 2 comments 2 replies
|
This seems kind of pointless to do, as after the first time the model would be cached just fine already.
This doesn't seem right to me, are you sure you're keeping the model cache correctly? |
|
Thanks for looking. The cache is persisted (./model-cache:/cache) and works: on a normal restart nothing recompiles, and the warm-up just loads everything in ~13 s. My wording was too broad, sorry. It's not every update: a compiled model is reused only while the manifest facts in sessions/ort.py match (ORT version, the loaded libmigraphx/libamdhip64, the rewrite plan digest, options/overrides). When an update changes one of those, or when I switch models or change the OCR resolution, the recompile happens inside the first real request: a search waits ~1 min, and an OCR job waits minutes per shape. So the request isn't about caching. It's about moving that occasional compile to startup without the memory cost. Today the only way to do that is PRELOAD, which keeps every model resident forever (3.3–8 GB here, vs ~128 MiB idle with load-on-demand). A "prepare, then release" preload mode would give both. I understand if that's too niche a use case for you, but it would be nice to have Immich running without the memory toll while making sure the models are already compiled when I need them. Loading them takes a few seconds instead of minutes to compile. |
Uh oh!
There was an error while loading. Please reload this page.
I have searched the existing feature requests, both open and closed, to make sure this is not a duplicate request.
The feature
An option for the machine-learning container to prepare every configured model at startup (download, and for MIGraphX/TensorRT/OpenVINO compile every shape) and then release them, instead of keeping them loaded. For example:
MACHINE_LEARNING_PRELOAD_MODE=warm(defaultkeep): run the existingMACHINE_LEARNING_PRELOAD__*logic, then unload soMACHINE_LEARNING_MODEL_TTLapplies as usual; orpython -m immich_ml --preload-onlythat runs the preload and exits, for use as a compose init service.Why
Today there are two choices, and with a compiled execution provider both have a cost:
idle_shutdown_taskrestarts the worker after the TTL, and the restart preloads every model again. (Preload does not setlast_called, so the idle timer only starts after the first real request, but after that every idle restart reloads everything.)What users with GPU backends want is: compile at startup, load on demand, free when idle.
Measurements (Radeon 760M iGPU, ROCm image, MIGraphX, ViT-B-16-SigLIP2__webli + buffalo_l + PP-OCRv5_mobile)
So load-on-demand costs a few seconds once compiled, but an uncompiled model costs minutes.
Current workaround
A one-shot compose service with the same image, cache volume, devices and env as
immich-machine-learning, plus thePRELOADvariables, which calls the internal function and exits; the ML servicedepends_onit withcondition: service_completed_successfully:With everything compiled it takes ~13 s and then exits, freeing its memory. It works, but it depends on
immich_ml.main.preload_models, which is internal and may change in any release.Related: #22502, #27407 (pre-warm on app open), #28459 (per-model TTL). In those, the answer was PRELOAD, which pins models in memory; this request is about the case where that is not wanted.
Platform
All reactions