





import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import (
         FalconForCausalLM,
         FalconForQuestionAnswering,
         FalconForSequenceClassification,
         FalconForTokenClassification,
         FalconModel,
     )







class 				__lowerCAmelCase       :







      def __init__(    self		,      lowerCAmelCase__		,      lowerCAmelCase__=3		,      lowerCAmelCase__=7		,      lowerCAmelCase__=True		,      lowerCAmelCase__=True		,      lowerCAmelCase__=False		,      lowerCAmelCase__=True		,      lowerCAmelCase__=9_9		,      lowerCAmelCase__=3_2		,      lowerCAmelCase__=5		,      lowerCAmelCase__=4		,      lowerCAmelCase__=3_7		,      lowerCAmelCase__="gelu"		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__=5_1_2		,      lowerCAmelCase__=1_6		,      lowerCAmelCase__=2		,      lowerCAmelCase__=0.02		,      lowerCAmelCase__=3		,      lowerCAmelCase__=4		,      lowerCAmelCase__=None		,      )   ->						List[Any]:



        '''simple docstring'''




        a__	:					Optional[Any]										=parent
        a__	:					Tuple										=batch_size
        a__	:					int										=seq_length
        a__	:					Tuple										=is_training
        a__	:					Any										=use_input_mask
        a__	:					Optional[int]										=use_token_type_ids
        a__	:					List[str]										=use_labels
        a__	:					Optional[Any]										=vocab_size
        a__	:					Dict										=hidden_size
        a__	:					List[Any]										=num_hidden_layers
        a__	:					List[Any]										=num_attention_heads
        a__	:					Union[str, Any]										=intermediate_size
        a__	:					Tuple										=hidden_act
        a__	:					Dict										=hidden_dropout_prob
        a__	:					Any										=attention_probs_dropout_prob
        a__	:					Tuple										=max_position_embeddings
        a__	:					Optional[int]										=type_vocab_size
        a__	:					Any										=type_sequence_label_size
        a__	:					Optional[int]										=initializer_range
        a__	:					Optional[Any]										=num_labels
        a__	:					int										=num_choices
        a__	:					Optional[int]										=scope







      def    _lowercase  (    self							)   ->						Union[str, Any]:



        '''simple docstring'''




        a__	:					int										=ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size							)

        a__	:					int										=None
        if self.use_input_mask:
          a__	:					Dict										=random_attention_mask([self.batch_size, self.seq_length]							)

        a__	:					Any										=None

        a__	:					Optional[Any]										=None
        a__	:					Tuple										=None
        a__	:					Dict										=None
        if self.use_labels:
          a__	:					str										=ids_tensor([self.batch_size]		,      self.type_sequence_label_size							)
          a__	:					Tuple										=ids_tensor([self.batch_size, self.seq_length]		,      self.num_labels							)
          a__	:					str										=ids_tensor([self.batch_size]		,      self.num_choices							)

        a__	:					Union[str, Any]										=self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







      def    _lowercase  (    self							)   ->						str:



        '''simple docstring'''




        return FalconConfig(
            vocab_size=self.vocab_size		,      hidden_size=self.hidden_size		,      num_hidden_layers=self.num_hidden_layers		,      num_attention_heads=self.num_attention_heads		,      intermediate_size=self.intermediate_size		,      hidden_act=self.hidden_act		,      hidden_dropout_prob=self.hidden_dropout_prob		,      attention_probs_dropout_prob=self.attention_probs_dropout_prob		,      max_position_embeddings=self.max_position_embeddings		,      type_vocab_size=self.type_vocab_size		,      is_decoder=lowerCAmelCase__		,      initializer_range=self.initializer_range		,      pad_token_id=1		,      new_decoder_architecture=lowerCAmelCase__		,      )







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__							)   ->						Tuple:



        '''simple docstring'''




        a__	:					List[Any]										=FalconModel(config=lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					List[str]										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__							)
        a__	:					str										=model(lowerCAmelCase__							)
        self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size)							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      )   ->						Any:



        '''simple docstring'''




        a__	:					List[Any]										=True
        a__	:					Any										=FalconModel(lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					int										=model(
            lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      encoder_hidden_states=lowerCAmelCase__		,      encoder_attention_mask=lowerCAmelCase__		,      )
        a__	:					int										=model(
            lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      encoder_hidden_states=lowerCAmelCase__		,      )
        a__	:					Any										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__							)
        self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size)							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      )   ->						Union[str, Any]:



        '''simple docstring'''




        a__	:					Any										=FalconForCausalLM(config=lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					Tuple										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      labels=lowerCAmelCase__							)
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.vocab_size)							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      lowerCAmelCase__		,      )   ->						Dict:



        '''simple docstring'''




        a__	:					str										=True
        a__	:					Union[str, Any]										=True
        a__	:					str										=FalconForCausalLM(config=lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()

        # first forward pass
        a__	:					int										=model(
            lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      encoder_hidden_states=lowerCAmelCase__		,      encoder_attention_mask=lowerCAmelCase__		,      use_cache=lowerCAmelCase__		,      )
        a__	:					str										=outputs.past_key_values

        # create hypothetical multiple next token and extent to next_input_ids
        a__	:					Union[str, Any]										=ids_tensor((self.batch_size, 3)		,      config.vocab_size							)
        a__	:					List[Any]										=ids_tensor((self.batch_size, 3)		,      vocab_size=2							)

        # append to next input_ids and
        a__	:					Union[str, Any]										=torch.cat([input_ids, next_tokens]		,      dim=-1							)
        a__	:					Tuple										=torch.cat([input_mask, next_mask]		,      dim=-1							)

        a__	:					str										=model(
            lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      encoder_hidden_states=lowerCAmelCase__		,      encoder_attention_mask=lowerCAmelCase__		,      output_hidden_states=lowerCAmelCase__		,      )["hidden_states"][0]
        a__	:					Tuple										=model(
            lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      encoder_hidden_states=lowerCAmelCase__		,      encoder_attention_mask=lowerCAmelCase__		,      past_key_values=lowerCAmelCase__		,      output_hidden_states=lowerCAmelCase__		,      )["hidden_states"][0]

        # select random slice
        a__	:					int										=ids_tensor((1,)		,      output_from_past.shape[-1]							).item()
        a__	:					List[Any]										=output_from_no_past[:, -3:, random_slice_idx].detach()
        a__	:					Tuple										=output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]							)

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(lowerCAmelCase__		,      lowerCAmelCase__		,      atol=1E-3							)							)







      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        a__	:					Dict										=self.prepare_config_and_inputs()
        (
            (
            a__
        )					,							(
            a__
        )					,							(
            a__
        )					,							(
            a__
        )					,							(
            a__
        )					,							(
            a__
        )					,							(
            a__
        )					,							
        )	:					Tuple										=config_and_inputs
        a__	:					Optional[Any]										={"input_ids": input_ids, "attention_mask": input_mask}
        return config, inputs_dict







