Ver código fonte

sync model loading, disabled model ttl by default

mertalev 2 anos atrás
pai
commit
d88030c132

+ 1 - 1
machine-learning/app/config.py

@@ -13,7 +13,7 @@ class Settings(BaseSettings):
     facial_recognition_model: str = "buffalo_l"
     min_tag_score: float = 0.9
     eager_startup: bool = True
-    model_ttl: int = 300
+    model_ttl: int = 0
     host: str = "0.0.0.0"
     port: int = 3003
     workers: int = 1

+ 1 - 5
machine-learning/app/models/cache.py

@@ -1,4 +1,3 @@
-import asyncio
 from typing import Any
 
 from aiocache.backends.memory import SimpleMemoryCache
@@ -51,10 +50,7 @@ class ModelCache:
         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),
-                )
+                model = InferenceModel.from_model_type(model_type, model_name, **model_kwargs)
                 await lock.cas(model, ttl=self.ttl)
         return model