






import inspect
import unittest

from transformers import BitConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch
       from torch import nn

       from transformers import BitBackbone, BitForImageClassification, BitImageProcessor, BitModel
       from transformers.models.bit.modeling_bit import BIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image







class 			_lowercase :
      def __init__(  self					,      a					,      a=3					,      a=3_2					,      a=3					,      a=1_0					,      a=[8, 1_6, 3_2, 6_4]					,      a=[1, 1, 2, 1]					,      a=True					,      a=True					,      a="relu"					,      a=3					,      a=None					,      a=["stage2", "stage3", "stage4"]					,      a=[2, 3, 4]					,      a=1					,      ):
       snake_case__	:     Any											=parent
       snake_case__	:     str											=batch_size
       snake_case__	:     Optional[int]											=image_size
       snake_case__	:     Tuple											=num_channels
       snake_case__	:     int											=embeddings_size
       snake_case__	:     List[Any]											=hidden_sizes
       snake_case__	:     Tuple											=depths
       snake_case__	:     Tuple											=is_training
       snake_case__	:     List[str]											=use_labels
       snake_case__	:     Optional[int]											=hidden_act
       snake_case__	:     str											=num_labels
       snake_case__	:     Optional[Any]											=scope
       snake_case__	:     List[Any]											=len(lowercase__ )
       snake_case__	:     Any											=out_features
       snake_case__	:     Tuple											=out_indices
       snake_case__	:     int											=num_groups
      def     lowercase__       (  self ):
       snake_case__	:     Optional[int]											=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

       snake_case__	:     Dict											=None
       if self.use_labels:
        snake_case__	:     Any											=ids_tensor([self.batch_size]					,      self.num_labels )

       snake_case__	:     str											=self.get_config()

       return config, pixel_values, labels
      def     lowercase__       (  self ):
       return BitConfig(
           num_channels=self.num_channels					,      embeddings_size=self.embeddings_size					,      hidden_sizes=self.hidden_sizes					,      depths=self.depths					,      hidden_act=self.hidden_act					,      num_labels=self.num_labels					,      out_features=self.out_features					,      out_indices=self.out_indices					,      num_groups=self.num_groups					,      )
      def     lowercase__       (  self					,      a					,      a					,      a ):
       snake_case__	:     List[Any]											=BitModel(config=lowercase__ )
       model.to(lowercase__ )
       model.eval()
       snake_case__	:     Optional[Any]											=model(lowercase__ )
       self.parent.assertEqual(
           result.last_hidden_state.shape					,      (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)					,      )
      def     lowercase__       (  self					,      a					,      a					,      a ):
       snake_case__	:     Optional[Any]											=self.num_labels
       snake_case__	:     Union[str, Any]											=BitForImageClassification(lowercase__ )
       model.to(lowercase__ )
       model.eval()
       snake_case__	:     Dict											=model(lowercase__					,      labels=lowercase__ )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_labels) )
      def     lowercase__       (  self					,      a					,      a					,      a ):
       snake_case__	:     Optional[Any]											=BitBackbone(config=lowercase__ )
       model.to(lowercase__ )
       model.eval()
       snake_case__	:     List[Any]											=model(lowercase__ )

       # verify feature maps
       self.parent.assertEqual(len(result.feature_maps )					,      len(config.out_features ) )
       self.parent.assertListEqual(list(result.feature_maps[0].shape )					,      [self.batch_size, self.hidden_sizes[1], 4, 4] )

       # verify channels
       self.parent.assertEqual(len(model.channels )					,      len(config.out_features ) )
       self.parent.assertListEqual(model.channels					,      config.hidden_sizes[1:] )

       # verify backbone works with out_features=None
       snake_case__	:     Dict											=None
       snake_case__	:     List[str]											=BitBackbone(config=lowercase__ )
       model.to(lowercase__ )
       model.eval()
       snake_case__	:     Tuple											=model(lowercase__ )

       # verify feature maps
       self.parent.assertEqual(len(result.feature_maps )					,      1 )
       self.parent.assertListEqual(list(result.feature_maps[0].shape )					,      [self.batch_size, self.hidden_sizes[-1], 1, 1] )

       # verify channels
       self.parent.assertEqual(len(model.channels )					,      1 )
       self.parent.assertListEqual(model.channels					,      [config.hidden_sizes[-1]] )



      def     lowercase__       (  self ):
       snake_case__	:     Dict											=self.prepare_config_and_inputs()
       snake_case__	:     Any											=config_and_inputs
       snake_case__	:     Any											={'''pixel_values''': pixel_values}
       return config, inputs_dict







