



"""simple docstring"""




import os
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

import torch
from torch import nn

from ...models.controlnet import ControlNetModel, ControlNetOutput
from ...models.modeling_utils import ModelMixin
from ...utils import logging


_lowerCAmelCase    : Optional[int]							=							logging.get_logger(__name__)






class      UpperCAmelCase_  (    A__						):



						def __init__(					self					:     int					,     A					:     List[Any]						):
											super().__init__()
											_UpperCAmelCase      :     int        =   nn.ModuleList(__A						)



						def 						snake_case_ (					self					:     Union[str, Any]					,     A					:     List[Any]					,     A					:     Union[str, Any]					,     A					:     List[Any]					,     A					:     Optional[Any]					,     A					:     Optional[int]					,     A					:     Union[str, Any] = None					,     A					:     Dict = None					,     A					:     Dict = None					,     A					:     int = None					,     A					:     Union[str, Any] = False					,     A					:     List[Any] = True					,     ):
											for i, (image, scale, controlnet) in enumerate(zip(__A					,     __A					,     self.nets						)						):
																_UpperCAmelCase      :     Optional[int]        =   controlnet(
																    __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     __A					,     )

																# merge samples
																if i == 0:
																					_UpperCAmelCase      :     Optional[int]        =   down_samples, mid_sample
																else:
																					_UpperCAmelCase      :     str        =   [
																					    samples_prev + samples_curr
																					    for samples_prev, samples_curr in zip(__A					,     __A						)
																					]
																					mid_block_res_sample += mid_sample

											return down_block_res_samples, mid_block_res_sample



						def 						snake_case_ (					self					:     Optional[Any]					,     A					:     Optional[Any]					,     A					:     Tuple = True					,     A					:     List[Any] = None					,     A					:     Union[str, Any] = False					,     A					:     List[Any] = None					,     ):
											_UpperCAmelCase      :     List[str]        =   0
											_UpperCAmelCase      :     Any        =   save_directory
											for controlnet in self.nets:
																controlnet.save_pretrained(
																    __A					,     is_main_process=__A					,     save_function=__A					,     safe_serialization=__A					,     variant=__A					,     )

																idx += 1
																_UpperCAmelCase      :     Optional[Any]        =   model_path_to_save + f'_{idx}'



						@classmethod
						def 						snake_case_ (					cls					:     Optional[int]					,     A					:     Any					,     **A					:     Optional[int]						):
											_UpperCAmelCase      :     Optional[int]        =   0
											_UpperCAmelCase      :     Union[str, Any]        =   []

											# load controlnet and append to list until no controlnet directory exists anymore
											# first controlnet has to be saved under `./mydirectory/controlnet` to be compliant with `DiffusionPipeline.from_prertained`
											# second, third, ... controlnets have to be saved under `./mydirectory/controlnet_1`, `./mydirectory/controlnet_2`, ...
											_UpperCAmelCase      :     Union[str, Any]        =   pretrained_model_path
											while os.path.isdir(__A						):
																_UpperCAmelCase      :     Optional[int]        =   ControlNetModel.from_pretrained(__A					,     **__A						)
																controlnets.append(__A						)

																idx += 1
																_UpperCAmelCase      :     int        =   pretrained_model_path + f'_{idx}'

											logger.info(f'{len(__A						)} controlnets loaded from {pretrained_model_path}.'						)

											if len(__A						) == 0:
																raise ValueError(
																    f'No ControlNets found under {os.path.dirname(__A						)}. Expected at least {pretrained_model_path + "_0"}.'						)

											return cls(__A						)





"""simple docstring"""




from __future__ import annotations

from typing import Any

def 						__snake_case						(				SCREAMING_SNAKE_CASE__     :						list[Any]    )  ->       None:





     '''simple docstring'''

     create_state_space_tree(SCREAMING_SNAKE_CASE__						,  []						,  0    )

def 						__snake_case						(				SCREAMING_SNAKE_CASE__     :						list[Any]						,  SCREAMING_SNAKE_CASE__     :						list[Any]						,  SCREAMING_SNAKE_CASE__     :						int    )  ->       None:





     '''simple docstring'''

     if index == len(SCREAMING_SNAKE_CASE__    ):
          print(SCREAMING_SNAKE_CASE__    )
          return

     create_state_space_tree(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__						,  index + 1    )
     current_subsequence.append(sequence[index]    )
     create_state_space_tree(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__						,  index + 1    )
     current_subsequence.pop()


if __name__ == "__main__":
 _lowerCAmelCase    : list[Any]							=							[3, 1, 2, 4]
 generate_all_subsequences(seq)

 seq.clear()
 seq.extend(["A", "B", "C"])
 generate_all_subsequences(seq)
