fix dtype logic

This commit is contained in:
Vladimir Mandic
2023-04-21 15:04:05 -04:00
parent 57204b3d70
commit cf277e7326
4 changed files with 19 additions and 15 deletions
+4
View File
@@ -6,12 +6,16 @@ Stuff to be fixed...
- Fix extensions imports
- ClipSkip not updated on read gen info
- Usage of `sd_vae` in quick settings
- Run VAE with hires at 1280
## Features
Stuff to be added...
- Add Gradio base themes: <https://gradio.app/theming-guide/#using-the-theme-builder>
- Add gradio theme maker
- Create new GitHub hooks/actions for CI/CD
- Move Restart Server from WebUI to Launch and reload modules
- Redo Extensions tab: see <https://vladmandic.github.io/sd-extension-manager/pages/extensions.html>
+12 -10
View File
@@ -54,17 +54,17 @@ def torch_gc():
def set_cuda_params():
if not torch.cuda.is_available():
return
from modules import shared
if torch.backends.cudnn.is_available():
torch.backends.cudnn.benchmark = shared.opts.cudnn_benchmark
torch.backends.cudnn.benchmark_limit = 0
torch.backends.cudnn.allow_tf32 = shared.opts.cuda_allow_tf32
torch.backends.cuda.matmul.allow_tf32 = shared.opts.cuda_allow_tf32
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = shared.opts.cuda_allow_tf16_reduced
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = shared.opts.cuda_allow_tf16_reduced
if torch.cuda.is_available():
torch.backends.cuda.matmul.allow_tf32 = shared.opts.cuda_allow_tf32
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = shared.opts.cuda_allow_tf16_reduced
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = shared.opts.cuda_allow_tf16_reduced
if torch.backends.cudnn.is_available():
torch.backends.cudnn.benchmark = shared.opts.cudnn_benchmark
torch.backends.cudnn.benchmark_limit = 0
torch.backends.cudnn.allow_tf32 = shared.opts.cuda_allow_tf32
global dtype, dtype_vae, dtype_unet, unet_needs_upcast # pylint: disable=global-statement
# set dtype
if shared.opts.cuda_dtype == 'FP16':
dtype = torch.float16
dtype_vae = torch.float16
@@ -73,10 +73,12 @@ def set_cuda_params():
dtype = torch.bfloat16
dtype_vae = torch.bfloat16
dtype_unet = torch.bfloat16
if shared.opts.cuda_dtype == 'FP32':
if shared.opts.cuda_dtype == 'FP32' or shared.opts.no_half:
dtype = torch.float32
dtype_vae = torch.float32
dtype_unet = torch.float32
if shared.opts.no_half_vae: # set dtype again as no-half-vae options take priority
dtype_vae = torch.float32
unet_needs_upcast = shared.opts.upcast_sampling
-5
View File
@@ -403,7 +403,6 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
current_checkpoint_info = shared.sd_model.sd_checkpoint_info
sd_hijack.model_hijack.undo_hijack(shared.sd_model)
shared.sd_model = None
gc.collect()
devices.torch_gc()
@@ -526,9 +525,7 @@ def reload_model_weights(sd_model=None, info=None):
def unload_model_weights(sd_model=None, _info=None):
from modules import sd_hijack
timer = Timer()
if shared.sd_model:
# shared.sd_model.cond_stage_model.to(devices.cpu)
# shared.sd_model.first_stage_model.to(devices.cpu)
shared.sd_model.to(devices.cpu)
@@ -538,9 +535,7 @@ def unload_model_weights(sd_model=None, _info=None):
gc.collect()
devices.torch_gc()
torch.cuda.empty_cache()
print(f"Unloaded weights {timer.summary()}")
return sd_model
@@ -130,6 +130,9 @@ class EmbeddingDatabase:
return embedding
def get_expected_shape(self):
if shared.sd_model is None:
print('Model not loaded')
return 0
vec = shared.sd_model.cond_stage_model.encode_embedding_init_text(",", 1)
return vec.shape[1]