@require_torch
class 				__lowerCAmelCase       (    UpperCamelCase__						,				UpperCamelCase__						,				UpperCamelCase__						,				unittest.TestCase):
      _lowercase				:					int						=			(
          (
              FalconModel,
              FalconForCausalLM,
              FalconForSequenceClassification,
              FalconForTokenClassification,
              FalconForQuestionAnswering,
          )
          if is_torch_available()
          else ()
      )
      _lowercase				:					Any						=			(FalconForCausalLM,) if is_torch_available() else ()
      _lowercase				:					int						=			(
          {
              """feature-extraction""": FalconModel,
              """text-classification""": FalconForSequenceClassification,
              """text-generation""": FalconForCausalLM,
              """question-answering""": FalconForQuestionAnswering,
              """token-classification""": FalconForTokenClassification,
              """zero-shot""": FalconForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      _lowercase				:					Dict						=			False
      _lowercase				:					int						=			False







      def    _lowercase  (    self							)   ->						Union[str, Any]:



        '''simple docstring'''




        a__	:					str										=FalconModelTester(self							)
        a__	:					Any										=ConfigTester(self		,      config_class=lowerCAmelCase__		,      hidden_size=3_7							)







      def    _lowercase  (    self							)   ->						Dict:



        '''simple docstring'''




        self.config_tester.run_common_tests()







      def    _lowercase  (    self							)   ->						Dict:



        '''simple docstring'''




        a__	:					Optional[int]										=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__							)







      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        a__					,							*a__	:					Dict										=self.model_tester.prepare_config_and_inputs()
        for alibi in [True, False]:
          a__	:					Any										=alibi
          self.model_tester.create_and_check_model(lowerCAmelCase__		,      *lowerCAmelCase__							)







      def    _lowercase  (    self							)   ->						Optional[Any]:



        '''simple docstring'''




        a__					,							a__	:					List[str]										=self.model_tester.prepare_config_and_inputs_for_common()
        a__	:					List[str]										=3
        a__	:					List[Any]										=input_dict["input_ids"]
        a__	:					Tuple										=input_ids.ne(1							).to(lowerCAmelCase__							)
        a__	:					Optional[int]										=ids_tensor([self.model_tester.batch_size]		,      self.model_tester.type_sequence_label_size							)
        a__	:					Tuple										=FalconForSequenceClassification(lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					Optional[Any]										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      labels=lowerCAmelCase__							)
        self.assertEqual(result.logits.shape		,      (self.model_tester.batch_size, self.model_tester.num_labels)							)







      def    _lowercase  (    self							)   ->						int:



        '''simple docstring'''




        a__					,							a__	:					int										=self.model_tester.prepare_config_and_inputs_for_common()
        a__	:					Optional[Any]										=3
        a__	:					Dict										="single_label_classification"
        a__	:					Optional[int]										=input_dict["input_ids"]
        a__	:					Any										=input_ids.ne(1							).to(lowerCAmelCase__							)
        a__	:					Optional[Any]										=ids_tensor([self.model_tester.batch_size]		,      self.model_tester.type_sequence_label_size							)
        a__	:					Dict										=FalconForSequenceClassification(lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					Optional[int]										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      labels=lowerCAmelCase__							)
        self.assertEqual(result.logits.shape		,      (self.model_tester.batch_size, self.model_tester.num_labels)							)







      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        a__					,							a__	:					Union[str, Any]										=self.model_tester.prepare_config_and_inputs_for_common()
        a__	:					str										=input_dict["input_ids"]
        a__	:					Any										=FalconForCausalLM(lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					Union[str, Any]										=model(lowerCAmelCase__		,      use_cache=lowerCAmelCase__							)
        a__	:					Union[str, Any]										=input_ids.shape[0]
        a__	:					Union[str, Any]										=model._convert_to_rw_cache(result.past_key_values							)
        a__	:					int										=model._convert_cache_to_standard_format(lowerCAmelCase__		,      lowerCAmelCase__							)
        for layer in range(len(lowerCAmelCase__							)							):
          for tensor_idx in range(2							):
            self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3							)
            self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4							)
            self.assertTrue(
                torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]							)							)







      def    _lowercase  (    self							)   ->						int:



        '''simple docstring'''




        a__					,							a__	:					List[str]										=self.model_tester.prepare_config_and_inputs_for_common()
        a__	:					List[str]										=3
        a__	:					Union[str, Any]										="multi_label_classification"
        a__	:					Optional[int]										=input_dict["input_ids"]
        a__	:					List[Any]										=input_ids.ne(1							).to(lowerCAmelCase__							)
        a__	:					Tuple										=ids_tensor(
            [self.model_tester.batch_size, config.num_labels]		,      self.model_tester.type_sequence_label_size							).to(torch.float							)
        a__	:					Tuple										=FalconForSequenceClassification(lowerCAmelCase__							)
        model.to(lowerCAmelCase__							)
        model.eval()
        a__	:					Tuple										=model(lowerCAmelCase__		,      attention_mask=lowerCAmelCase__		,      labels=lowerCAmelCase__							)
        self.assertEqual(result.logits.shape		,      (self.model_tester.batch_size, self.model_tester.num_labels)							)







      def    _lowercase  (    self							)   ->						Optional[int]:



        '''simple docstring'''




        for model_class in self.all_generative_model_classes:
          a__					,							a__	:					int										=self.model_tester.prepare_config_and_inputs_for_common()

          # If it doesn't support cache, pass the test
          if not hasattr(lowerCAmelCase__		,      "use_cache"							):
            return

          a__	:					int										=model_class(lowerCAmelCase__							).to(lowerCAmelCase__							)
          if "use_cache" not in inputs:
            a__	:					Optional[int]										=True
          a__	:					Dict										=model(**lowerCAmelCase__							)

          # If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
          if "past_key_values" not in outputs:
            return

          a__	:					int										=(
              getattr(lowerCAmelCase__		,      "decoder_layers"		,      lowerCAmelCase__							)
              or getattr(lowerCAmelCase__		,      "num_decoder_layers"		,      lowerCAmelCase__							)
              or config.num_hidden_layers
          )
          a__	:					str										=getattr(lowerCAmelCase__		,      "num_kv_heads"		,      config.num_attention_heads							)
          a__	:					Tuple										=getattr(lowerCAmelCase__		,      "d_model"		,      config.hidden_size							)
          a__	:					Any										=embed_dim // num_attention_heads

          a__	:					List[Any]										=outputs["past_key_values"]
          self.assertEqual(len(lowerCAmelCase__							)		,      lowerCAmelCase__							)

          a__					,							a__	:					Tuple										=inputs["input_ids"].shape
          for i in range(lowerCAmelCase__							):
            if config.new_decoder_architecture:
              a__	:					Dict										=config.num_attention_heads
            elif config.multi_query:
              a__	:					List[str]										=1
            self.assertEqual(len(past_kv[0]							)		,      2							)  # K V for the decoder = 2
            self.assertEqual(
                past_kv[i][0].shape		,      (batch_size, num_attention_heads, seq_length, per_head_embed_dim)							)
            self.assertEqual(
                past_kv[i][1].shape		,      (batch_size, num_attention_heads, seq_length, per_head_embed_dim)							)







