1
0
Fork 0

remove oldest items from model cache first

This commit is contained in:
Sean Sube 2023-02-13 18:33:06 -06:00
parent c6b2751cc1
commit c432ab0795
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
5 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,5 @@
from logging import getLogger
from os import path
from typing import Optional
import numpy as np
from gfpgan import GFPGANer

View File

@ -48,7 +48,10 @@ def load_resrgan(
elif params.format == "onnx":
# use ONNX acceleration, if available
model = OnnxNet(
server, model_file, provider=device.provider, provider_options=device.options
server,
model_file,
provider=device.provider,
provider_options=device.options,
)
elif params.format == "pth":
model = RRDBNet(
@ -71,7 +74,9 @@ def load_resrgan(
logger.debug("loading Real ESRGAN upscale model from %s", model_path)
# TODO: shouldn't need the PTH file
model_path_pth = path.join(server.model_path, ".cache", ("%s.pth" % params.upscale_model))
model_path_pth = path.join(
server.model_path, ".cache", ("%s.pth" % params.upscale_model)
)
upsampler = RealESRGANer(
scale=params.scale,
model_path=model_path_pth,

View File

@ -15,7 +15,6 @@ from ..utils import ServerContext, run_gc
logger = getLogger(__name__)
def load_stable_diffusion(
server: ServerContext, upscale: UpscaleParams, device: DeviceParams
):

View File

@ -121,4 +121,10 @@ def apply_patches(ctx: ServerContext):
apply_patch_basicsr(ctx)
apply_patch_codeformer(ctx)
apply_patch_facexlib(ctx)
unload(["basicsr.utils.download_util", "codeformer.facelib.utils.misc", "facexlib.utils"])
unload(
[
"basicsr.utils.download_util",
"codeformer.facelib.utils.misc",
"facexlib.utils",
]
)

View File

@ -43,6 +43,6 @@ class ModelCache:
logger.info(
"Removing models from cache, %s of %s", (total - self.limit), total
)
self.cache[:] = self.cache[: self.limit]
self.cache[:] = self.cache[-self.limit :]
else:
logger.debug("Model cache below limit, %s of %s", total, self.limit)