Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,53 @@ def get_output_names(self):
"down_block_04", "down_block_05", "down_block_06", "down_block_07",
"down_block_08", "mid_block"]

def get_dynamic_axes(self) -> Dict[str, Dict[int, str]]:
"""Get dynamic axes configuration for variable input shapes"""
return {
"sample": {0: "B", 2: "H", 3: "W"},
"encoder_hidden_states": {0: "B"},
"timestep": {0: "B"},
"controlnet_cond": {0: "B", 2: "H_ctrl", 3: "W_ctrl"},
"text_embeds": {0: "B"},
"time_ids": {0: "B"},
**{f"down_block_{i:02d}": {0: "B", 2: "H", 3: "W"} for i in range(9)},
"mid_block": {0: "B", 2: "H", 3: "W"}
}

def get_input_profile(self, batch_size, image_height, image_width,
static_batch, static_shape):
"""Override to provide SDXL-specific input profiles including text_embeds and time_ids"""
# Get base profiles from parent class
profile = super().get_input_profile(batch_size, image_height, image_width,
static_batch, static_shape)

# Add SDXL-specific input profiles with dynamic batch dimension
min_batch = batch_size if static_batch else self.min_batch
max_batch = batch_size if static_batch else self.max_batch

# conditioning_scale is a scalar (empty shape)
profile["conditioning_scale"] = [
(), # min
(), # opt
(), # max
]

# text_embeds has shape (batch, 1280)
profile["text_embeds"] = [
(min_batch, 1280), # min
(batch_size, 1280), # opt
(max_batch, 1280), # max
]

# time_ids has shape (batch, 6)
profile["time_ids"] = [
(min_batch, 6), # min
(batch_size, 6), # opt
(max_batch, 6), # max
]

return profile


def create_controlnet_model(model_type: str = "sd15",
unet=None, model_path: str = "",
Expand Down
2 changes: 1 addition & 1 deletion src/streamdiffusion/modules/controlnet_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def add_controlnet(self, cfg: ControlNetConfig, control_image: Optional[Union[st
preproc = None
if cfg.preprocessor:
from streamdiffusion.preprocessing.processors import get_preprocessor
preproc = get_preprocessor(cfg.preprocessor, pipeline_ref=self._stream, normalization_context='controlnet')
preproc = get_preprocessor(cfg.preprocessor, pipeline_ref=self._stream, normalization_context='controlnet', params=cfg.preprocessor_params)
# Apply provided parameters to the preprocessor instance
if cfg.preprocessor_params:
params = cfg.preprocessor_params or {}
Expand Down
6 changes: 3 additions & 3 deletions src/streamdiffusion/preprocessing/processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_preprocessor_class(name: str) -> type:
return _preprocessor_registry[name]


def get_preprocessor(name: str, pipeline_ref: Any = None, normalization_context: str = 'controlnet') -> BasePreprocessor:
def get_preprocessor(name: str, pipeline_ref: Any = None, normalization_context: str = 'controlnet', params: Any = None) -> BasePreprocessor:
"""
Get a preprocessor by name

Expand All @@ -135,9 +135,9 @@ def get_preprocessor(name: str, pipeline_ref: Any = None, normalization_context:
if hasattr(processor_class, 'requires_sync_processing') and processor_class.requires_sync_processing:
if pipeline_ref is None:
raise ValueError(f"Processor '{name}' requires a pipeline_ref")
return processor_class(pipeline_ref=pipeline_ref, normalization_context=normalization_context, _registry_name=name)
return processor_class(pipeline_ref=pipeline_ref, normalization_context=normalization_context, _registry_name=name, **(params or {}))
else:
return processor_class(normalization_context=normalization_context, _registry_name=name)
return processor_class(normalization_context=normalization_context, _registry_name=name, **(params or {}))


def register_preprocessor(name: str, preprocessor_class):
Expand Down
Loading