@require_torch
class 			_lowercase ( _UpperCamelCase    ,					_UpperCamelCase    ,					unittest.TestCase    ):
      _a				:    str				      =				(BitModel, BitForImageClassification, BitBackbone) if is_torch_available() else ()
      _a				:    Optional[Any]				      =				(
          {'''feature-extraction''': BitModel, '''image-classification''': BitForImageClassification}
          if is_torch_available()
          else {}
      )

      _a				:    Tuple				      =				False
      _a				:    List[Any]				      =				False
      _a				:    Optional[int]				      =				False
      _a				:    str				      =				False
      _a				:    List[str]				      =				False
      def     lowercase__       (  self ):
       snake_case__	:     Tuple											=BitModelTester(self )
       snake_case__	:     List[Any]											=ConfigTester(self					,      config_class=lowercase__					,      has_text_modality=lowercase__ )
      def     lowercase__       (  self ):
       self.create_and_test_config_common_properties()
       self.config_tester.create_and_test_config_to_json_string()
       self.config_tester.create_and_test_config_to_json_file()
       self.config_tester.create_and_test_config_from_and_save_pretrained()
       self.config_tester.create_and_test_config_with_num_labels()
       self.config_tester.check_config_can_be_init_without_params()
       self.config_tester.check_config_arguments_init()
      def     lowercase__       (  self ):
       return
      @unittest.skip(reason="""Bit does not output attentions""" )
      def     lowercase__       (  self ):
       pass
      @unittest.skip(reason="""Bit does not use inputs_embeds""" )
      def     lowercase__       (  self ):
       pass
      @unittest.skip(reason="""Bit does not support input and output embeddings""" )
      def     lowercase__       (  self ):
       pass
      def     lowercase__       (  self ):
       snake_case__	:     Optional[int]											=self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
        snake_case__	:     int											=model_class(lowercase__ )
        snake_case__	:     int											=inspect.signature(model.forward )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        snake_case__	:     Any											=[*signature.parameters.keys()]

        snake_case__	:     Optional[Any]											=['''pixel_values''']
        self.assertListEqual(arg_names[:1]					,      lowercase__ )
      def     lowercase__       (  self ):
       snake_case__	:     int											=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*lowercase__ )
      def     lowercase__       (  self ):
       snake_case__	:     Optional[Any]											=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_backbone(*lowercase__ )
      def     lowercase__       (  self ):
       snake_case__	:     Dict											=self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
        snake_case__	:     int											=model_class(config=lowercase__ )
        for name, module in model.named_modules():
         if isinstance(lowercase__					,      (nn.BatchNormad, nn.GroupNorm) ):
          self.assertTrue(
              torch.all(module.weight == 1 )					,      msg=F"Parameter {name} of model {model_class} seems not properly initialized"					,      )
          self.assertTrue(
              torch.all(module.bias == 0 )					,      msg=F"Parameter {name} of model {model_class} seems not properly initialized"					,      )
      def     lowercase__       (  self ):
       def check_hidden_states_output(a					,      a					,      a ):
        snake_case__	:     List[str]											=model_class(lowercase__ )
        model.to(lowercase__ )
        model.eval()

        with torch.no_grad():
         snake_case__	:     Optional[int]											=model(**self._prepare_for_class(lowercase__					,      lowercase__ ) )

        snake_case__	:     int											=outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

        snake_case__	:     Dict											=self.model_tester.num_stages
        self.assertEqual(len(lowercase__ )					,      expected_num_stages + 1 )

        # Bit's feature maps are of shape (batch_size, num_channels, height, width)
        self.assertListEqual(
            list(hidden_states[0].shape[-2:] )					,      [self.model_tester.image_size // 4, self.model_tester.image_size // 4]					,      )

       snake_case__	:     Tuple											=self.model_tester.prepare_config_and_inputs_for_common()
       snake_case__	:     Union[str, Any]											=['''preactivation''', '''bottleneck''']
       for model_class in self.all_model_classes:
        for layer_type in layers_type:
         snake_case__	:     Optional[Any]											=layer_type
         snake_case__	:     Optional[int]											=True
         check_hidden_states_output(lowercase__					,      lowercase__					,      lowercase__ )

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         snake_case__	:     List[Any]											=True

         check_hidden_states_output(lowercase__					,      lowercase__					,      lowercase__ )
      @unittest.skip(reason="""Bit does not use feedforward chunking""" )
      def     lowercase__       (  self ):
       pass
      def     lowercase__       (  self ):
       snake_case__	:     Dict											=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*lowercase__ )



      @slow
      def     lowercase__       (  self ):
       for model_name in BIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        snake_case__	:     Union[str, Any]											=BitModel.from_pretrained(lowercase__ )
        self.assertIsNotNone(lowercase__ )







def       A__				(   ):





 '''simple docstring'''







 snake_case__	:     Tuple											=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""						)
 return image







