Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow multiple ML models to be preloaded #15418

Merged
merged 46 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b03f186
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
05fda40
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
41d74f0
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
f67c051
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
a5a9cc6
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
cf27958
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
38068e6
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
c378afb
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
3bd2ec6
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
85e17e4
Update config.py
1-tempest Jan 14, 2025
4a22421
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
5679c4f
Add additional variables to preload part ML models
1-tempest Jan 14, 2025
8556c32
Apply formatting
1-tempest Jan 14, 2025
3970aa7
minor update
1-tempest Jan 14, 2025
007db2b
formatting
1-tempest Jan 14, 2025
6c9d173
root validator
1-tempest Jan 14, 2025
6f79390
minor update
1-tempest Jan 14, 2025
47d53b1
minor update
1-tempest Jan 14, 2025
ef3b303
minor update
1-tempest Jan 14, 2025
b4ea6e9
change to support explicit models
1-tempest Jan 14, 2025
12eff16
minor update
1-tempest Jan 14, 2025
233427a
minor change
1-tempest Jan 14, 2025
648851e
minor change
1-tempest Jan 14, 2025
624445b
minor change
1-tempest Jan 14, 2025
e2b5f71
minor update
1-tempest Jan 14, 2025
71527ea
add logs, resolve errors
1-tempest Jan 14, 2025
8cfa055
minor change
1-tempest Jan 14, 2025
85ca87c
add new enviornment variables
1-tempest Jan 14, 2025
1a26a3f
minor revisons
1-tempest Jan 14, 2025
10446e1
remove comments
1-tempest Jan 14, 2025
78dac70
add additional variables to ML (fixed)
1-tempest Jan 16, 2025
9e0fc1b
add additional variables to ML (fixed)
1-tempest Jan 16, 2025
a97e33b
Merge branch 'main' into main
1-tempest Jan 16, 2025
45841bb
add additional variables to ML
1-tempest Jan 16, 2025
77846a1
Merge branch 'main' of https://github.com/1-tempest/immich
1-tempest Jan 16, 2025
aae30f3
formatting
1-tempest Jan 16, 2025
35dd748
remove comment
1-tempest Jan 16, 2025
d862aec
remove mypy error
1-tempest Jan 17, 2025
813ffc7
remove unused module
1-tempest Jan 17, 2025
f599668
merge f strings
1-tempest Jan 17, 2025
ad008bb
Add multi-model preload functionality
1-tempest Jan 18, 2025
3721670
Merge branch 'main' into main
1-tempest Jan 18, 2025
e396c9e
Add type annotation
1-tempest Jan 18, 2025
1660146
Merge branch 'main' of https://github.com/1-tempest/immich
1-tempest Jan 18, 2025
76c18bf
Update machine-learning/app/main.py
1-tempest Jan 19, 2025
86627a9
Update main.py
1-tempest Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/docs/install/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ Redis (Sentinel) URL example JSON before encoding:
| `MACHINE_LEARNING_WORKERS`<sup>\*2</sup> | Number of worker processes to spawn | `1` | machine learning |
| `MACHINE_LEARNING_HTTP_KEEPALIVE_TIMEOUT_S`<sup>\*3</sup> | HTTP Keep-alive time in seconds | `2` | machine learning |
| `MACHINE_LEARNING_WORKER_TIMEOUT` | Maximum time (s) of unresponsiveness before a worker is killed | `120` (`300` if using OpenVINO) | machine learning |
| `MACHINE_LEARNING_PRELOAD__CLIP__TEXTUAL` | Name of the textual CLIP model to be preloaded and kept in cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__CLIP__VISUAL` | Name of the visual CLIP model to be preloaded and kept in cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION__RECOGNITION` | Name of the recognition portion of the facial recognition model to be preloaded and kept in cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION__DETECTION` | Name of the detection portion of the facial recognition model to be preloaded and kept in cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__CLIP__TEXTUAL` | Comma-separated list of (textual) CLIP model(s) to preload and cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__CLIP__VISUAL` | Comma-separated list of (visual) CLIP model(s) to preload and cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION__RECOGNITION` | Comma-separated list of (recognition) facial recognition model(s) to preload and cache | | machine learning |
| `MACHINE_LEARNING_PRELOAD__FACIAL_RECOGNITION__DETECTION` | Comma-separated list of (detection) facial recognition model(s) to preload and cache | | machine learning |
| `MACHINE_LEARNING_ANN` | Enable ARM-NN hardware acceleration if supported | `True` | machine learning |
| `MACHINE_LEARNING_ANN_FP16_TURBO` | Execute operations in FP16 precision: increasing speed, reducing precision (applies only to ARM-NN) | `False` | machine learning |
| `MACHINE_LEARNING_ANN_TUNING_LEVEL` | ARM-NN GPU tuning level (1: rapid, 2: normal, 3: exhaustive) | `2` | machine learning |
Expand Down
18 changes: 10 additions & 8 deletions machine-learning/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,31 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
async def preload_models(preload: PreloadModelData) -> None:
log.info(f"Preloading models: clip:{preload.clip} facial_recognition:{preload.facial_recognition}")

async def load_models(model_string: str, model_type: ModelType, model_task: ModelTask) -> None:
for model_name in model_string.split(","):
model_name = model_name.strip()
model = await model_cache.get(model_name, model_type, model_task)
await load(model)

if preload.clip.textual is not None:
model = await model_cache.get(preload.clip.textual, ModelType.TEXTUAL, ModelTask.SEARCH)
await load(model)
await load_models(preload.clip.textual, ModelType.TEXTUAL, ModelTask.SEARCH)

if preload.clip.visual is not None:
model = await model_cache.get(preload.clip.visual, ModelType.VISUAL, ModelTask.SEARCH)
await load(model)
await load_models(preload.clip.visual, ModelType.VISUAL, ModelTask.SEARCH)

if preload.facial_recognition.detection is not None:
model = await model_cache.get(
await load_models(
preload.facial_recognition.detection,
ModelType.DETECTION,
ModelTask.FACIAL_RECOGNITION,
)
await load(model)

if preload.facial_recognition.recognition is not None:
model = await model_cache.get(
await load_models(
preload.facial_recognition.recognition,
ModelType.RECOGNITION,
ModelTask.FACIAL_RECOGNITION,
)
await load(model)

if preload.clip_fallback is not None:
log.warning(
Expand Down
Loading