





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


snake_case_           =      logging.get_logger(__name__)

class 		SCREAMING_SNAKE_CASE__    (	_UpperCAmelCase  ):


      def __init__(self	:				Any    ,      a__	:				Union[List[ControlNetModel], Tuple[ControlNetModel]]				):





         """simple docstring"""



         super().__init__()
         __snake_case								=       nn.ModuleList(a__				)


      def        a			(self	:				Tuple    ,      a__	:				torch.FloatTensor    ,      a__	:				Union[torch.Tensor, float, int]    ,      a__	:				torch.Tensor    ,      a__	:				List[torch.tensor]    ,      a__	:				List[float]    ,      a__	:				Optional[torch.Tensor] = None    ,      a__	:				Optional[torch.Tensor] = None    ,      a__	:				Optional[torch.Tensor] = None    ,      a__	:				Optional[Dict[str, Any]] = None    ,      a__	:				bool = False    ,      a__	:				bool = True    ,      ):





         """simple docstring"""



         for i, (image, scale, controlnet) in enumerate(zip(a__    ,      a__    ,      self.nets				)				):
            __snake_case	,     __snake_case								=       controlnet(
                a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      a__    ,      )

            # merge samples
            if i == 0:
               __snake_case	,     __snake_case								=       down_samples, mid_sample
            else:
               __snake_case								=       [
                   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        a			(self	:				Union[str, Any]    ,      a__	:				Union[str, os.PathLike]    ,      a__	:				bool = True    ,      a__	:				Callable = None    ,      a__	:				bool = False    ,      a__	:				Optional[str] = None    ,      ):





         """simple docstring"""



         __snake_case								=       0
         __snake_case								=       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
            __snake_case								=       model_path_to_save + f"""_{idx}"""


      @classmethod
      def        a			(cls	:				Union[str, Any]    ,      a__	:				Optional[Union[str, os.PathLike]]    ,      **a__	:				Any				):





         """simple docstring"""



         __snake_case								=       0
         __snake_case								=       []

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

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








from __future__ import annotations

snake_case_           =      [True] * 1000001
snake_case_           =      2
while i * i <= 1000000:
    if seive[i]:
        for j in range(i * i, 1000001, i):
            snake_case_           =      False
    i += 1






def lowerCamelCase__   (							snake_case_     :  int	)				->    bool:
   return seive[n]






def lowerCamelCase__   (							snake_case_     :  int	)				->    bool:
   return any(digit in '''02468''' for digit in str(snake_case_	)	)






def lowerCamelCase__   (							snake_case_     :  int = 100_0000	)				->    list[int]:
   __snake_case								=       [2]  # result already includes the number 2.
   for num in range(3	,				limit + 1	,				2	):
      if is_prime(snake_case_	) and not contains_an_even_digit(snake_case_	):
         __snake_case								=       str(snake_case_	)
         __snake_case								=       [int(str_num[j:] + str_num[:j]	) for j in range(len(snake_case_	)	)]
         if all(is_prime(snake_case_	) for i in list_nums	):
            result.append(snake_case_	)
   return result






def lowerCamelCase__   (							)				->    int:
   return len(find_circular_primes()	)


if __name__ == "__main__":
    print(F'{len(find_circular_primes()) = }')