@require_torch
class 				__lowerCAmelCase       (    unittest.TestCase):







      @slow
      def    _lowercase  (    self							)   ->						Dict:



        '''simple docstring'''




        a__	:					str										=AutoTokenizer.from_pretrained("Rocketknight1/falcon-rw-1b"							)
        a__	:					str										=FalconForCausalLM.from_pretrained("Rocketknight1/falcon-rw-1b"							)
        model.eval()
        model.to(lowerCAmelCase__							)
        a__	:					int										=tokenizer("My favorite food is"		,      return_tensors="pt"							).to(lowerCAmelCase__							)

        a__	:					str										=(
            "My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday."
        )

        a__	:					Tuple										=model.generate(**lowerCAmelCase__		,      do_sample=lowerCAmelCase__		,      max_new_tokens=1_9							)
        a__	:					Tuple										=tokenizer.batch_decode(lowerCAmelCase__							)[0]

        self.assertEqual(lowerCAmelCase__		,      lowerCAmelCase__							)







      @slow
      def    _lowercase  (    self							)   ->						List[Any]:



        '''simple docstring'''




        for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
          a__	:					Union[str, Any]										=AutoTokenizer.from_pretrained(lowerCAmelCase__							)
          a__	:					Any										=FalconForCausalLM.from_pretrained(lowerCAmelCase__							)
          model.eval()
          model.to(lowerCAmelCase__							)
          a__	:					Optional[int]										=tokenizer("My favorite food is"		,      return_tensors="pt"							).to(lowerCAmelCase__							)

          # We just test that these run without errors - the models are randomly initialized
          # and so the actual text outputs will be garbage
          model.generate(**lowerCAmelCase__		,      do_sample=lowerCAmelCase__		,      max_new_tokens=4							)
          model.generate(**lowerCAmelCase__		,      do_sample=lowerCAmelCase__		,      max_new_tokens=4							)
          model.generate(**lowerCAmelCase__		,      num_beams=2		,      max_new_tokens=4							)







      @slow
      def    _lowercase  (    self							)   ->						Optional[Any]:



        '''simple docstring'''




        with torch.no_grad():
          for repo in [
              "Rocketknight1/falcon-rw-1b",
              "Rocketknight1/tiny-random-falcon-7b",
              "Rocketknight1/tiny-random-falcon-40b",
          ]:
            a__	:					str										=AutoTokenizer.from_pretrained(lowerCAmelCase__							)
            a__	:					int										=FalconForCausalLM.from_pretrained(lowerCAmelCase__							)
            model.eval()
            model.to(device=lowerCAmelCase__							)
            a__	:					Optional[int]										=tokenizer("My favorite food is"		,      return_tensors="pt"							).to(lowerCAmelCase__							)

            # Test results are the same with and without cache
            a__	:					Optional[int]										=model.generate(**lowerCAmelCase__		,      do_sample=lowerCAmelCase__		,      max_new_tokens=2_0		,      use_cache=lowerCAmelCase__							)
            a__	:					Any										=model.generate(**lowerCAmelCase__		,      do_sample=lowerCAmelCase__		,      max_new_tokens=2_0		,      use_cache=lowerCAmelCase__							)
            self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0							)













