Add Diffusers model and VAE variant loading option

This commit is contained in:
Disty0
2023-07-31 14:39:32 +03:00
parent 20d94af063
commit 8ffaea76ba
5 changed files with 23 additions and 6 deletions
+4 -1
View File
@@ -572,7 +572,10 @@
{"id":"","label":"Enable model CPU offload","localized":"","hint":"Transferring of entire models to the GPU, negligible impact on inference time while still providing some memory savings. Use with Enable Attention slicing for additional memory savings"},
{"id":"","label":"Enable VAE slicing","localized":"","hint":"Decodes batch latents one image at a time with limited VRAM. Small performance boost in VAE decode on multi-image batches. Use with Enable Attention slicing"},
{"id":"","label":"Enable VAE tiling","localized":"","hint":"Divide large images into overlapping tiles with limited VRAM. Might result in a minor increase in processing time. Use with Enable Attention Slicing"},
{"id":"","label":"Enable attention slicing","localized":"","hint":"Performs attention computation in steps instead of all at once. 10% slower inference times. Greatly reduces memory usage. Best used, period"}
{"id":"","label":"Enable attention slicing","localized":"","hint":"Performs attention computation in steps instead of all at once. 10% slower inference times. Greatly reduces memory usage. Best used, period"},
{"id":"","label":"Diffusers model loading variant","localized":"","hint":""},
{"id":"","label":"Diffusers VAE loading variant","localized":"","hint":""}
],
"scripts": [
{"id":"","label":"Script","localized":"","hint":""},
+3 -1
View File
@@ -572,7 +572,9 @@
{"id":"","label":"Enable model CPU offload","localized":"모델 CPU 오프로드 활성화","hint":"전체 모델을 GPU로 옮긴다. 여전히 GPU 메모리 사용률을 약간 낮춰주지만 생성 속도에는 무시할 수 있는 정도의 영향을 준다. 추가적인 메모리 절약을 위해서는 어텐션 슬라이싱과 함께 사용한다."},
{"id":"","label":"Enable VAE slicing","localized":"VAE 슬라이싱 활성화","hint":"Decodes batch latents one image at a time with limited VRAM. 여러 이미지를 다룰 때 VAE 해독 시 작은 성능 향상이 있다. 어텐션 슬라이싱과 함께 사용한다."},
{"id":"","label":"Enable VAE tiling","localized":"VAE 타일링 활성화","hint":"Divide large images into overlapping tiles with limited VRAM. 생성 시간이 약간 늘어날 수 있다. 어텐션 슬라이싱과 함께 사용한다."},
{"id":"","label":"Enable attention slicing","localized":"어텐션 슬라이싱 활성화","hint":"Performs attention computation in steps instead of all at once. 생성이 10% 느려지지만 메모리 사용률을 매우 크게 줄여준다."}
{"id":"","label":"Enable attention slicing","localized":"어텐션 슬라이싱 활성화","hint":"Performs attention computation in steps instead of all at once. 생성이 10% 느려지지만 메모리 사용률을 매우 크게 줄여준다."},
{"id":"","label":"Diffusers model loading variant","localized":"","hint":""},
{"id":"","label":"Diffusers VAE loading variant","localized":"","hint":""}
],
"scripts": [
{"id":"","label":"Script","localized":"스크립트","hint":""},
+7 -2
View File
@@ -548,8 +548,13 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No
"load_connected_pipeline": True # always load end-to-end / connected pipelines
# "use_safetensors": True, # TODO(PVP) - we can't enable this for all checkpoints just yet
}
if devices.dtype == torch.float16:
diffusers_load_config['variant'] = 'fp16'
if shared.opts.diffusers_model_load_variant == 'default':
if devices.dtype == torch.float16:
diffusers_load_config['variant'] = 'fp16'
elif shared.opts.diffusers_model_load_variant == 'fp32':
pass
else:
diffusers_load_config['variant'] = shared.opts.diffusers_model_load_variant
if shared.opts.data.get('sd_model_checkpoint', '') == 'model.ckpt' or shared.opts.data.get('sd_model_checkpoint', '') == '':
shared.opts.data['sd_model_checkpoint'] = "runwayml/stable-diffusion-v1-5"
+7 -2
View File
@@ -181,8 +181,13 @@ def load_vae_diffusers(_model, vae_file=None, vae_source="from unknown source"):
"torch_dtype": devices.dtype_vae,
"use_safetensors": True,
}
if devices.dtype_vae == torch.float16:
diffusers_load_config['variant'] = 'fp16'
if shared.opts.diffusers_vae_load_variant == 'default':
if devices.dtype_vae == torch.float16:
diffusers_load_config['variant'] = 'fp16'
elif shared.opts.diffusers_vae_load_variant == 'fp32':
pass
else:
diffusers_load_config['variant'] = shared.opts.diffusers_vae_load_variant
if shared.opts.diffusers_vae_upcast != 'default':
diffusers_load_config['force_upcast'] = True if shared.opts.diffusers_vae_upcast == 'true' else False
+2
View File
@@ -407,6 +407,8 @@ options_templates.update(options_section(('diffusers', "Diffusers Settings"), {
"diffusers_vae_slicing": OptionInfo(True, "Enable VAE slicing"),
"diffusers_vae_tiling": OptionInfo(False, "Enable VAE tiling"),
"diffusers_attention_slicing": OptionInfo(False, "Enable attention slicing"),
"diffusers_model_load_variant": OptionInfo("default", "Diffusers model loading variant", gr.Radio, lambda: {"choices": ['default', 'fp32', 'fp16']}),
"diffusers_vae_load_variant": OptionInfo("default", "Diffusers VAE loading variant", gr.Radio, lambda: {"choices": ['default', 'fp32', 'fp16']}),
# "diffusers_force_zeros": OptionInfo(False, "Force zeros for prompts when empty"),
# "diffusers_aesthetics_score": OptionInfo(6.0, "Require aesthetic score", gr.Slider, {"minimum": 0, "maximum": 10, "step": 0.1}),
}))