@require_torch
@require_vision
class 			_lowercase ( unittest.TestCase    ):
      @cached_property
      def     lowercase__       (  self ):
       return (
           BitImageProcessor.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0] ) if is_vision_available() else None
       )



      @slow
      def     lowercase__       (  self ):
       snake_case__	:     List[Any]											=BitForImageClassification.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0] ).to(lowercase__ )

       snake_case__	:     List[Any]											=self.default_image_processor
       snake_case__	:     List[str]											=prepare_img()
       snake_case__	:     Union[str, Any]											=image_processor(images=lowercase__					,      return_tensors="""pt""" ).to(lowercase__ )

       # forward pass
       with torch.no_grad():
        snake_case__	:     Optional[Any]											=model(**lowercase__ )

       # verify the logits
       snake_case__	:     List[Any]											=torch.Size((1, 1_0_0_0) )
       self.assertEqual(outputs.logits.shape					,      lowercase__ )

       snake_case__	:     List[Any]											=torch.tensor([[-0.6526, -0.5263, -1.4398]] ).to(lowercase__ )

       self.assertTrue(torch.allclose(outputs.logits[0, :3]					,      lowercase__					,      atol=1e-4 ) )







@require_torch
class 			_lowercase ( _UpperCamelCase    ,					unittest.TestCase    ):
      _a				:    Optional[Any]				      =				(BitBackbone,) if is_torch_available() else ()
      _a				:    Optional[Any]				      =				BitConfig

      _a				:    str				      =				False
      def     lowercase__       (  self ):
       snake_case__	:     int											=BitModelTester(self )









import gc
import random
import unittest

import numpy as np
import torch
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModel,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableUnCLIPImgaImgPipeline, UNetaDConditionModel
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
from diffusers.pipelines.stable_diffusion.stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    floats_tensor,
    load_image,
    load_numpy,
    require_torch_gpu,
    skip_mps,
    slow,
    torch_device,
)

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import (
    PipelineKarrasSchedulerTesterMixin,
    PipelineLatentTesterMixin,
    PipelineTesterMixin,
    assert_mean_pixel_difference,
)


enable_full_determinism()