import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


UpperCAmelCase	:	int		     =       False







class 				__lowerCAmelCase       (    unittest.TestCase):
      pass







@nightly
@require_torch_gpu
class 				__lowerCAmelCase       (    unittest.TestCase):







      def    _lowercase  (    self							)   ->						Tuple:



        '''simple docstring'''




        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()







      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        a__	:					str										=VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"		,      torch_dtype=torch.floataa							)
        pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        a__	:					int										=load_image(
            "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"							)

        a__	:					Optional[Any]										=torch.manual_seed(0							)
        a__	:					Optional[Any]										=pipe.dual_guided(
            prompt="first prompt"		,      image=lowerCAmelCase__		,      text_to_image_strength=0.75		,      generator=lowerCAmelCase__		,      guidance_scale=7.5		,      num_inference_steps=2		,      output_type="numpy"		,      ).images

        with tempfile.TemporaryDirectory() as tmpdirname:
          pipe.save_pretrained(lowerCAmelCase__							)
          a__	:					str										=VersatileDiffusionPipeline.from_pretrained(lowerCAmelCase__		,      torch_dtype=torch.floataa							)
        pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        a__	:					Optional[Any]										=generator.manual_seed(0							)
        a__	:					Tuple										=pipe.dual_guided(
            prompt="first prompt"		,      image=lowerCAmelCase__		,      text_to_image_strength=0.75		,      generator=lowerCAmelCase__		,      guidance_scale=7.5		,      num_inference_steps=2		,      output_type="numpy"		,      ).images

        assert np.abs(image - new_image							).sum() < 1E-5, "Models don't have the same forward pass"







      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        a__	:					str										=VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"		,      torch_dtype=torch.floataa							)
        pipe.to(lowerCAmelCase__							)
        pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

        a__	:					Optional[Any]										="cyberpunk 2077"
        a__	:					int										=load_image(
            "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"							)
        a__	:					Union[str, Any]										=torch.manual_seed(0							)
        a__	:					Tuple										=pipe.dual_guided(
            prompt=lowerCAmelCase__		,      image=lowerCAmelCase__		,      text_to_image_strength=0.75		,      generator=lowerCAmelCase__		,      guidance_scale=7.5		,      num_inference_steps=5_0		,      output_type="numpy"		,      ).images

        a__	:					int										=image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

        assert image.shape == (1, 5_1_2, 5_1_2, 3)
        a__	:					Any										=np.array([0.14_48, 0.16_19, 0.17_41, 0.10_86, 0.11_47, 0.11_28, 0.11_99, 0.11_65, 0.10_01]							)

        assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-1

        a__	:					str										="A painting of a squirrel eating a burger "
        a__	:					Optional[int]										=torch.manual_seed(0							)
        a__	:					str										=pipe.text_to_image(
            prompt=lowerCAmelCase__		,      generator=lowerCAmelCase__		,      guidance_scale=7.5		,      num_inference_steps=5_0		,      output_type="numpy"							).images

        a__	:					Any										=image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

        assert image.shape == (1, 5_1_2, 5_1_2, 3)
        a__	:					Optional[int]										=np.array([0.33_67, 0.31_69, 0.26_56, 0.38_70, 0.47_90, 0.37_96, 0.40_09, 0.48_78, 0.47_78]							)

        assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-1

        a__	:					Optional[Any]										=pipe.image_variation(lowerCAmelCase__		,      generator=lowerCAmelCase__		,      output_type="numpy"							).images

        a__	:					Union[str, Any]										=image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

        assert image.shape == (1, 5_1_2, 5_1_2, 3)
        a__	:					Any										=np.array([0.30_76, 0.31_23, 0.32_84, 0.37_82, 0.37_70, 0.38_94, 0.42_97, 0.43_31, 0.44_56]							)

        assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-1






