mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix(ml): race condition when loading models (#3207)
* sync model loading, disabled model ttl by default * disable revalidation if model unloading disabled * moved lock
This commit is contained in:
parent
9ad024c189
commit
848ba685eb
3 changed files with 6 additions and 10 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from aiocache.backends.memory import SimpleMemoryCache
|
||||
|
|
@ -48,13 +47,10 @@ class ModelCache:
|
|||
"""
|
||||
|
||||
key = self.cache.build_key(model_name, model_type.value)
|
||||
model = await self.cache.get(key)
|
||||
if model is None:
|
||||
async with OptimisticLock(self.cache, key) as lock:
|
||||
model = await asyncio.get_running_loop().run_in_executor(
|
||||
None,
|
||||
lambda: InferenceModel.from_model_type(model_type, model_name, **model_kwargs),
|
||||
)
|
||||
async with OptimisticLock(self.cache, key) as lock:
|
||||
model = await self.cache.get(key)
|
||||
if model is None:
|
||||
model = InferenceModel.from_model_type(model_type, model_name, **model_kwargs)
|
||||
await lock.cas(model, ttl=self.ttl)
|
||||
return model
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue