-
Couldn't load subscription status.
- Fork 6.5k
[Modular] Qwen #12220
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
Merged
Merged
[Modular] Qwen #12220
Changes from 21 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3bd289f
initial
yiyixuxu fa1a9cd
Merge branch 'main' into modular-qwen
yiyixuxu 44e058c
up up
yiyixuxu ff06e95
Merge branch 'main' into modular-qwen
yiyixuxu 49e683f
start to work on edit
yiyixuxu f72763c
add support for qwen edit
yiyixuxu 57a1bc6
first dynamic block!
yiyixuxu 5fbc817
add controlnet support!
yiyixuxu 100122c
style
yiyixuxu 84dbf17
up
yiyixuxu 0a9f7f9
up
yiyixuxu 4483400
up up
yiyixuxu a562806
style
yiyixuxu 30faada
Merge branch 'main' into modular-qwen
yiyixuxu 2d5d876
Apply suggestions from code review
yiyixuxu b89cc40
up
yiyixuxu 8dce330
add inpaint processor to doc
yiyixuxu d16b7b9
refactor!
yiyixuxu dd8d0f6
add auto pipeline blocks, guider support
yiyixuxu 2c05729
style + copies
yiyixuxu 78f0038
Merge branch 'main' into modular-qwen
yiyixuxu 7bf9730
qwen modular work with standard repo
yiyixuxu cd3a6a6
style
yiyixuxu 5ecbbff
support edit inpaint!
yiyixuxu ef66598
style
yiyixuxu eed3ae0
qwen image edit autopipeline!
yiyixuxu a95651a
up up
yiyixuxu 4efac2c
style
yiyixuxu 1668c77
up up some refactor
yiyixuxu 5b408fa
img2img
yiyixuxu a7414e6
more refactor
yiyixuxu 675ae14
up
yiyixuxu 6bf38c8
Apply suggestions from code review
yiyixuxu 0e9c496
docstring etc
yiyixuxu f97e24a
style + copy
yiyixuxu 7084119
fix
yiyixuxu 9c5830e
fix more docs5rings
yiyixuxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -838,6 +838,134 @@ def apply_overlay( | |
| return image | ||
|
|
||
|
|
||
| class InpaintProcessor(ConfigMixin): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really nice! (not for this PR, we could attempt to have an example of the processor for an inpaint pipeline) |
||
| """ | ||
| Image processor for inpainting image and mask. | ||
| """ | ||
|
|
||
| config_name = CONFIG_NAME | ||
|
|
||
| @register_to_config | ||
| def __init__( | ||
| self, | ||
| do_resize: bool = True, | ||
| vae_scale_factor: int = 8, | ||
| vae_latent_channels: int = 4, | ||
| resample: str = "lanczos", | ||
| reducing_gap: int = None, | ||
| do_normalize: bool = True, | ||
| do_binarize: bool = False, | ||
| do_convert_grayscale: bool = False, | ||
| mask_do_normalize: bool = False, | ||
| mask_do_binarize: bool = True, | ||
| mask_do_convert_grayscale: bool = True, | ||
| ): | ||
| super().__init__() | ||
|
|
||
| self._image_processor = VaeImageProcessor( | ||
| do_resize=do_resize, | ||
| vae_scale_factor=vae_scale_factor, | ||
| vae_latent_channels=vae_latent_channels, | ||
| resample=resample, | ||
| reducing_gap=reducing_gap, | ||
| do_normalize=do_normalize, | ||
| do_binarize=do_binarize, | ||
| do_convert_grayscale=do_convert_grayscale, | ||
| ) | ||
| self._mask_processor = VaeImageProcessor( | ||
| do_resize=do_resize, | ||
| vae_scale_factor=vae_scale_factor, | ||
| vae_latent_channels=vae_latent_channels, | ||
| resample=resample, | ||
| reducing_gap=reducing_gap, | ||
| do_normalize=mask_do_normalize, | ||
| do_binarize=mask_do_binarize, | ||
| do_convert_grayscale=mask_do_convert_grayscale, | ||
| ) | ||
|
|
||
| def preprocess( | ||
| self, | ||
| image: PIL.Image.Image, | ||
| mask: PIL.Image.Image = None, | ||
| height: int = None, | ||
| width: int = None, | ||
| padding_mask_crop: Optional[int] = None, | ||
| ) -> Tuple[torch.Tensor, torch.Tensor]: | ||
| """ | ||
| Preprocess the image and mask. | ||
| """ | ||
| if mask is None and padding_mask_crop is not None: | ||
| raise ValueError("mask must be provided if padding_mask_crop is provided") | ||
|
|
||
| # if mask is None, same behavior as regular image processor | ||
| if mask is None: | ||
| return self._image_processor.preprocess(image, height=height, width=width) | ||
|
|
||
| if padding_mask_crop is not None: | ||
| crops_coords = self._image_processor.get_crop_region(mask, width, height, pad=padding_mask_crop) | ||
| resize_mode = "fill" | ||
| else: | ||
| crops_coords = None | ||
| resize_mode = "default" | ||
|
|
||
| processed_image = self._image_processor.preprocess( | ||
| image, | ||
| height=height, | ||
| width=width, | ||
| crops_coords=crops_coords, | ||
| resize_mode=resize_mode, | ||
| ) | ||
|
|
||
| processed_mask = self._mask_processor.preprocess( | ||
| mask, | ||
| height=height, | ||
| width=width, | ||
| resize_mode=resize_mode, | ||
| crops_coords=crops_coords, | ||
| ) | ||
|
|
||
| if crops_coords is not None: | ||
| postprocessing_kwargs = { | ||
| "crops_coords": crops_coords, | ||
| "original_image": image, | ||
| "original_mask": mask, | ||
| } | ||
| else: | ||
| postprocessing_kwargs = { | ||
| "crops_coords": None, | ||
| "original_image": None, | ||
| "original_mask": None, | ||
| } | ||
|
|
||
| return processed_image, processed_mask, postprocessing_kwargs | ||
|
|
||
| def postprocess( | ||
| self, | ||
| image: torch.Tensor, | ||
| output_type: str = "pil", | ||
| original_image: Optional[PIL.Image.Image] = None, | ||
| original_mask: Optional[PIL.Image.Image] = None, | ||
| crops_coords: Optional[Tuple[int, int, int, int]] = None, | ||
| ) -> Tuple[PIL.Image.Image, PIL.Image.Image]: | ||
| """ | ||
| Postprocess the image, optionally apply mask overlay | ||
| """ | ||
| image = self._image_processor.postprocess( | ||
| image, | ||
| output_type=output_type, | ||
| ) | ||
| # optionally apply the mask overlay | ||
| if crops_coords is not None and (original_image is None or original_mask is None): | ||
| raise ValueError("original_image and original_mask must be provided if crops_coords is provided") | ||
|
|
||
| elif crops_coords is not None: | ||
| image = [ | ||
| self._image_processor.apply_overlay(original_mask, original_image, i, crops_coords) for i in image | ||
| ] | ||
|
|
||
| return image | ||
|
|
||
|
|
||
| class VaeImageProcessorLDM3D(VaeImageProcessor): | ||
| """ | ||
| Image processor for VAE LDM3D. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import ( | ||
| DIFFUSERS_SLOW_IMPORT, | ||
| OptionalDependencyNotAvailable, | ||
| _LazyModule, | ||
| get_objects_from_module, | ||
| is_torch_available, | ||
| is_transformers_available, | ||
| ) | ||
|
|
||
|
|
||
| _dummy_objects = {} | ||
| _import_structure = {} | ||
|
|
||
| try: | ||
| if not (is_transformers_available() and is_torch_available()): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| from ...utils import dummy_torch_and_transformers_objects # noqa F403 | ||
|
|
||
| _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects)) | ||
| else: | ||
| _import_structure["encoders"] = ["QwenImageTextEncoderStep"] | ||
| _import_structure["modular_blocks"] = [ | ||
| "ALL_BLOCKS", | ||
| "CONTROLNET_BLOCKS", | ||
| "INPAINT_BLOCKS", | ||
| "TEXT2IMAGE_BLOCKS", | ||
| ] | ||
| _import_structure["modular_pipeline"] = ["QwenImageModularPipeline"] | ||
|
|
||
| if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: | ||
| try: | ||
| if not (is_transformers_available() and is_torch_available()): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| from ...utils.dummy_torch_and_transformers_objects import * # noqa F403 | ||
| else: | ||
| from .encoders import ( | ||
| QwenImageTextEncoderStep, | ||
| ) | ||
| from .modular_blocks import ( | ||
| ALL_BLOCKS, | ||
| CONTROLNET_BLOCKS, | ||
| INPAINT_BLOCKS, | ||
| TEXT2IMAGE_BLOCKS, | ||
| ) | ||
| from .modular_pipeline import QwenImageModularPipeline | ||
| else: | ||
| import sys | ||
|
|
||
| sys.modules[__name__] = _LazyModule( | ||
| __name__, | ||
| globals()["__file__"], | ||
| _import_structure, | ||
| module_spec=__spec__, | ||
| ) | ||
|
|
||
| for name, value in _dummy_objects.items(): | ||
| setattr(sys.modules[__name__], name, value) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding. This one is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for guiders/hooks