mirror of
https://github.com/huggingface/diffusers.git
synced 2025-12-15 08:54:20 +08:00
Compare commits
20 Commits
attention-
...
custom-cod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3f6ba3fc1 | ||
|
|
fb8722e9ab | ||
|
|
512044c5ea | ||
|
|
6c85fcd899 | ||
|
|
085e9cba36 | ||
|
|
919ee1aee3 | ||
|
|
9cda45701c | ||
|
|
c678e8a445 | ||
|
|
d1342d7464 | ||
|
|
9a0cc463ee | ||
|
|
ef4e373a65 | ||
|
|
1b4af6b7ef | ||
|
|
ea77fdc4b4 | ||
|
|
255c5742aa | ||
|
|
4524d43279 | ||
|
|
b6dc0b75f4 | ||
|
|
966a2ff8df | ||
|
|
201da97dd0 | ||
|
|
4423097b23 | ||
|
|
60d1b81023 |
@@ -25,7 +25,6 @@ else:
|
|||||||
_import_structure["modular_pipeline"] = [
|
_import_structure["modular_pipeline"] = [
|
||||||
"ModularPipelineBlocks",
|
"ModularPipelineBlocks",
|
||||||
"ModularPipeline",
|
"ModularPipeline",
|
||||||
"PipelineBlock",
|
|
||||||
"AutoPipelineBlocks",
|
"AutoPipelineBlocks",
|
||||||
"SequentialPipelineBlocks",
|
"SequentialPipelineBlocks",
|
||||||
"LoopSequentialPipelineBlocks",
|
"LoopSequentialPipelineBlocks",
|
||||||
@@ -59,7 +58,6 @@ if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
|
|||||||
LoopSequentialPipelineBlocks,
|
LoopSequentialPipelineBlocks,
|
||||||
ModularPipeline,
|
ModularPipeline,
|
||||||
ModularPipelineBlocks,
|
ModularPipelineBlocks,
|
||||||
PipelineBlock,
|
|
||||||
PipelineState,
|
PipelineState,
|
||||||
SequentialPipelineBlocks,
|
SequentialPipelineBlocks,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from ...models import AutoencoderKL
|
|||||||
from ...schedulers import FlowMatchEulerDiscreteScheduler
|
from ...schedulers import FlowMatchEulerDiscreteScheduler
|
||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ...utils.torch_utils import randn_tensor
|
from ...utils.torch_utils import randn_tensor
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
from .modular_pipeline import FluxModularPipeline
|
from .modular_pipeline import FluxModularPipeline
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ def _get_initial_timesteps_and_optionals(
|
|||||||
return timesteps, num_inference_steps, sigmas, guidance
|
return timesteps, num_inference_steps, sigmas, guidance
|
||||||
|
|
||||||
|
|
||||||
class FluxInputStep(PipelineBlock):
|
class FluxInputStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -249,11 +249,6 @@ class FluxInputStep(PipelineBlock):
|
|||||||
def inputs(self) -> List[InputParam]:
|
def inputs(self) -> List[InputParam]:
|
||||||
return [
|
return [
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"prompt_embeds",
|
"prompt_embeds",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -322,7 +317,7 @@ class FluxInputStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class FluxSetTimestepsStep(PipelineBlock):
|
class FluxSetTimestepsStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -340,14 +335,10 @@ class FluxSetTimestepsStep(PipelineBlock):
|
|||||||
InputParam("timesteps"),
|
InputParam("timesteps"),
|
||||||
InputParam("sigmas"),
|
InputParam("sigmas"),
|
||||||
InputParam("guidance_scale", default=3.5),
|
InputParam("guidance_scale", default=3.5),
|
||||||
|
InputParam("latents", type_hint=torch.Tensor),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
InputParam("height", type_hint=int),
|
InputParam("height", type_hint=int),
|
||||||
InputParam("width", type_hint=int),
|
InputParam("width", type_hint=int),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -398,7 +389,7 @@ class FluxSetTimestepsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class FluxImg2ImgSetTimestepsStep(PipelineBlock):
|
class FluxImg2ImgSetTimestepsStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -420,11 +411,6 @@ class FluxImg2ImgSetTimestepsStep(PipelineBlock):
|
|||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
InputParam("height", type_hint=int),
|
InputParam("height", type_hint=int),
|
||||||
InputParam("width", type_hint=int),
|
InputParam("width", type_hint=int),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -497,7 +483,7 @@ class FluxImg2ImgSetTimestepsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class FluxPrepareLatentsStep(PipelineBlock):
|
class FluxPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -515,11 +501,6 @@ class FluxPrepareLatentsStep(PipelineBlock):
|
|||||||
InputParam("width", type_hint=int),
|
InputParam("width", type_hint=int),
|
||||||
InputParam("latents", type_hint=Optional[torch.Tensor]),
|
InputParam("latents", type_hint=Optional[torch.Tensor]),
|
||||||
InputParam("num_images_per_prompt", type_hint=int, default=1),
|
InputParam("num_images_per_prompt", type_hint=int, default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
@@ -621,7 +602,7 @@ class FluxPrepareLatentsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class FluxImg2ImgPrepareLatentsStep(PipelineBlock):
|
class FluxImg2ImgPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -639,11 +620,6 @@ class FluxImg2ImgPrepareLatentsStep(PipelineBlock):
|
|||||||
InputParam("width", type_hint=int),
|
InputParam("width", type_hint=int),
|
||||||
InputParam("latents", type_hint=Optional[torch.Tensor]),
|
InputParam("latents", type_hint=Optional[torch.Tensor]),
|
||||||
InputParam("num_images_per_prompt", type_hint=int, default=1),
|
InputParam("num_images_per_prompt", type_hint=int, default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"image_latents",
|
"image_latents",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from ...configuration_utils import FrozenDict
|
|||||||
from ...models import AutoencoderKL
|
from ...models import AutoencoderKL
|
||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ...video_processor import VaeImageProcessor
|
from ...video_processor import VaeImageProcessor
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ def _unpack_latents(latents, height, width, vae_scale_factor):
|
|||||||
return latents
|
return latents
|
||||||
|
|
||||||
|
|
||||||
class FluxDecodeStep(PipelineBlock):
|
class FluxDecodeStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -70,17 +70,12 @@ class FluxDecodeStep(PipelineBlock):
|
|||||||
InputParam("output_type", default="pil"),
|
InputParam("output_type", default="pil"),
|
||||||
InputParam("height", default=1024),
|
InputParam("height", default=1024),
|
||||||
InputParam("width", default=1024),
|
InputParam("width", default=1024),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
type_hint=torch.Tensor,
|
type_hint=torch.Tensor,
|
||||||
description="The denoised latents from the denoising step",
|
description="The denoised latents from the denoising step",
|
||||||
)
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from ...utils import logging
|
|||||||
from ..modular_pipeline import (
|
from ..modular_pipeline import (
|
||||||
BlockState,
|
BlockState,
|
||||||
LoopSequentialPipelineBlocks,
|
LoopSequentialPipelineBlocks,
|
||||||
PipelineBlock,
|
ModularPipelineBlocks,
|
||||||
PipelineState,
|
PipelineState,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
@@ -32,7 +32,7 @@ from .modular_pipeline import FluxModularPipeline
|
|||||||
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
class FluxLoopDenoiser(PipelineBlock):
|
class FluxLoopDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -49,11 +49,8 @@ class FluxLoopDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [InputParam("joint_attention_kwargs")]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
return [
|
||||||
|
InputParam("joint_attention_kwargs"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -113,7 +110,7 @@ class FluxLoopDenoiser(PipelineBlock):
|
|||||||
return components, block_state
|
return components, block_state
|
||||||
|
|
||||||
|
|
||||||
class FluxLoopAfterDenoiser(PipelineBlock):
|
class FluxLoopAfterDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -175,7 +172,7 @@ class FluxDenoiseLoopWrapper(LoopSequentialPipelineBlocks):
|
|||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loop_intermediate_inputs(self) -> List[InputParam]:
|
def loop_inputs(self) -> List[InputParam]:
|
||||||
return [
|
return [
|
||||||
InputParam(
|
InputParam(
|
||||||
"timesteps",
|
"timesteps",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from ...image_processor import VaeImageProcessor
|
|||||||
from ...loaders import FluxLoraLoaderMixin, TextualInversionLoaderMixin
|
from ...loaders import FluxLoraLoaderMixin, TextualInversionLoaderMixin
|
||||||
from ...models import AutoencoderKL
|
from ...models import AutoencoderKL
|
||||||
from ...utils import USE_PEFT_BACKEND, is_ftfy_available, logging, scale_lora_layers, unscale_lora_layers
|
from ...utils import USE_PEFT_BACKEND, is_ftfy_available, logging, scale_lora_layers, unscale_lora_layers
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
||||||
from .modular_pipeline import FluxModularPipeline
|
from .modular_pipeline import FluxModularPipeline
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ def retrieve_latents(
|
|||||||
raise AttributeError("Could not access latents of provided encoder_output")
|
raise AttributeError("Could not access latents of provided encoder_output")
|
||||||
|
|
||||||
|
|
||||||
class FluxVaeEncoderStep(PipelineBlock):
|
class FluxVaeEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -88,11 +88,10 @@ class FluxVaeEncoderStep(PipelineBlock):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def inputs(self) -> List[InputParam]:
|
def inputs(self) -> List[InputParam]:
|
||||||
return [InputParam("image", required=True), InputParam("height"), InputParam("width")]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
return [
|
||||||
|
InputParam("image", required=True),
|
||||||
|
InputParam("height"),
|
||||||
|
InputParam("width"),
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam("dtype", type_hint=torch.dtype, description="Data type of model tensor inputs"),
|
InputParam("dtype", type_hint=torch.dtype, description="Data type of model tensor inputs"),
|
||||||
InputParam(
|
InputParam(
|
||||||
@@ -157,7 +156,7 @@ class FluxVaeEncoderStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class FluxTextEncoderStep(PipelineBlock):
|
class FluxTextEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "flux"
|
model_name = "flux"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -618,7 +618,6 @@ def format_configs(configs, indent_level=4, max_line_length=115, add_empty_lines
|
|||||||
|
|
||||||
def make_doc_string(
|
def make_doc_string(
|
||||||
inputs,
|
inputs,
|
||||||
intermediate_inputs,
|
|
||||||
outputs,
|
outputs,
|
||||||
description="",
|
description="",
|
||||||
class_name=None,
|
class_name=None,
|
||||||
@@ -664,7 +663,7 @@ def make_doc_string(
|
|||||||
output += configs_str + "\n\n"
|
output += configs_str + "\n\n"
|
||||||
|
|
||||||
# Add inputs section
|
# Add inputs section
|
||||||
output += format_input_params(inputs + intermediate_inputs, indent_level=2)
|
output += format_input_params(inputs, indent_level=2)
|
||||||
|
|
||||||
# Add outputs section
|
# Add outputs section
|
||||||
output += "\n\n"
|
output += "\n\n"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from ...schedulers import EulerDiscreteScheduler
|
|||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ...utils.torch_utils import randn_tensor, unwrap_module
|
from ...utils.torch_utils import randn_tensor, unwrap_module
|
||||||
from ..modular_pipeline import (
|
from ..modular_pipeline import (
|
||||||
PipelineBlock,
|
ModularPipelineBlocks,
|
||||||
PipelineState,
|
PipelineState,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
||||||
@@ -195,7 +195,7 @@ def prepare_latents_img2img(
|
|||||||
return latents
|
return latents
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLInputStep(PipelineBlock):
|
class StableDiffusionXLInputStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -213,11 +213,6 @@ class StableDiffusionXLInputStep(PipelineBlock):
|
|||||||
def inputs(self) -> List[InputParam]:
|
def inputs(self) -> List[InputParam]:
|
||||||
return [
|
return [
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"prompt_embeds",
|
"prompt_embeds",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -394,7 +389,7 @@ class StableDiffusionXLInputStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLImg2ImgSetTimestepsStep(PipelineBlock):
|
class StableDiffusionXLImg2ImgSetTimestepsStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -421,11 +416,6 @@ class StableDiffusionXLImg2ImgSetTimestepsStep(PipelineBlock):
|
|||||||
InputParam("denoising_start"),
|
InputParam("denoising_start"),
|
||||||
# YiYi TODO: do we need num_images_per_prompt here?
|
# YiYi TODO: do we need num_images_per_prompt here?
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -543,7 +533,7 @@ class StableDiffusionXLImg2ImgSetTimestepsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLSetTimestepsStep(PipelineBlock):
|
class StableDiffusionXLSetTimestepsStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -611,7 +601,7 @@ class StableDiffusionXLSetTimestepsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLInpaintPrepareLatentsStep(PipelineBlock):
|
class StableDiffusionXLInpaintPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -640,11 +630,6 @@ class StableDiffusionXLInpaintPrepareLatentsStep(PipelineBlock):
|
|||||||
"`num_inference_steps`. A value of 1, therefore, essentially ignores `image`. Note that in the case of "
|
"`num_inference_steps`. A value of 1, therefore, essentially ignores `image`. Note that in the case of "
|
||||||
"`denoising_start` being declared as an integer, the value of `strength` will be ignored.",
|
"`denoising_start` being declared as an integer, the value of `strength` will be ignored.",
|
||||||
),
|
),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
@@ -890,7 +875,7 @@ class StableDiffusionXLInpaintPrepareLatentsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLImg2ImgPrepareLatentsStep(PipelineBlock):
|
class StableDiffusionXLImg2ImgPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -910,11 +895,6 @@ class StableDiffusionXLImg2ImgPrepareLatentsStep(PipelineBlock):
|
|||||||
InputParam("latents"),
|
InputParam("latents"),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
InputParam("denoising_start"),
|
InputParam("denoising_start"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"latent_timestep",
|
"latent_timestep",
|
||||||
@@ -971,7 +951,7 @@ class StableDiffusionXLImg2ImgPrepareLatentsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLPrepareLatentsStep(PipelineBlock):
|
class StableDiffusionXLPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -992,11 +972,6 @@ class StableDiffusionXLPrepareLatentsStep(PipelineBlock):
|
|||||||
InputParam("width"),
|
InputParam("width"),
|
||||||
InputParam("latents"),
|
InputParam("latents"),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"batch_size",
|
"batch_size",
|
||||||
@@ -1082,7 +1057,7 @@ class StableDiffusionXLPrepareLatentsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(PipelineBlock):
|
class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1119,11 +1094,6 @@ class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(PipelineBlock):
|
|||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
InputParam("aesthetic_score", default=6.0),
|
InputParam("aesthetic_score", default=6.0),
|
||||||
InputParam("negative_aesthetic_score", default=2.0),
|
InputParam("negative_aesthetic_score", default=2.0),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -1306,7 +1276,7 @@ class StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLPrepareAdditionalConditioningStep(PipelineBlock):
|
class StableDiffusionXLPrepareAdditionalConditioningStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1335,11 +1305,6 @@ class StableDiffusionXLPrepareAdditionalConditioningStep(PipelineBlock):
|
|||||||
InputParam("crops_coords_top_left", default=(0, 0)),
|
InputParam("crops_coords_top_left", default=(0, 0)),
|
||||||
InputParam("negative_crops_coords_top_left", default=(0, 0)),
|
InputParam("negative_crops_coords_top_left", default=(0, 0)),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -1489,7 +1454,7 @@ class StableDiffusionXLPrepareAdditionalConditioningStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLControlNetInputStep(PipelineBlock):
|
class StableDiffusionXLControlNetInputStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1517,11 +1482,6 @@ class StableDiffusionXLControlNetInputStep(PipelineBlock):
|
|||||||
InputParam("controlnet_conditioning_scale", default=1.0),
|
InputParam("controlnet_conditioning_scale", default=1.0),
|
||||||
InputParam("guess_mode", default=False),
|
InputParam("guess_mode", default=False),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -1708,7 +1668,7 @@ class StableDiffusionXLControlNetInputStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLControlNetUnionInputStep(PipelineBlock):
|
class StableDiffusionXLControlNetUnionInputStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1737,11 +1697,6 @@ class StableDiffusionXLControlNetUnionInputStep(PipelineBlock):
|
|||||||
InputParam("controlnet_conditioning_scale", default=1.0),
|
InputParam("controlnet_conditioning_scale", default=1.0),
|
||||||
InputParam("guess_mode", default=False),
|
InputParam("guess_mode", default=False),
|
||||||
InputParam("num_images_per_prompt", default=1),
|
InputParam("num_images_per_prompt", default=1),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from ...models import AutoencoderKL
|
|||||||
from ...models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
|
from ...models.attention_processor import AttnProcessor2_0, XFormersAttnProcessor
|
||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ..modular_pipeline import (
|
from ..modular_pipeline import (
|
||||||
PipelineBlock,
|
ModularPipelineBlocks,
|
||||||
PipelineState,
|
PipelineState,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
@@ -33,7 +33,7 @@ from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
|||||||
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLDecodeStep(PipelineBlock):
|
class StableDiffusionXLDecodeStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -56,17 +56,12 @@ class StableDiffusionXLDecodeStep(PipelineBlock):
|
|||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [
|
return [
|
||||||
InputParam("output_type", default="pil"),
|
InputParam("output_type", default="pil"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
required=True,
|
required=True,
|
||||||
type_hint=torch.Tensor,
|
type_hint=torch.Tensor,
|
||||||
description="The denoised latents from the denoising step",
|
description="The denoised latents from the denoising step",
|
||||||
)
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -157,7 +152,7 @@ class StableDiffusionXLDecodeStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLInpaintOverlayMaskStep(PipelineBlock):
|
class StableDiffusionXLInpaintOverlayMaskStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -184,11 +179,6 @@ class StableDiffusionXLInpaintOverlayMaskStep(PipelineBlock):
|
|||||||
InputParam("image"),
|
InputParam("image"),
|
||||||
InputParam("mask_image"),
|
InputParam("mask_image"),
|
||||||
InputParam("padding_mask_crop"),
|
InputParam("padding_mask_crop"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"images",
|
"images",
|
||||||
type_hint=Union[List[PIL.Image.Image], List[torch.Tensor], List[np.array]],
|
type_hint=Union[List[PIL.Image.Image], List[torch.Tensor], List[np.array]],
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from ...utils import logging
|
|||||||
from ..modular_pipeline import (
|
from ..modular_pipeline import (
|
||||||
BlockState,
|
BlockState,
|
||||||
LoopSequentialPipelineBlocks,
|
LoopSequentialPipelineBlocks,
|
||||||
PipelineBlock,
|
ModularPipelineBlocks,
|
||||||
PipelineState,
|
PipelineState,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
@@ -37,7 +37,7 @@ logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
|||||||
|
|
||||||
# YiYi experimenting composible denoise loop
|
# YiYi experimenting composible denoise loop
|
||||||
# loop step (1): prepare latent input for denoiser
|
# loop step (1): prepare latent input for denoiser
|
||||||
class StableDiffusionXLLoopBeforeDenoiser(PipelineBlock):
|
class StableDiffusionXLLoopBeforeDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -55,7 +55,7 @@ class StableDiffusionXLLoopBeforeDenoiser(PipelineBlock):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def intermediate_inputs(self) -> List[str]:
|
def inputs(self) -> List[str]:
|
||||||
return [
|
return [
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
@@ -73,7 +73,7 @@ class StableDiffusionXLLoopBeforeDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
|
|
||||||
# loop step (1): prepare latent input for denoiser (with inpainting)
|
# loop step (1): prepare latent input for denoiser (with inpainting)
|
||||||
class StableDiffusionXLInpaintLoopBeforeDenoiser(PipelineBlock):
|
class StableDiffusionXLInpaintLoopBeforeDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -91,7 +91,7 @@ class StableDiffusionXLInpaintLoopBeforeDenoiser(PipelineBlock):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def intermediate_inputs(self) -> List[str]:
|
def inputs(self) -> List[str]:
|
||||||
return [
|
return [
|
||||||
InputParam(
|
InputParam(
|
||||||
"latents",
|
"latents",
|
||||||
@@ -144,7 +144,7 @@ class StableDiffusionXLInpaintLoopBeforeDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
|
|
||||||
# loop step (2): denoise the latents with guidance
|
# loop step (2): denoise the latents with guidance
|
||||||
class StableDiffusionXLLoopDenoiser(PipelineBlock):
|
class StableDiffusionXLLoopDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -171,11 +171,6 @@ class StableDiffusionXLLoopDenoiser(PipelineBlock):
|
|||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [
|
return [
|
||||||
InputParam("cross_attention_kwargs"),
|
InputParam("cross_attention_kwargs"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"num_inference_steps",
|
"num_inference_steps",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -249,7 +244,7 @@ class StableDiffusionXLLoopDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
|
|
||||||
# loop step (2): denoise the latents with guidance (with controlnet)
|
# loop step (2): denoise the latents with guidance (with controlnet)
|
||||||
class StableDiffusionXLControlNetLoopDenoiser(PipelineBlock):
|
class StableDiffusionXLControlNetLoopDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -277,11 +272,6 @@ class StableDiffusionXLControlNetLoopDenoiser(PipelineBlock):
|
|||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [
|
return [
|
||||||
InputParam("cross_attention_kwargs"),
|
InputParam("cross_attention_kwargs"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam(
|
InputParam(
|
||||||
"controlnet_cond",
|
"controlnet_cond",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -449,7 +439,7 @@ class StableDiffusionXLControlNetLoopDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
|
|
||||||
# loop step (3): scheduler step to update latents
|
# loop step (3): scheduler step to update latents
|
||||||
class StableDiffusionXLLoopAfterDenoiser(PipelineBlock):
|
class StableDiffusionXLLoopAfterDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -470,11 +460,6 @@ class StableDiffusionXLLoopAfterDenoiser(PipelineBlock):
|
|||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [
|
return [
|
||||||
InputParam("eta", default=0.0),
|
InputParam("eta", default=0.0),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -520,7 +505,7 @@ class StableDiffusionXLLoopAfterDenoiser(PipelineBlock):
|
|||||||
|
|
||||||
|
|
||||||
# loop step (3): scheduler step to update latents (with inpainting)
|
# loop step (3): scheduler step to update latents (with inpainting)
|
||||||
class StableDiffusionXLInpaintLoopAfterDenoiser(PipelineBlock):
|
class StableDiffusionXLInpaintLoopAfterDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -542,11 +527,6 @@ class StableDiffusionXLInpaintLoopAfterDenoiser(PipelineBlock):
|
|||||||
def inputs(self) -> List[Tuple[str, Any]]:
|
def inputs(self) -> List[Tuple[str, Any]]:
|
||||||
return [
|
return [
|
||||||
InputParam("eta", default=0.0),
|
InputParam("eta", default=0.0),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[str]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam(
|
InputParam(
|
||||||
"timesteps",
|
"timesteps",
|
||||||
@@ -660,7 +640,7 @@ class StableDiffusionXLDenoiseLoopWrapper(LoopSequentialPipelineBlocks):
|
|||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loop_intermediate_inputs(self) -> List[InputParam]:
|
def loop_inputs(self) -> List[InputParam]:
|
||||||
return [
|
return [
|
||||||
InputParam(
|
InputParam(
|
||||||
"timesteps",
|
"timesteps",
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from ...utils import (
|
|||||||
scale_lora_layers,
|
scale_lora_layers,
|
||||||
unscale_lora_layers,
|
unscale_lora_layers,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
||||||
from .modular_pipeline import StableDiffusionXLModularPipeline
|
from .modular_pipeline import StableDiffusionXLModularPipeline
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ def retrieve_latents(
|
|||||||
raise AttributeError("Could not access latents of provided encoder_output")
|
raise AttributeError("Could not access latents of provided encoder_output")
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLIPAdapterStep(PipelineBlock):
|
class StableDiffusionXLIPAdapterStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -215,7 +215,7 @@ class StableDiffusionXLIPAdapterStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLTextEncoderStep(PipelineBlock):
|
class StableDiffusionXLTextEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -576,7 +576,7 @@ class StableDiffusionXLTextEncoderStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLVaeEncoderStep(PipelineBlock):
|
class StableDiffusionXLVaeEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -601,11 +601,6 @@ class StableDiffusionXLVaeEncoderStep(PipelineBlock):
|
|||||||
InputParam("image", required=True),
|
InputParam("image", required=True),
|
||||||
InputParam("height"),
|
InputParam("height"),
|
||||||
InputParam("width"),
|
InputParam("width"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
InputParam("dtype", type_hint=torch.dtype, description="Data type of model tensor inputs"),
|
InputParam("dtype", type_hint=torch.dtype, description="Data type of model tensor inputs"),
|
||||||
InputParam(
|
InputParam(
|
||||||
@@ -668,12 +663,11 @@ class StableDiffusionXLVaeEncoderStep(PipelineBlock):
|
|||||||
block_state.device = components._execution_device
|
block_state.device = components._execution_device
|
||||||
block_state.dtype = block_state.dtype if block_state.dtype is not None else components.vae.dtype
|
block_state.dtype = block_state.dtype if block_state.dtype is not None else components.vae.dtype
|
||||||
|
|
||||||
block_state.image = components.image_processor.preprocess(
|
image = components.image_processor.preprocess(
|
||||||
block_state.image, height=block_state.height, width=block_state.width, **block_state.preprocess_kwargs
|
block_state.image, height=block_state.height, width=block_state.width, **block_state.preprocess_kwargs
|
||||||
)
|
)
|
||||||
block_state.image = block_state.image.to(device=block_state.device, dtype=block_state.dtype)
|
image = image.to(device=block_state.device, dtype=block_state.dtype)
|
||||||
|
block_state.batch_size = image.shape[0]
|
||||||
block_state.batch_size = block_state.image.shape[0]
|
|
||||||
|
|
||||||
# if generator is a list, make sure the length of it matches the length of images (both should be batch_size)
|
# if generator is a list, make sure the length of it matches the length of images (both should be batch_size)
|
||||||
if isinstance(block_state.generator, list) and len(block_state.generator) != block_state.batch_size:
|
if isinstance(block_state.generator, list) and len(block_state.generator) != block_state.batch_size:
|
||||||
@@ -682,16 +676,14 @@ class StableDiffusionXLVaeEncoderStep(PipelineBlock):
|
|||||||
f" size of {block_state.batch_size}. Make sure the batch size matches the length of the generators."
|
f" size of {block_state.batch_size}. Make sure the batch size matches the length of the generators."
|
||||||
)
|
)
|
||||||
|
|
||||||
block_state.image_latents = self._encode_vae_image(
|
block_state.image_latents = self._encode_vae_image(components, image=image, generator=block_state.generator)
|
||||||
components, image=block_state.image, generator=block_state.generator
|
|
||||||
)
|
|
||||||
|
|
||||||
self.set_block_state(state, block_state)
|
self.set_block_state(state, block_state)
|
||||||
|
|
||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class StableDiffusionXLInpaintVaeEncoderStep(PipelineBlock):
|
class StableDiffusionXLInpaintVaeEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "stable-diffusion-xl"
|
model_name = "stable-diffusion-xl"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -726,11 +718,6 @@ class StableDiffusionXLInpaintVaeEncoderStep(PipelineBlock):
|
|||||||
InputParam("image", required=True),
|
InputParam("image", required=True),
|
||||||
InputParam("mask_image", required=True),
|
InputParam("mask_image", required=True),
|
||||||
InputParam("padding_mask_crop"),
|
InputParam("padding_mask_crop"),
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def intermediate_inputs(self) -> List[InputParam]:
|
|
||||||
return [
|
|
||||||
InputParam("dtype", type_hint=torch.dtype, description="The dtype of the model inputs"),
|
InputParam("dtype", type_hint=torch.dtype, description="The dtype of the model inputs"),
|
||||||
InputParam("generator"),
|
InputParam("generator"),
|
||||||
]
|
]
|
||||||
@@ -860,34 +847,32 @@ class StableDiffusionXLInpaintVaeEncoderStep(PipelineBlock):
|
|||||||
block_state.crops_coords = None
|
block_state.crops_coords = None
|
||||||
block_state.resize_mode = "default"
|
block_state.resize_mode = "default"
|
||||||
|
|
||||||
block_state.image = components.image_processor.preprocess(
|
image = components.image_processor.preprocess(
|
||||||
block_state.image,
|
block_state.image,
|
||||||
height=block_state.height,
|
height=block_state.height,
|
||||||
width=block_state.width,
|
width=block_state.width,
|
||||||
crops_coords=block_state.crops_coords,
|
crops_coords=block_state.crops_coords,
|
||||||
resize_mode=block_state.resize_mode,
|
resize_mode=block_state.resize_mode,
|
||||||
)
|
)
|
||||||
block_state.image = block_state.image.to(dtype=torch.float32)
|
image = image.to(dtype=torch.float32)
|
||||||
|
|
||||||
block_state.mask = components.mask_processor.preprocess(
|
mask = components.mask_processor.preprocess(
|
||||||
block_state.mask_image,
|
block_state.mask_image,
|
||||||
height=block_state.height,
|
height=block_state.height,
|
||||||
width=block_state.width,
|
width=block_state.width,
|
||||||
resize_mode=block_state.resize_mode,
|
resize_mode=block_state.resize_mode,
|
||||||
crops_coords=block_state.crops_coords,
|
crops_coords=block_state.crops_coords,
|
||||||
)
|
)
|
||||||
block_state.masked_image = block_state.image * (block_state.mask < 0.5)
|
block_state.masked_image = image * (mask < 0.5)
|
||||||
|
|
||||||
block_state.batch_size = block_state.image.shape[0]
|
block_state.batch_size = image.shape[0]
|
||||||
block_state.image = block_state.image.to(device=block_state.device, dtype=block_state.dtype)
|
image = image.to(device=block_state.device, dtype=block_state.dtype)
|
||||||
block_state.image_latents = self._encode_vae_image(
|
block_state.image_latents = self._encode_vae_image(components, image=image, generator=block_state.generator)
|
||||||
components, image=block_state.image, generator=block_state.generator
|
|
||||||
)
|
|
||||||
|
|
||||||
# 7. Prepare mask latent variables
|
# 7. Prepare mask latent variables
|
||||||
block_state.mask, block_state.masked_image_latents = self.prepare_mask_latents(
|
block_state.mask, block_state.masked_image_latents = self.prepare_mask_latents(
|
||||||
components,
|
components,
|
||||||
block_state.mask,
|
mask,
|
||||||
block_state.masked_image,
|
block_state.masked_image,
|
||||||
block_state.batch_size,
|
block_state.batch_size,
|
||||||
block_state.height,
|
block_state.height,
|
||||||
|
|||||||
@@ -247,10 +247,6 @@ SDXL_INPUTS_SCHEMA = {
|
|||||||
"control_mode": InputParam(
|
"control_mode": InputParam(
|
||||||
"control_mode", type_hint=List[int], required=True, description="Control mode for union controlnet"
|
"control_mode", type_hint=List[int], required=True, description="Control mode for union controlnet"
|
||||||
),
|
),
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SDXL_INTERMEDIATE_INPUTS_SCHEMA = {
|
|
||||||
"prompt_embeds": InputParam(
|
"prompt_embeds": InputParam(
|
||||||
"prompt_embeds",
|
"prompt_embeds",
|
||||||
type_hint=torch.Tensor,
|
type_hint=torch.Tensor,
|
||||||
@@ -271,13 +267,6 @@ SDXL_INTERMEDIATE_INPUTS_SCHEMA = {
|
|||||||
"preprocess_kwargs": InputParam(
|
"preprocess_kwargs": InputParam(
|
||||||
"preprocess_kwargs", type_hint=Optional[dict], description="Kwargs for ImageProcessor"
|
"preprocess_kwargs", type_hint=Optional[dict], description="Kwargs for ImageProcessor"
|
||||||
),
|
),
|
||||||
"latents": InputParam(
|
|
||||||
"latents", type_hint=torch.Tensor, required=True, description="Initial latents for denoising process"
|
|
||||||
),
|
|
||||||
"timesteps": InputParam("timesteps", type_hint=torch.Tensor, required=True, description="Timesteps for inference"),
|
|
||||||
"num_inference_steps": InputParam(
|
|
||||||
"num_inference_steps", type_hint=int, required=True, description="Number of denoising steps"
|
|
||||||
),
|
|
||||||
"latent_timestep": InputParam(
|
"latent_timestep": InputParam(
|
||||||
"latent_timestep", type_hint=torch.Tensor, required=True, description="Initial noise level timestep"
|
"latent_timestep", type_hint=torch.Tensor, required=True, description="Initial noise level timestep"
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import torch
|
|||||||
from ...schedulers import UniPCMultistepScheduler
|
from ...schedulers import UniPCMultistepScheduler
|
||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ...utils.torch_utils import randn_tensor
|
from ...utils.torch_utils import randn_tensor
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
from .modular_pipeline import WanModularPipeline
|
from .modular_pipeline import WanModularPipeline
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ def retrieve_timesteps(
|
|||||||
return timesteps, num_inference_steps
|
return timesteps, num_inference_steps
|
||||||
|
|
||||||
|
|
||||||
class WanInputStep(PipelineBlock):
|
class WanInputStep(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -194,7 +194,7 @@ class WanInputStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class WanSetTimestepsStep(PipelineBlock):
|
class WanSetTimestepsStep(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -243,7 +243,7 @@ class WanSetTimestepsStep(PipelineBlock):
|
|||||||
return components, state
|
return components, state
|
||||||
|
|
||||||
|
|
||||||
class WanPrepareLatentsStep(PipelineBlock):
|
class WanPrepareLatentsStep(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ from ...configuration_utils import FrozenDict
|
|||||||
from ...models import AutoencoderKLWan
|
from ...models import AutoencoderKLWan
|
||||||
from ...utils import logging
|
from ...utils import logging
|
||||||
from ...video_processor import VideoProcessor
|
from ...video_processor import VideoProcessor
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
|
|
||||||
|
|
||||||
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
class WanDecodeStep(PipelineBlock):
|
class WanDecodeStep(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from ...utils import logging
|
|||||||
from ..modular_pipeline import (
|
from ..modular_pipeline import (
|
||||||
BlockState,
|
BlockState,
|
||||||
LoopSequentialPipelineBlocks,
|
LoopSequentialPipelineBlocks,
|
||||||
PipelineBlock,
|
ModularPipelineBlocks,
|
||||||
PipelineState,
|
PipelineState,
|
||||||
)
|
)
|
||||||
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, InputParam, OutputParam
|
||||||
@@ -34,7 +34,7 @@ from .modular_pipeline import WanModularPipeline
|
|||||||
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
|
||||||
class WanLoopDenoiser(PipelineBlock):
|
class WanLoopDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -132,7 +132,7 @@ class WanLoopDenoiser(PipelineBlock):
|
|||||||
return components, block_state
|
return components, block_state
|
||||||
|
|
||||||
|
|
||||||
class WanLoopAfterDenoiser(PipelineBlock):
|
class WanLoopAfterDenoiser(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from transformers import AutoTokenizer, UMT5EncoderModel
|
|||||||
from ...configuration_utils import FrozenDict
|
from ...configuration_utils import FrozenDict
|
||||||
from ...guiders import ClassifierFreeGuidance
|
from ...guiders import ClassifierFreeGuidance
|
||||||
from ...utils import is_ftfy_available, logging
|
from ...utils import is_ftfy_available, logging
|
||||||
from ..modular_pipeline import PipelineBlock, PipelineState
|
from ..modular_pipeline import ModularPipelineBlocks, PipelineState
|
||||||
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
from ..modular_pipeline_utils import ComponentSpec, ConfigSpec, InputParam, OutputParam
|
||||||
from .modular_pipeline import WanModularPipeline
|
from .modular_pipeline import WanModularPipeline
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ def prompt_clean(text):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
class WanTextEncoderStep(PipelineBlock):
|
class WanTextEncoderStep(ModularPipelineBlocks):
|
||||||
model_name = "wan"
|
model_name = "wan"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -117,13 +117,9 @@ class SDXLModularIPAdapterTests:
|
|||||||
|
|
||||||
_ = blocks.sub_blocks.pop("ip_adapter")
|
_ = blocks.sub_blocks.pop("ip_adapter")
|
||||||
parameters = blocks.input_names
|
parameters = blocks.input_names
|
||||||
intermediate_parameters = blocks.intermediate_input_names
|
|
||||||
assert "ip_adapter_image" not in parameters, (
|
assert "ip_adapter_image" not in parameters, (
|
||||||
"`ip_adapter_image` argument must be removed from the `__call__` method"
|
"`ip_adapter_image` argument must be removed from the `__call__` method"
|
||||||
)
|
)
|
||||||
assert "ip_adapter_image_embeds" not in intermediate_parameters, (
|
|
||||||
"`ip_adapter_image_embeds` argument must be supported by the `__call__` method"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_dummy_image_embeds(self, cross_attention_dim: int = 32):
|
def _get_dummy_image_embeds(self, cross_attention_dim: int = 32):
|
||||||
return torch.randn((1, 1, cross_attention_dim), device=torch_device)
|
return torch.randn((1, 1, cross_attention_dim), device=torch_device)
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ class ModularPipelineTesterMixin:
|
|||||||
def test_pipeline_call_signature(self):
|
def test_pipeline_call_signature(self):
|
||||||
pipe = self.get_pipeline()
|
pipe = self.get_pipeline()
|
||||||
input_parameters = pipe.blocks.input_names
|
input_parameters = pipe.blocks.input_names
|
||||||
intermediate_parameters = pipe.blocks.intermediate_input_names
|
|
||||||
optional_parameters = pipe.default_call_parameters
|
optional_parameters = pipe.default_call_parameters
|
||||||
|
|
||||||
def _check_for_parameters(parameters, expected_parameters, param_type):
|
def _check_for_parameters(parameters, expected_parameters, param_type):
|
||||||
@@ -149,7 +148,6 @@ class ModularPipelineTesterMixin:
|
|||||||
)
|
)
|
||||||
|
|
||||||
_check_for_parameters(self.params, input_parameters, "input")
|
_check_for_parameters(self.params, input_parameters, "input")
|
||||||
_check_for_parameters(self.intermediate_params, intermediate_parameters, "intermediate")
|
|
||||||
_check_for_parameters(self.optional_params, optional_parameters, "optional")
|
_check_for_parameters(self.optional_params, optional_parameters, "optional")
|
||||||
|
|
||||||
def test_inference_batch_consistent(self, batch_sizes=[2], batch_generator=True):
|
def test_inference_batch_consistent(self, batch_sizes=[2], batch_generator=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user