Skip to content

Commit

Permalink
fix: error of using cpu_offloading before deepcache
Browse files Browse the repository at this point in the history
test result shows deepcache should be loaded before cpu_offloading
if not, may cause issues like
horseee/DeepCache#23
vladmandic/automatic#2888

Signed-off-by: wxiwnd <[email protected]>
  • Loading branch information
wxiwnd authored and frostyplanet committed Sep 27, 2024
1 parent 7ff4245 commit f56066d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions xinference/model/image/stable_diffusion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,24 @@ def load(self):
self._model_path,
**self._kwargs,
)
if self._kwargs.get("deepcache", True):
# NOTE: DeepCache should be loaded first before cpu_offloading
try:
from DeepCache import DeepCacheSDHelper

helper = DeepCacheSDHelper(pipe=self._model)
helper.set_params(cache_interval=3, cache_branch_id=0)
helper.enable()
except ImportError:
logger.debug("deepcache is not installed")
pass

if self._kwargs.get("cpu_offload", False):
logger.debug("CPU offloading model")
self._model.enable_model_cpu_offload()
elif not self._kwargs.get("device_map"):
logger.debug("Loading model to available device")
self._model = move_model_to_available_device(self._model)
try:
from DeepCache import DeepCacheSDHelper

helper = DeepCacheSDHelper(pipe=self._model)
helper.set_params(cache_interval=3, cache_branch_id=0)
helper.enable()
except:
pass
# Recommended if your computer has < 64 GB of RAM
self._model.enable_attention_slicing()
self._apply_lora()
Expand Down

0 comments on commit f56066d

Please sign in to comment.