mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
95cfe22866
* cuda and openvino ep, refactor, update dockerfile * updated workflow * typing fixes * added tests * updated ml test gh action * updated README * updated docker-compose * added compute to hwaccel.yml * updated gh matrix updated gh matrix updated gh matrix updated gh matrix updated gh matrix give up * remove cuda/arm64 build * add hwaccel image tags to docker-compose * remove unnecessary quotes * add suffix to git tag * fixed kwargs in base model * armnn ld_library_path * update pyproject.toml * add armnn workflow * formatting * consolidate hwaccel files, update docker compose * update hw transcoding docs * add ml hwaccel docs * update dev and prod docker-compose * added armnn prerequisite docs * support 3.10 * updated docker-compose comments * formatting * test coverage * don't set arena extend strategy for openvino * working openvino * formatting * fix dockerfile * added type annotation * add wsl configuration for openvino * updated lock file * copy python3 * comment out extends section * fix platforms * simplify workflow suffix tagging * simplify aio transcoding doc * update docs and workflow for `hwaccel.yml` change * revert docs
99 lines
2.6 KiB
Python
99 lines
2.6 KiB
Python
import logging
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
from socket import socket
|
|
|
|
import starlette
|
|
from gunicorn.arbiter import Arbiter
|
|
from pydantic import BaseSettings
|
|
from rich.console import Console
|
|
from rich.logging import RichHandler
|
|
from uvicorn import Server
|
|
from uvicorn.workers import UvicornWorker
|
|
|
|
from .schemas import ModelType
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
cache_folder: str = "/cache"
|
|
model_ttl: int = 300
|
|
model_ttl_poll_s: int = 10
|
|
host: str = "0.0.0.0"
|
|
port: int = 3003
|
|
workers: int = 1
|
|
test_full: bool = False
|
|
request_threads: int = os.cpu_count() or 4
|
|
model_inter_op_threads: int = 0
|
|
model_intra_op_threads: int = 0
|
|
ann: bool = True
|
|
|
|
class Config:
|
|
env_prefix = "MACHINE_LEARNING_"
|
|
case_sensitive = False
|
|
|
|
|
|
class LogSettings(BaseSettings):
|
|
log_level: str = "info"
|
|
no_color: bool = False
|
|
|
|
class Config:
|
|
case_sensitive = False
|
|
|
|
|
|
_clean_name = str.maketrans(":\\/", "___", ".")
|
|
|
|
|
|
def clean_name(model_name: str) -> str:
|
|
return model_name.split("/")[-1].translate(_clean_name)
|
|
|
|
|
|
def get_cache_dir(model_name: str, model_type: ModelType) -> Path:
|
|
return Path(settings.cache_folder) / model_type.value / clean_name(model_name)
|
|
|
|
|
|
def get_hf_model_name(model_name: str) -> str:
|
|
return f"immich-app/{clean_name(model_name)}"
|
|
|
|
|
|
LOG_LEVELS: dict[str, int] = {
|
|
"critical": logging.ERROR,
|
|
"error": logging.ERROR,
|
|
"warning": logging.WARNING,
|
|
"warn": logging.WARNING,
|
|
"info": logging.INFO,
|
|
"log": logging.INFO,
|
|
"debug": logging.DEBUG,
|
|
"verbose": logging.DEBUG,
|
|
}
|
|
|
|
settings = Settings()
|
|
log_settings = LogSettings()
|
|
|
|
|
|
class CustomRichHandler(RichHandler):
|
|
def __init__(self) -> None:
|
|
console = Console(color_system="standard", no_color=log_settings.no_color)
|
|
super().__init__(show_path=False, omit_repeated_times=False, console=console, tracebacks_suppress=[starlette])
|
|
|
|
|
|
log = logging.getLogger("gunicorn.access")
|
|
log.setLevel(LOG_LEVELS.get(log_settings.log_level.lower(), logging.INFO))
|
|
|
|
|
|
# patches this issue https://github.com/encode/uvicorn/discussions/1803
|
|
class CustomUvicornServer(Server):
|
|
async def shutdown(self, sockets: list[socket] | None = None) -> None:
|
|
for sock in sockets or []:
|
|
sock.close()
|
|
await super().shutdown()
|
|
|
|
|
|
class CustomUvicornWorker(UvicornWorker):
|
|
async def _serve(self) -> None:
|
|
self.config.app = self.wsgi
|
|
server = CustomUvicornServer(config=self.config)
|
|
self._install_sigquit_handler()
|
|
await server.serve(sockets=self.sockets)
|
|
if not server.started:
|
|
sys.exit(Arbiter.WORKER_BOOT_ERROR)
|