Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix optimum-quanto version #88

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions multigen/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,22 @@ def __init__(self, *args, pipe: Optional[StableDiffusionImg2ImgPipeline] = None,
def _from_pipe(self, pipe, **args):
cls = pipe.__class__
if 'StableDiffusionXLPipeline' in str(cls) :
return self._classxl(**pipe.components, **args)
return self.__verify_from_pipe(self._classxl, pipe, **args)
elif 'StableDiffusionPipeline' in str(cls):
return self._class(**pipe.components, **args)
return self.__verify_from_pipe(self._class, pipe, **args)
elif 'Flux' in str(cls):
return self._classflux(**pipe.components, **args)
return self.__verify_from_pipe(self._classflux, pipe, **args)
raise RuntimeError(f"can't load pipeline from type {cls}")

def __verify_from_pipe(self, cls, pipe, **args):
allowed = util.get_allowed_components(cls)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now FluxPipeline has empty feature_extractor and image_encoder

source_components = set(pipe.components.keys())
target_components = set(allowed)

logging.debug("Missing components: ", target_components - source_components)
logging.debug("Extra components: ", source_components - target_components)
return cls(**{k: v for (k, v) in pipe.components.items() if k in allowed}, **args)

def setup(self, image=None, image_painted=None, mask=None, blur=4,
blur_compose=4, sample_mode='sample', scale=None, **kwargs):
"""
Expand Down Expand Up @@ -697,12 +706,12 @@ class Cond2ImPipe(BasePipe):
"inpaint": 1.0,
"qr": 1.5
})
cond_scales_defaults_flux = defaultdict(lambda: 0.8,

cond_scales_defaults_flux = defaultdict(lambda: 0.8,
{"canny-dev": 0.6})

def __init__(self, model_id, pipe: Optional[StableDiffusionControlNetPipeline] = None,
ctypes=["soft"], cnets: Optional[List[ControlNetModel]]=None,
ctypes=["soft"], cnets: Optional[List[ControlNetModel]]=None,
cnet_ids: Optional[List[str]]=None, model_type=None, **args):
"""
Constructor
Expand Down
7 changes: 7 additions & 0 deletions multigen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import psutil
from PIL import Image
import copy as cp
from inspect import signature
import optimum.quanto
from optimum.quanto import freeze, qfloat8, quantize as _quantize
from diffusers.utils import is_accelerate_available
Expand Down Expand Up @@ -146,3 +147,9 @@ def weightshare_copy(pipe):
# some buffers might not be transfered from pipe to copy
copy.to(pipe.device)
return copy


def get_allowed_components(cls: type) -> dict:
params = signature(cls.__init__).parameters
components = [name for name in params.keys() if name != 'self']
return components