The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Merge branch 'master' into ipex
藍+85CD05eeaa2de5c7
diff --cc comfy/model_management.pyindex b0123b5fc,7dda073dc..92c59efe7--- a/comfy/model_management.py+++ b/comfy/model_management.py@@@ -13,31 -17,19 +17,26 @@@ set_vram_to = VRAMState.NORMAL_VRAtotal_vram = 0total_vram_available_mb = -1- import sys- import psutil-- forced_cpu = "--cpu" in sys.argv-- set_vram_to = NORMAL_VRAM+ accelerate_enabled = False++xpu_available = Falsetry:import torch- total_vram = torch.cuda.mem_get_info(torch.cuda.current_device())[1] / (1024 * 1024)+ try:+ import intel_extension_for_pytorch as ipex+ if torch.xpu.is_available():+ xpu_available = True+ total_vram = torch.xpu.get_device_properties(torch.xpu.current_device()).total_memory / (1024 * 1024)+ except:+ total_vram = torch.cuda.mem_get_info(torch.cuda.current_device())[1] / (1024 * 1024)total_ram = psutil.virtual_memory().total / (1024 * 1024)- forced_normal_vram = "--normalvram" in sys.argv- if not forced_normal_vram and not forced_cpu:+ if not args.normalvram and not args.cpu:if total_vram <= 4096:print("Trying to enable lowvram mode because your GPU seems to have 4GB or less. If you don't want this use: --normalvram")- set_vram_to = LOW_VRAM+ set_vram_to = VRAMState.LOW_VRAMelif total_vram > total_ram * 1.1 and total_vram > 14336:print("Enabling highvram mode because your GPU has more vram than your computer has ram. If you don't want this use: --normalvram")- vram_state = HIGH_VRAM+ vram_state = VRAMState.HIGH_VRAMexcept:pass@@@ -149,19 -138,16 +146,19 @@@ def load_model_gpu(model)mps_device = torch.device("mps")real_model.to(mps_device)pass- elif vram_state == NORMAL_VRAM or vram_state == HIGH_VRAM:+ elif vram_state == VRAMState.NORMAL_VRAM or vram_state == VRAMState.HIGH_VRAM:model_accelerated = False- real_model.cuda()+ if xpu_available:+ real_model.to("xpu")+ else:+ real_model.cuda()else:- if vram_state == NO_VRAM:+ if vram_state == VRAMState.NO_VRAM:device_map = accelerate.infer_auto_device_map(real_model, max_memory={0: "256MiB", "cpu": "16GiB"})- elif vram_state == LOW_VRAM:+ elif vram_state == VRAMState.LOW_VRAM:device_map = accelerate.infer_auto_device_map(real_model, max_memory={0: "{}MiB".format(total_vram_available_mb), "cpu": "16GiB"})- accelerate.dispatch_model(real_model, device_map=device_map, main_device="cuda")+ accelerate.dispatch_model(real_model, device_map=device_map, main_device="xpu" if xpu_available else "cuda")model_accelerated = Truereturn current_loaded_model@@@ -187,12 -173,8 +184,12 @@@ def load_controlnet_gpu(models)def load_if_low_vram(model):global vram_state+ global xpu_available- if vram_state == LOW_VRAM or vram_state == NO_VRAM:+ if vram_state == VRAMState.LOW_VRAM or vram_state == VRAMState.NO_VRAM:- return model.cuda()+ if xpu_available:+ return model.to("xpu")+ else:+ return model.cuda()return modeldef unload_if_low_vram(model):@@@ -202,16 -184,12 +199,16 @@@return modeldef get_torch_device():+ global xpu_available- if vram_state == MPS:+ if vram_state == VRAMState.MPS:return torch.device("mps")- if vram_state == CPU:+ if vram_state == VRAMState.CPU:return torch.device("cpu")else:- return torch.cuda.current_device()+ if xpu_available:+ return torch.device("xpu")+ else:+ return torch.cuda.current_device()def get_autocast_device(dev):if hasattr(dev, 'type'):@@@ -280,11 -253,10 +277,11 @@@ def cpu_mode()def mps_mode():global vram_state- return vram_state == MPS+ return vram_state == VRAMState.MPSdef should_use_fp16():- if cpu_mode() or mps_mode():+ global xpu_available+ if cpu_mode() or mps_mode() or xpu_available:return False #TODO ?if torch.cuda.is_bf16_supported():