


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


_lowercase       :      List[Any]	=	logging.get_logger(__name__)






class       _UpperCamelCase    (					__snake_case				):

				"""simple docstring"""







				def __init__(						self				,   a__   )	->				Optional[Any]:
					super().__init__()
					A								=				nn.ModuleList(a__   )

				def      _UpperCAmelCase					(						self				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__ = None				,   a__ = None				,   a__ = None				,   a__ = None				,   a__ = False				,   a__ = True				,   )	->				Union[ControlNetOutput, Tuple]:
					for i, (image, scale, controlnet) in enumerate(zip(a__				,   a__				,   self.nets   )   ):
						A					,			A								=				controlnet(
						    a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   a__				,   )

						# merge samples
						if i == 0:
							A					,			A								=				down_samples, mid_sample
						else:
							A								=				[
							    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      _UpperCAmelCase					(						self				,   a__				,   a__ = True				,   a__ = None				,   a__ = False				,   a__ = None				,   )	->				Optional[int]:
					A								=				0
					A								=				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
						A								=				model_path_to_save + f'_{idx}'

				@classmethod
				def      _UpperCAmelCase					(						cls				,   a__				,   **a__   )	->				Dict:
					A								=				0
					A								=				[]

					# 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`, ...
					A								=				pretrained_model_path
					while os.path.isdir(a__   ):
						A								=				ControlNetModel.from_pretrained(a__				,   **a__   )
						controlnets.append(a__   )

						idx += 1
						A								=				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__   )



def   _lowerCAmelCase				(   UpperCamelCase__:     int						) ->   bool:





	"""simple docstring"""







	return str(UpperCamelCase__						) == str(UpperCamelCase__						)[::-1]





def   _lowerCAmelCase				(   UpperCamelCase__:     int						) ->   int:





	"""simple docstring"""







	return int(UpperCamelCase__						) + int(str(UpperCamelCase__						)[::-1]						)





def   _lowerCAmelCase				(   UpperCamelCase__:     int = 1_00_00						) ->   int:





	"""simple docstring"""







	A								=				[]
	for num in range(1							,					UpperCamelCase__						):
		A								=				0
		A								=				num
		while iterations < 50:
			A								=				sum_reverse(UpperCamelCase__						)
			iterations += 1
			if is_palindrome(UpperCamelCase__						):
				break
		else:
			lychrel_nums.append(UpperCamelCase__						)
	return len(UpperCamelCase__						)


if __name__ == "__main__":
				print(f'''{solution() = }''')