class 							lowerCamelCase   (  _UpperCamelCase							,						_UpperCamelCase							,						_UpperCamelCase							,						unittest.TestCase ):
	_lowerCAmelCase     :		Optional[Any]										=						StableUnCLIPImgaImgPipeline
	_lowerCAmelCase     :		Any										=						TEXT_GUIDED_IMAGE_VARIATION_PARAMS
	_lowerCAmelCase     :		List[Any]										=						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
	_lowerCAmelCase     :		Dict										=						frozenset(
	    [] )  # TO-DO: update image_params once pipeline is refactored with VaeImageProcessor.preprocess
	_lowerCAmelCase     :		str										=						frozenset([] )


	def  A(    self):
							__UpperCAmelCase			:							Any	    =	3_2
							__UpperCAmelCase			:							Union[str, Any]	    =	embedder_hidden_size

							# image encoding components

							__UpperCAmelCase			:							Union[str, Any]	    =	CLIPImageProcessor(crop_size=3_2				,     size=3_2)

							torch.manual_seed(0)
							__UpperCAmelCase			:							List[str]	    =	CLIPVisionModelWithProjection(
							    CLIPVisionConfig(
							        hidden_size=lowercase__				,     projection_dim=lowercase__				,     num_hidden_layers=5				,     num_attention_heads=4				,     image_size=3_2				,     intermediate_size=3_7				,     patch_size=1				,     ))

							# regular denoising components

							torch.manual_seed(0)
							__UpperCAmelCase			:							List[Any]	    =	StableUnCLIPImageNormalizer(embedding_dim=lowercase__)
							__UpperCAmelCase			:							Any	    =	DDPMScheduler(beta_schedule='''squaredcos_cap_v2''')

							torch.manual_seed(0)
							__UpperCAmelCase			:							Dict	    =	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip''')

							torch.manual_seed(0)
							__UpperCAmelCase			:							int	    =	CLIPTextModel(
							    CLIPTextConfig(
							        bos_token_id=0				,     eos_token_id=2				,     hidden_size=lowercase__				,     projection_dim=3_2				,     intermediate_size=3_7				,     layer_norm_eps=1e-05				,     num_attention_heads=4				,     num_hidden_layers=5				,     pad_token_id=1				,     vocab_size=1_0_0_0				,     ))

							torch.manual_seed(0)
							__UpperCAmelCase			:							Tuple	    =	UNetaDConditionModel(
							    sample_size=3_2				,     in_channels=4				,     out_channels=4				,     down_block_types=('''CrossAttnDownBlock2D''', '''DownBlock2D''')				,     up_block_types=('''UpBlock2D''', '''CrossAttnUpBlock2D''')				,     block_out_channels=(3_2, 6_4)				,     attention_head_dim=(2, 4)				,     class_embed_type='''projection'''				,     projection_class_embeddings_input_dim=embedder_projection_dim * 2				,     cross_attention_dim=lowercase__				,     layers_per_block=1				,     upcast_attention=lowercase__				,     use_linear_projection=lowercase__				,     )

							torch.manual_seed(0)
							__UpperCAmelCase			:							Optional[Any]	    =	DDIMScheduler(
							    beta_schedule='''scaled_linear'''				,     beta_start=0.0_0_0_8_5				,     beta_end=0.0_1_2				,     prediction_type='''v_prediction'''				,     set_alpha_to_one=lowercase__				,     steps_offset=1				,     )

							torch.manual_seed(0)
							__UpperCAmelCase			:							Optional[Any]	    =	AutoencoderKL()

							__UpperCAmelCase			:							Optional[Any]	    =	{
							    # image encoding components
							    '''feature_extractor''': feature_extractor,
							    '''image_encoder''': image_encoder.eval(),
							    # image noising components
							    '''image_normalizer''': image_normalizer.eval(),
							    '''image_noising_scheduler''': image_noising_scheduler,
							    # regular denoising components
							    '''tokenizer''': tokenizer,
							    '''text_encoder''': text_encoder.eval(),
							    '''unet''': unet.eval(),
							    '''scheduler''': scheduler,
							    '''vae''': vae.eval(),
							}

							return components


	def  A(    self				,     lowercase__				,     lowercase__=0				,     lowercase__=True):
							if str(lowercase__).startswith('''mps'''):
													__UpperCAmelCase			:							Union[str, Any]	    =	torch.manual_seed(lowercase__)
							else:
													__UpperCAmelCase			:							int	    =	torch.Generator(device=lowercase__).manual_seed(lowercase__)

							__UpperCAmelCase			:							Dict	    =	floats_tensor((1, 3, 3_2, 3_2)				,     rng=random.Random(lowercase__)).to(lowercase__)

							if pil_image:
													__UpperCAmelCase			:							int	    =	input_image * 0.5 + 0.5
													__UpperCAmelCase			:							str	    =	input_image.clamp(0				,     1)
													__UpperCAmelCase			:							Optional[int]	    =	input_image.cpu().permute(0				,     2				,     3				,     1).float().numpy()
													__UpperCAmelCase			:							Union[str, Any]	    =	DiffusionPipeline.numpy_to_pil(lowercase__)[0]

							return {
							    "prompt": "An anime racoon running a marathon",
							    "image": input_image,
							    "generator": generator,
							    "num_inference_steps": 2,
							    "output_type": "np",
							}


	@skip_mps
	def  A(    self):
							__UpperCAmelCase			:							Union[str, Any]	    =	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
							__UpperCAmelCase			:							Dict	    =	self.get_dummy_components()
							__UpperCAmelCase			:							List[Any]	    =	StableUnCLIPImgaImgPipeline(**lowercase__)
							__UpperCAmelCase			:							List[str]	    =	sd_pipe.to(lowercase__)
							sd_pipe.set_progress_bar_config(disable=lowercase__)

							__UpperCAmelCase			:							Dict	    =	self.get_dummy_inputs(lowercase__)
							inputs.update({'''image_embeds''': None})
							__UpperCAmelCase			:							Any	    =	sd_pipe(**lowercase__).images
							__UpperCAmelCase			:							Union[str, Any]	    =	image[0, -3:, -3:, -1]

							assert image.shape == (1, 3_2, 3_2, 3)
							__UpperCAmelCase			:							Union[str, Any]	    =	np.array([0.3_8_7_2, 0.7_2_2_4, 0.5_6_0_1, 0.4_7_4_1, 0.6_8_7_2, 0.5_8_1_4, 0.4_6_3_6, 0.3_8_6_7, 0.5_0_7_8])

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


	def  A(    self):
							__UpperCAmelCase			:							Optional[Any]	    =	torch_device in ['''cpu''', '''mps''']

							self._test_attention_slicing_forward_pass(test_max_difference=lowercase__)


	def  A(    self):
							__UpperCAmelCase			:							str	    =	torch_device in ['''cpu''', '''mps''']

							self._test_inference_batch_single_identical(test_max_difference=lowercase__)


	@unittest.skipIf(
	    torch_device != '''cuda''' or not is_xformers_available()				,     reason='''XFormers attention is only available with CUDA and `xformers` installed'''				,     )
	def  A(    self):
							self._test_xformers_attention_forwardGenerator_pass(test_max_difference=lowercase__)






@slow
@require_torch_gpu
class 							lowerCamelCase   (  unittest.TestCase ):


	def  A(    self):
							# clean up the VRAM after each test
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()


	def  A(    self):
							__UpperCAmelCase			:							Dict	    =	load_image(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png''')

							__UpperCAmelCase			:							List[str]	    =	load_numpy(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/stable_unclip_2_1_l_img2img_anime_turtle_fp16.npy''')

							__UpperCAmelCase			:							Optional[int]	    =	StableUnCLIPImgaImgPipeline.from_pretrained(
							    '''fusing/stable-unclip-2-1-l-img2img'''				,     torch_dtype=torch.floataa)
							pipe.to(lowercase__)
							pipe.set_progress_bar_config(disable=lowercase__)
							# stable unclip will oom when integration tests are run on a V100,
							# so turn on memory savings
							pipe.enable_attention_slicing()
							pipe.enable_sequential_cpu_offload()

							__UpperCAmelCase			:							Optional[Any]	    =	torch.Generator(device='''cpu''').manual_seed(0)
							__UpperCAmelCase			:							Any	    =	pipe(lowercase__				,     '''anime turle'''				,     generator=lowercase__				,     output_type='''np''')

							__UpperCAmelCase			:							Optional[Any]	    =	output.images[0]

							assert image.shape == (7_6_8, 7_6_8, 3)

							assert_mean_pixel_difference(lowercase__				,     lowercase__)


	def  A(    self):
							__UpperCAmelCase			:							str	    =	load_image(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png''')

							__UpperCAmelCase			:							Union[str, Any]	    =	load_numpy(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/stable_unclip_2_1_h_img2img_anime_turtle_fp16.npy''')

							__UpperCAmelCase			:							Union[str, Any]	    =	StableUnCLIPImgaImgPipeline.from_pretrained(
							    '''fusing/stable-unclip-2-1-h-img2img'''				,     torch_dtype=torch.floataa)
							pipe.to(lowercase__)
							pipe.set_progress_bar_config(disable=lowercase__)
							# stable unclip will oom when integration tests are run on a V100,
							# so turn on memory savings
							pipe.enable_attention_slicing()
							pipe.enable_sequential_cpu_offload()

							__UpperCAmelCase			:							Dict	    =	torch.Generator(device='''cpu''').manual_seed(0)
							__UpperCAmelCase			:							int	    =	pipe(lowercase__				,     '''anime turle'''				,     generator=lowercase__				,     output_type='''np''')

							__UpperCAmelCase			:							List[str]	    =	output.images[0]

							assert image.shape == (7_6_8, 7_6_8, 3)

							assert_mean_pixel_difference(lowercase__				,     lowercase__)


	def  A(    self):
							__UpperCAmelCase			:							str	    =	load_image(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/turtle.png''')

							torch.cuda.empty_cache()
							torch.cuda.reset_max_memory_allocated()
							torch.cuda.reset_peak_memory_stats()

							__UpperCAmelCase			:							Optional[int]	    =	StableUnCLIPImgaImgPipeline.from_pretrained(
							    '''fusing/stable-unclip-2-1-h-img2img'''				,     torch_dtype=torch.floataa)
							__UpperCAmelCase			:							Optional[int]	    =	pipe.to(lowercase__)
							pipe.set_progress_bar_config(disable=lowercase__)
							pipe.enable_attention_slicing()
							pipe.enable_sequential_cpu_offload()

							__UpperCAmelCase			:							int	    =	pipe(
							    lowercase__				,     '''anime turtle'''				,     num_inference_steps=2				,     output_type='''np'''				,     )

							__UpperCAmelCase			:							Optional[Any]	    =	torch.cuda.max_memory_allocated()
							# make sure that less than 7 GB is allocated
							assert mem_bytes < 7 * 1_0**9

