


'''simple docstring'''







import tempfile
import unittest

import numpy as np
import torch

from diffusers import DiffusionPipeline
from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor
class  lowercase_					(   unittest.TestCase       ):


    def        __a							(					self  , a = False   ):
          UpperCamelCase__  =    10

          if only_cross_attention:
                UpperCamelCase__  =    12
          else:
                # when only cross attention is not set, the cross attention dim must be the same as the query dim
                UpperCamelCase__  =    query_dim

          return {
              "query_dim": query_dim,
              "cross_attention_dim": cross_attention_dim,
              "heads": 2,
              "dim_head": 4,
              "added_kv_proj_dim": 6,
              "norm_num_groups": 1,
              "only_cross_attention": only_cross_attention,
              "processor": AttnAddedKVProcessor(),
          }


    def        __a							(					self  , a  , a   ):
          UpperCamelCase__  =    2

          UpperCamelCase__  =    torch.rand(a  , a  , 3  , 2   )
          UpperCamelCase__  =    torch.rand(a  , 4  , a   )
          UpperCamelCase__  =    None

          return {
              "hidden_states": hidden_states,
              "encoder_hidden_states": encoder_hidden_states,
              "attention_mask": attention_mask,
          }


    def        __a							(					self   ):
          # self and cross attention

          torch.manual_seed(0   )

          UpperCamelCase__  =    self.get_constructor_arguments(only_cross_attention=a   )
          UpperCamelCase__  =    Attention(**a   )

          self.assertTrue(attn.to_k is not None   )
          self.assertTrue(attn.to_v is not None   )

          UpperCamelCase__  =    self.get_forward_arguments(
              query_dim=constructor_args["query_dim"]  , added_kv_proj_dim=constructor_args["added_kv_proj_dim"]   )

          UpperCamelCase__  =    attn(**a   )

          # only self attention

          torch.manual_seed(0   )

          UpperCamelCase__  =    self.get_constructor_arguments(only_cross_attention=a   )
          UpperCamelCase__  =    Attention(**a   )

          self.assertTrue(attn.to_k is None   )
          self.assertTrue(attn.to_v is None   )

          UpperCamelCase__  =    self.get_forward_arguments(
              query_dim=constructor_args["query_dim"]  , added_kv_proj_dim=constructor_args["added_kv_proj_dim"]   )

          UpperCamelCase__  =    attn(**a   )

          self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()   )

class  lowercase_					(   unittest.TestCase       ):


    def        __a							(					self   ):
          UpperCamelCase__  =    DiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-pipe"  , safety_checker=a   )

          UpperCamelCase__  =    pipe(
              "foo"  , num_inference_steps=2  , generator=torch.Generator("cpu"   ).manual_seed(0   )  , output_type="np"  , ).images

          # the initial conversion succeeds
          UpperCamelCase__  =    DiffusionPipeline.from_pretrained(
              "hf-internal-testing/tiny-stable-diffusion-pipe"  , device_map="sequential"  , safety_checker=a   )

          UpperCamelCase__  =    pipe(
              "foo"  , num_inference_steps=2  , generator=torch.Generator("cpu"   ).manual_seed(0   )  , output_type="np"  , ).images

          with tempfile.TemporaryDirectory() as tmpdir:
                # save the converted model
                pipe.save_pretrained(a   )

                # can also load the converted weights
                UpperCamelCase__  =    DiffusionPipeline.from_pretrained(a  , device_map="sequential"  , safety_checker=a   )

          UpperCamelCase__  =    pipe(
              "foo"  , num_inference_steps=2  , generator=torch.Generator("cpu"   ).manual_seed(0   )  , output_type="np"  , ).images

          self.assertTrue(np.allclose(a  , a  , atol=1e-5   )   )
          self.assertTrue(np.allclose(a  , a  , atol=1e-5   )   )









'''simple docstring'''







import math







def _UpperCamelCase	(					__A   )							->		bool:


      '''simple docstring'''



      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5				,      int(math.sqrt(__A   ) + 1   )				,      6   ):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True







def _UpperCamelCase	(					__A = 1000				,      __A = 1000   )							->		int:


      '''simple docstring'''



      UpperCamelCase__  =    [0, 0, 0]  # length, a, b
      for a in range((a_limit * -1) + 1				,      __A   ):
            for b in range(2				,      __A   ):
                  if is_prime(__A   ):
                        UpperCamelCase__  =    0
                        UpperCamelCase__  =    0
                        while is_prime((n**2) + (a * n) + b   ):
                              count += 1
                              n += 1
                        if count > longest[0]:
                              UpperCamelCase__  =    [count, a, b]
      UpperCamelCase__  =    longest[1] * longest[2]
      return ans


if __name__ == "__main__":
  print(solution(1_0_0_0, 1_0_0_0))





