
"""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


__UpperCAmelCase       =  logging.get_logger(__name__)




class 			_SCREAMING_SNAKE_CASE					(			A__							):






			def __init__(					self       ,   __A       )			->     Optional[Any]:
						super().__init__()
						lowerCAmelCase_    :int			     =  nn.ModuleList(__A       )






			def  __lowerCAmelCase (					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       )       ):
									lowerCAmelCase_     ,       lowerCAmelCase_    :List[Any]			     =  controlnet(
									    __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   __A       ,   )

									# merge samples
									if i == 0:
												lowerCAmelCase_     ,       lowerCAmelCase_    :Tuple			     =  down_samples, mid_sample
									else:
												lowerCAmelCase_    :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  __lowerCAmelCase (					self       ,   __A       ,   __A = True       ,   __A = None       ,   __A = False       ,   __A = None       ,   )			->     Optional[Any]:
						lowerCAmelCase_    :int			     =  0
						lowerCAmelCase_    :Dict			     =  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
									lowerCAmelCase_    :Any			     =  model_path_to_save + f"""_{idx}"""






			@classmethod
			def  __lowerCAmelCase (					cls       ,   __A       ,   **__A       )			->     List[Any]:
						lowerCAmelCase_    :int			     =  0
						lowerCAmelCase_    :Dict			     =  []

						# 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`, ...
						lowerCAmelCase_    :List[Any]			     =  pretrained_model_path
						while os.path.isdir(__A       ):
									lowerCAmelCase_    :Tuple			     =  ControlNetModel.from_pretrained(__A       ,   **__A       )
									controlnets.append(__A       )

									idx += 1
									lowerCAmelCase_    :Dict			     =  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'''


def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				return int((input_a, input_a).count(0     ) != 0     )







def 			snake_case_   (  ):







				"""simple docstring"""





				assert nand_gate(0							,      0     ) == 1
				assert nand_gate(0							,      1     ) == 1
				assert nand_gate(1							,      0     ) == 1
				assert nand_gate(1							,      1     ) == 0


if __name__ == "__main__":
				print(nand_gate(0, 0))
				print(nand_gate(0, 1))
				print(nand_gate(1, 0))
				print(nand_gate(1, 1))




