remove oldest items from model cache first
This commit is contained in:
parent
c6b2751cc1
commit
c432ab0795
|
@ -1,6 +1,5 @@
|
|||
from logging import getLogger
|
||||
from os import path
|
||||
from typing import Optional
|
||||
|
||||
import numpy as np
|
||||
from gfpgan import GFPGANer
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -15,7 +15,6 @@ from ..utils import ServerContext, run_gc
|
|||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
def load_stable_diffusion(
|
||||
server: ServerContext, upscale: UpscaleParams, device: DeviceParams
|
||||
):
|
||||
|
|
|
@ -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",
|
||||
]
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue