1
0
Fork 0

fix(api): correct caching for upscaling models

This commit is contained in:
Sean Sube 2023-01-28 00:05:37 -06:00
parent 56a4acee2a
commit ee495a8d93
2 changed files with 8 additions and 3 deletions

View File

@ -28,7 +28,8 @@ def load_resrgan(ctx: ServerContext, params: UpscaleParams, tile=0):
if not path.isfile(model_path):
raise Exception('Real ESRGAN model not found at %s' % model_path)
if last_pipeline_instance != None and (model_path, params.format) == last_pipeline_params:
cache_params = (model_path, params.format)
if last_pipeline_instance != None and cache_params == last_pipeline_params:
print('reusing existing Real ESRGAN pipeline')
return last_pipeline_instance
@ -59,7 +60,7 @@ def load_resrgan(ctx: ServerContext, params: UpscaleParams, tile=0):
half=params.half)
last_pipeline_instance = upsampler
last_pipeline_params = (model_path, params.format)
last_pipeline_params = cache_params
return upsampler

View File

@ -27,8 +27,9 @@ last_pipeline_params = (None, None)
def load_stable_diffusion(ctx: ServerContext, upscale: UpscaleParams):
model_path = path.join(ctx.model_path, upscale.upscale_model)
cache_params = (model_path, upscale.format)
if last_pipeline_instance != None and (model_path, upscale.format) == last_pipeline_params:
if last_pipeline_instance != None and cache_params == last_pipeline_params:
print('reusing existing Stable Diffusion upscale pipeline')
return last_pipeline_instance
@ -47,6 +48,9 @@ def load_stable_diffusion(ctx: ServerContext, upscale: UpscaleParams):
pipeline = StableDiffusionUpscalePipeline.from_pretrained(
'stabilityai/stable-diffusion-x4-upscaler')
last_pipeline_instance = pipeline
last_pipeline_params = cache_params
return pipeline