



"""simple docstring"""
import unittest
from unittest import skip

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow
from transformers.trainer_utils import set_seed


if is_torch_available():
   import torch

   from transformers import JukeboxModel, JukeboxPrior, JukeboxTokenizer
@require_torch
class    a		(					unittest.TestCase    ):
  UpperCamelCase		:			int         =   (JukeboxModel,) if is_torch_available() else ()
  UpperCamelCase		:			Union[str, Any]         =   'openai/jukebox-1b-lyrics'
  UpperCamelCase		:			Optional[int]         =   {
      'artist': 'Zac Brown Band',
      'genres': 'Country',
      'lyrics': 'I met a traveller from an antique land,\n    Who said "Two vast and trunkless legs of stone\n    Stand in the desert. . . . Near them, on the sand,\n    Half sunk a shattered visage lies, whose frown,\n    And wrinkled lip, and sneer of cold command,\n    Tell that its sculptor well those passions read\n    Which yet survive, stamped on these lifeless things,\n    The hand that mocked them, and the heart that fed;\n    And on the pedestal, these words appear:\n    My name is Ozymandias, King of Kings;\n    Look on my Works, ye Mighty, and despair!\n    Nothing beside remains. Round the decay\n    Of that colossal Wreck, boundless and bare\n    The lone and level sands stretch far away\n    ',
  }
  # fmt: off
  UpperCamelCase		:			Any         =   [
      1_8_6_4, 1_5_3_6, 1_2_1_3, 1_8_7_0, 1_3_5_7, 1_5_3_6, 5_1_9, 8_8_0, 1_3_2_3, 7_8_9, 1_0_8_2, 5_3_4,
      1_0_0_0, 1_4_4_5, 1_1_0_5, 1_1_3_0, 9_6_7, 5_1_5, 1_4_3_4, 1_6_2_0, 5_3_4, 1_4_9_5, 2_8_3, 1_4_4_5,
      3_3_3, 1_3_0_7, 5_3_9, 1_6_3_1, 1_5_2_8, 3_7_5, 1_4_3_4, 6_7_3, 6_2_7, 7_1_0, 7_7_8, 1_8_8_3,
      1_4_0_5, 1_2_7_6, 1_4_5_5, 1_2_2_8
  ]

  UpperCamelCase		:			int         =   [
      1_4_8_9, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3
  ]

  UpperCamelCase		:			List[str]         =   [
      1_1_2_5, 1_7_5_1, 6_9_7, 1_7_7_6, 1_1_4_1, 1_4_7_6, 3_9_1, 6_9_7, 1_1_2_5, 6_8_4, 8_6_7, 4_1_6,
      8_4_4, 1_3_7_2, 1_2_7_4, 7_1_7, 1_2_7_4, 8_4_4, 1_2_9_9, 1_4_1_9, 6_9_7, 1_3_7_0, 3_1_7, 1_1_2_5,
      1_9_1, 1_4_4_0, 1_3_7_0, 1_4_4_0, 1_3_7_0, 2_8_2, 1_6_2_1, 1_3_7_0, 3_6_8, 3_4_9, 8_6_7, 1_8_7_2,
      1_2_6_2, 8_6_9, 1_7_2_8, 7_4_7
  ]
  UpperCamelCase		:			List[str]         =   [
      4_1_6, 4_1_6, 1_1_2_5, 1_1_2_5, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6
  ]

  UpperCamelCase		:			Optional[int]         =   [
      1_7_5_5, 8_4_2, 3_0_7, 1_8_4_3, 1_0_2_2, 1_3_9_5, 2_3_4, 1_5_5_4, 8_0_6, 7_3_9, 1_0_2_2, 4_4_2,
      6_1_6, 5_5_6, 2_6_8, 1_4_9_9, 9_3_3, 4_5_7, 1_4_4_0, 1_8_3_7, 7_5_5, 9_8_5, 3_0_8, 9_0_2,
      2_9_3, 1_4_4_3, 1_6_7_1, 1_1_4_1, 1_5_3_3, 5_5_5, 1_5_6_2, 1_0_6_1, 2_8_7, 4_1_7, 1_0_2_2, 2_0_0_8,
      1_1_8_6, 1_0_1_5, 1_7_7_7, 2_6_8
  ]
  UpperCamelCase		:			List[Any]         =   [
      8_5_4, 8_4_2, 1_3_5_3, 1_1_4, 1_3_5_3, 8_4_2, 1_8_5, 8_4_2, 1_8_5, 1_1_4, 5_9_1, 8_4_2,
      1_8_5, 4_1_7, 1_8_5, 8_4_2, 3_0_7, 8_4_2, 5_9_1, 8_4_2, 1_8_5, 8_4_2, 3_0_7, 8_4_2,
      5_9_1, 8_4_2, 1_3_5_3, 8_4_2, 1_8_5, 8_4_2, 5_9_1, 8_4_2, 5_9_1, 1_1_4, 5_9_1, 8_4_2,
      1_8_5, 8_4_2, 5_9_1, 8_9
  ]

  UpperCamelCase		:			Union[str, Any]         =   [1_0_5_8_3_0_4, 0, 7_8_6_4_3_2, 7_1_6_9, 5_0_7, 7_6, 2_7, 4_0, 3_0, 7_6]

  UpperCamelCase		:			int         =   [
      3_9_0, 1_1_6_0, 1_0_0_2, 1_9_0_7, 1_7_8_8, 1_7_8_8, 1_7_8_8, 1_9_0_7, 1_0_0_2, 1_0_0_2, 1_8_5_4, 1_0_0_2,
      1_0_0_2, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_1_6_0, 1_1_6_0, 1_6_0_6, 5_9_6, 5_9_6, 1_1_6_0, 1_0_0_2,
      1_5_1_6, 5_9_6, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_9_0_7, 1_7_8_8, 1_7_8_8, 1_7_8_8, 1_8_5_4, 1_7_8_8, 1_9_0_7,
      1_9_0_7, 1_7_8_8, 5_9_6, 1_6_2_6
  ]
  UpperCamelCase		:			str         =   [
      1_2_3_6, 1_6_6_8, 1_4_8_4, 1_9_2_0, 1_8_4_8, 1_4_0_9, 1_3_9, 8_6_4, 1_8_2_8, 1_2_7_2, 1_5_9_9, 8_2_4,
      1_6_7_2, 1_3_9, 5_5_5, 1_4_8_4, 8_2_4, 1_9_2_0, 5_5_5, 5_9_6, 1_5_7_9, 1_5_9_9, 1_2_3_1, 1_5_9_9,
      1_6_3_7, 1_4_0_7, 2_1_2, 8_2_4, 1_5_9_9, 1_1_6, 1_4_3_3, 8_2_4, 2_5_8, 1_5_9_9, 1_4_3_3, 1_8_9_5,
      1_0_6_3, 1_4_3_3, 1_4_3_3, 1_5_9_9
  ]
  UpperCamelCase		:			Optional[int]         =   [
      1_6_8_4, 1_8_7_3, 1_1_1_9, 1_1_8_9, 3_9_5, 6_1_1, 1_9_0_1, 9_7_2, 8_9_0, 1_3_3_7, 1_3_9_2, 1_9_2_7,
      9_6, 9_7_2, 6_7_2, 7_8_0, 1_1_1_9, 8_9_0, 1_5_8, 7_7_1, 1_0_7_3, 1_9_2_7, 3_5_3, 1_3_3_1,
      1_2_6_9, 1_4_5_9, 1_3_3_3, 1_6_4_5, 8_1_2, 1_5_7_7, 1_3_3_7, 6_0_6, 3_5_3, 9_8_1, 1_4_6_6, 6_1_9,
      1_9_7, 3_9_1, 3_0_2, 1_9_3_0
  ]
  UpperCamelCase		:			int         =   [
      3_9_0, 1_1_6_0, 1_0_0_2, 1_9_0_7, 1_7_8_8, 1_7_8_8, 1_7_8_8, 1_9_0_7, 1_0_0_2, 1_0_0_2, 1_8_5_4, 1_0_0_2,
      1_0_0_2, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_1_6_0, 1_1_6_0, 1_6_0_6, 5_9_6, 5_9_6, 1_1_6_0, 1_0_0_2,
      1_5_1_6, 5_9_6, 1_0_0_2, 1_0_0_2, 1_0_0_2, 1_9_0_7, 1_7_8_8, 1_7_8_8, 1_7_8_8, 1_8_5_4, 1_7_8_8, 1_9_0_7,
      1_9_0_7, 1_7_8_8, 5_9_6, 1_6_2_6
  ]
  UpperCamelCase		:			List[str]         =   [
      -0.04_92, -0.05_24, -0.05_65, -0.06_40, -0.06_86, -0.06_84, -0.06_77, -0.06_64,
      -0.06_05, -0.04_90, -0.03_30, -0.01_68, -0.00_83, -0.00_75, -0.00_51, 0.00_25,
      0.01_36, 0.02_61, 0.03_86, 0.04_97, 0.05_80, 0.05_99, 0.05_83, 0.06_14,
      0.07_40, 0.08_89, 0.10_23, 0.11_62, 0.12_11, 0.12_12, 0.12_51, 0.13_36,
      0.15_02, 0.16_86, 0.18_83, 0.21_48, 0.23_63, 0.24_58, 0.25_07, 0.25_31
  ]
  UpperCamelCase		:			List[str]         =   [
      0.02_56, -0.05_44, 0.16_00, -0.00_32, 0.10_66, 0.08_25, -0.00_13, 0.34_40,
      0.02_10, 0.04_12, -0.17_77, -0.08_92, -0.01_64, 0.02_85, -0.06_13, -0.06_17,
      -0.01_37, -0.02_01, -0.01_75, 0.02_15, -0.06_27, 0.05_20, -0.07_30, 0.09_70,
      -0.01_00, 0.04_42, -0.05_86, 0.02_07, -0.00_15, -0.00_82
  ]
  UpperCamelCase		:			Optional[int]         =   [
      0.04_15, 0.08_77, 0.00_22, -0.00_55, 0.07_51, 0.03_34, 0.03_24, -0.00_68,
      0.00_11, 0.00_17, -0.06_76, 0.06_55, -0.01_43, 0.03_99, 0.03_03, 0.07_43,
      -0.01_68, -0.03_94, -0.11_13, 0.01_24, 0.04_42, 0.02_67, -0.00_03, -0.15_36,
      -0.01_16, -0.18_37, -0.01_80, -0.10_26, -0.07_77, -0.04_56
  ]
  UpperCamelCase		:			Optional[Any]         =   [
      7_6, 2_7, 4_0, 3_0, 7_6, 4_6, 4_4, 4_7, 4_0, 3_7, 3_8, 3_1, 4_5, 4_5, 7_6, 3_8, 3_1, 3_3,
      4_5, 7_6, 4_1, 3_2, 7_6, 4_5, 4_6, 4_1, 4_0, 3_1, 7_8, 7_6
  ]



  def 		lowerCamelCase__    (  self	:   int						)       ->   Optional[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Any            =JukeboxTokenizer.from_pretrained(self.model_id						)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =tokenizer(**self.metas						)["""input_ids"""]
     return tokens



  @slow
  def 		lowerCamelCase__    (  self	:   Union[str, Any]						)       ->   Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Dict            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()
     SCREAMING_SNAKE_CASE_:	Any            =self.prepare_inputs()

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	str            =[torch.zeros(1    ,						0    ,						dtype=torch.long						).cpu() for _ in range(3						)]
     SCREAMING_SNAKE_CASE_:	Optional[int]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[0]    ,						sample_length=40 * model.priors[0].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[0][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_2, self.EXPECTED_OUTPUT_2_PT_2]						)

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	List[str]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[1]    ,						sample_length=40 * model.priors[1].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[1][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_1, self.EXPECTED_OUTPUT_1_PT_2]						)

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	List[str]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[2]    ,						sample_length=40 * model.priors[2].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[2][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_0, self.EXPECTED_OUTPUT_0_PT_2]						)



  @slow
  def 		lowerCamelCase__    (  self	:   str						)       ->   str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Tuple            =False
     SCREAMING_SNAKE_CASE_:	int            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()

     SCREAMING_SNAKE_CASE_:	Tuple            =self.prepare_inputs()
     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	Tuple            =[torch.zeros(1    ,						0    ,						dtype=torch.long						) for _ in range(3						)]

     SCREAMING_SNAKE_CASE_:	Any            =model.priors[0]
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =0
     SCREAMING_SNAKE_CASE_:	Tuple            =top_prior.get_music_tokens_conds(__UpperCamelCase    ,						start=__UpperCamelCase    ,						end=start + top_prior.n_ctx						)
     SCREAMING_SNAKE_CASE_:	Tuple            =top_prior.get_metadata(labels[0].clone()    ,						__UpperCamelCase    ,						105_8304    ,						0						)

     self.assertIsNone(__UpperCamelCase						)
     self.assertListEqual(metadata.numpy()[0][:10].tolist()    ,						self.EXPECTED_Y_COND						)

     SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_:	Dict            =top_prior.get_cond(__UpperCamelCase    ,						__UpperCamelCase						)
     torch.testing.assert_allclose(
         audio_conditioning[0][0][:30].detach()    ,						torch.tensor(self.EXPECTED_AUDIO_COND						)    ,						atol=1E-4    ,						rtol=1E-4						)
     torch.testing.assert_allclose(
         metadata_conditioning[0][0][:30].detach()    ,						torch.tensor(self.EXPECTED_META_COND						)    ,						atol=1E-4    ,						rtol=1E-4						)
     torch.testing.assert_allclose(
         lyric_tokens[0, :30].detach()    ,						torch.tensor(self.EXPECTED_LYRIC_COND						)    ,						atol=1E-4    ,						rtol=1E-4						)



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	List[Any]            =False

     SCREAMING_SNAKE_CASE_:	List[Any]            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()
     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	List[str]            =torch.rand((1, 5120, 1)						)
     SCREAMING_SNAKE_CASE_:	str            =list(self.prepare_inputs()						)

     SCREAMING_SNAKE_CASE_:	int            =[model.vqvae.encode(__UpperCamelCase    ,						start_level=2    ,						bs_chunks=waveform.shape[0]						)[0], None, None]
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =model._sample(
         __UpperCamelCase    ,						__UpperCamelCase    ,						sample_levels=[0]    ,						save_results=__UpperCamelCase    ,						sample_length=40 * model.priors[0].raw_to_tokens						)
     torch.testing.assert_allclose(zs[0][0][:40]    ,						torch.tensor(self.EXPECTED_PRIMED_0						)						)

     SCREAMING_SNAKE_CASE_:	Optional[Any]            =torch.cat((zs[0], torch.zeros(1    ,						2048 - zs[0].shape[-1]						))    ,						dim=-1						).long()
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =[upper_a, model.vqvae.encode(__UpperCamelCase    ,						start_level=1    ,						bs_chunks=waveform.shape[0]						)[0], None]
     SCREAMING_SNAKE_CASE_:	Tuple            =model._sample(
         __UpperCamelCase    ,						__UpperCamelCase    ,						sample_levels=[1]    ,						save_results=__UpperCamelCase    ,						sample_length=40 * model.priors[1].raw_to_tokens						)
     torch.testing.assert_allclose(zs[1][0][:40]    ,						torch.tensor(self.EXPECTED_PRIMED_1						)						)

     SCREAMING_SNAKE_CASE_:	List[Any]            =torch.cat((zs[1], torch.zeros(1    ,						2048 - zs[1].shape[-1]						))    ,						dim=-1						).long()
     SCREAMING_SNAKE_CASE_:	Any            =[upper_a, upper_a, model.vqvae.encode(__UpperCamelCase    ,						start_level=0    ,						bs_chunks=waveform.shape[0]						)[0]]
     SCREAMING_SNAKE_CASE_:	Optional[int]            =model._sample(
         __UpperCamelCase    ,						__UpperCamelCase    ,						sample_levels=[2]    ,						save_results=__UpperCamelCase    ,						sample_length=40 * model.priors[2].raw_to_tokens						)
     torch.testing.assert_allclose(zs[2][0][:40].cpu()    ,						torch.tensor(self.EXPECTED_PRIMED_2						)						)





  @slow
  def 		lowerCamelCase__    (  self	:   Dict						)       ->   Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	int            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()
     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	Any            =torch.rand((1, 5120, 1)						)
     with torch.no_grad():
        SCREAMING_SNAKE_CASE_:	int            =model.vqvae.encode(__UpperCamelCase    ,						start_level=2    ,						bs_chunks=x.shape[0]						)
     torch.testing.assert_allclose(zs[0][0]    ,						torch.tensor(self.EXPECTED_VQVAE_ENCODE						)						)

     with torch.no_grad():
        SCREAMING_SNAKE_CASE_:	List[Any]            =model.vqvae.decode(__UpperCamelCase    ,						start_level=2    ,						bs_chunks=x.shape[0]						)
     torch.testing.assert_allclose(x[0, :40, 0]    ,						torch.tensor(self.EXPECTED_VQVAE_DECODE						)    ,						atol=1E-4    ,						rtol=1E-4						)







@require_torch
class    a		(					unittest.TestCase    ):
  UpperCamelCase		:			Optional[int]         =   (JukeboxModel,) if is_torch_available() else ()
  UpperCamelCase		:			str         =   'openai/jukebox-5b-lyrics'
  UpperCamelCase		:			Tuple         =   {
      'artist': 'Zac Brown Band',
      'genres': 'Country',
      'lyrics': 'I met a traveller from an antique land,\n    Who said "Two vast and trunkless legs of stone\n    Stand in the desert. . . . Near them, on the sand,\n    Half sunk a shattered visage lies, whose frown,\n    And wrinkled lip, and sneer of cold command,\n    Tell that its sculptor well those passions read\n    Which yet survive, stamped on these lifeless things,\n    The hand that mocked them, and the heart that fed;\n    And on the pedestal, these words appear:\n    My name is Ozymandias, King of Kings;\n    Look on my Works, ye Mighty, and despair!\n    Nothing beside remains. Round the decay\n    Of that colossal Wreck, boundless and bare\n    The lone and level sands stretch far away\n    ',
  }

  # fmt: off
  UpperCamelCase		:			List[str]         =   [
      1_4_8_9, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      1_4_8_9, 1_4_8_9, 1_4_8_9, 1_4_8_9, 1_1_5_0, 1_8_5_3, 1_5_0_9, 1_1_5_0, 1_3_5_7, 1_5_0_9, 6, 1_2_7_2
  ]
  UpperCamelCase		:			Optional[int]         =   [
      1_4_8_9, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3
  ]

  UpperCamelCase		:			Optional[int]         =   [
      1_1_2_5, 4_1_6, 1_1_2_5, 1_1_2_5, 1_1_2_5, 1_1_2_5, 1_1_2_5, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6
  ]
  UpperCamelCase		:			Optional[int]         =   [
      4_1_6, 4_1_6, 1_1_2_5, 1_1_2_5, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6
  ]

  UpperCamelCase		:			Optional[int]         =   [
      1_7_5_5, 1_0_6_1, 2_3_4, 1_7_5_5, 1_0_6_1, 1_7_5_5, 1_8_5, 2_9_0, 3_0_7, 3_0_7, 6_1_6, 6_1_6,
      6_1_6, 6_1_6, 6_1_6, 6_1_6, 3_0_7, 2_9_0, 4_1_7, 1_7_5_5, 2_3_4, 1_7_5_5, 1_8_5, 2_9_0,
      2_9_0, 2_9_0, 3_0_7, 6_1_6, 6_1_6, 6_1_6, 6_1_6, 6_1_6, 2_9_0, 2_3_4, 2_3_4, 1_7_5_5,
      2_3_4, 2_3_4, 1_7_5_5, 2_3_4, 1_8_5, 1_8_5, 3_0_7, 6_1_6, 6_1_6, 6_1_6, 6_1_6, 2_9_0,
      1_7_5_5, 1_7_5_5, 1_7_5_5, 2_3_4, 2_3_4, 1_7_5_5, 1_5_7_2, 2_9_0, 3_0_7, 6_1_6, 3_4, 6_1_6
  ]
  UpperCamelCase		:			Any         =   [
      8_5_4, 8_4_2, 1_3_5_3, 1_1_4, 1_3_5_3, 8_4_2, 1_8_5, 8_4_2, 1_8_5, 1_1_4, 5_9_1, 8_4_2, 1_8_5,
      4_1_7, 1_8_5, 8_4_2, 3_0_7, 8_4_2, 5_9_1, 8_4_2, 1_8_5, 8_4_2, 1_8_5, 8_4_2, 5_9_1, 8_4_2,
      1_3_5_3, 8_4_2, 1_8_5, 8_4_2, 5_9_1, 8_4_2, 5_9_1, 1_1_4, 5_9_1, 8_4_2, 1_8_5, 8_4_2, 5_9_1,
      8_9, 5_9_1, 8_4_2, 5_9_1, 8_4_2, 5_9_1, 4_1_7, 1_3_7_2, 8_4_2, 1_3_7_2, 8_4_2, 3_4, 8_4_2,
      1_8_5, 8_9, 5_9_1, 8_4_2, 1_8_5, 8_4_2, 5_9_1, 6_3_2
  ]

  UpperCamelCase		:			Optional[Any]         =   [
      1_4_8_9, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3
  ]
  UpperCamelCase		:			str         =   [
      1_4_8_9, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3,
      6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 6_5_3, 1_8_5_3, 1_1_7_7, 1_5_3_6, 1_2_2_8,
      7_1_0, 4_7_5, 1_4_8_9, 1_2_2_9, 1_2_2_4, 2_3_1, 1_2_2_4, 2_5_2, 1_4_3_4, 6_5_3, 4_7_5,
      1_1_0_6, 1_8_7_7, 1_5_9_9, 1_2_2_8, 1_6_0_0, 1_6_8_3, 1_1_8_2, 1_8_5_3, 4_7_5, 1_8_6_4,
      2_5_2, 1_2_2_9, 1_4_3_4, 2_0_0_1
  ]

  UpperCamelCase		:			List[Any]         =   [
      1_1_2_5, 1_1_2_5, 4_1_6, 1_1_2_5, 1_1_2_5, 4_1_6, 1_1_2_5, 1_1_2_5, 4_1_6, 4_1_6, 1_1_2_5, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6,
      4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6, 4_1_6
  ]
  UpperCamelCase		:			List[Any]         =   [
      4_9_1, 1_7_5_5, 3_4, 1_6_1_3, 1_7_5_5, 4_1_7, 9_9_2, 1_6_1_3, 2_2_2, 8_4_2, 1_3_5_3, 1_6_1_3,
      8_4_4, 6_3_2, 1_8_5, 1_6_1_3, 8_4_4, 6_3_2, 1_8_5, 1_6_1_3, 1_8_5, 8_4_2, 6_7_7, 1_6_1_3,
      1_8_5, 1_1_4, 1_3_5_3, 1_6_1_3, 3_0_7, 8_9, 8_4_4, 1_6_1_3, 3_0_7, 1_3_3_2, 2_3_4, 1_9_7_9,
      3_0_7, 8_9, 1_3_5_3, 6_1_6, 3_4, 8_4_2, 1_8_5, 8_4_2, 3_4, 8_4_2, 1_8_5, 8_4_2,
      3_0_7, 1_1_4, 1_8_5, 8_9, 3_4, 1_2_6_8, 1_8_5, 8_9, 3_4, 8_4_2, 1_8_5, 8_9
  ]



  def 		lowerCamelCase__    (  self	:   Optional[Any]    ,						lowerCAmelCase	:   Union[str, Any]						)       ->   Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Optional[int]            =JukeboxTokenizer.from_pretrained(__UpperCamelCase						)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =tokenizer(**self.metas						)["""input_ids"""]
     return tokens



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Tuple            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()
     SCREAMING_SNAKE_CASE_:	Any            =self.prepare_inputs(self.model_id						)

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =[torch.zeros(1    ,						0    ,						dtype=torch.long						).cpu() for _ in range(3						)]
     SCREAMING_SNAKE_CASE_:	Any            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[0]    ,						sample_length=60 * model.priors[0].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[0][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_2, self.EXPECTED_OUTPUT_2_PT_2]						)

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	Optional[int]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[1]    ,						sample_length=60 * model.priors[1].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[1][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_1, self.EXPECTED_OUTPUT_1_PT_2]						)

     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	List[Any]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[2]    ,						sample_length=60 * model.priors[2].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     self.assertIn(zs[2][0].detach().cpu().tolist()    ,						[self.EXPECTED_OUTPUT_0, self.EXPECTED_OUTPUT_0_PT_2]						)



  @slow
  @skip("""Not enough GPU memory on CI runners"""						)
  def 		lowerCamelCase__    (  self	:   int						)       ->   List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Optional[Any]            =JukeboxModel.from_pretrained(self.model_id    ,						min_duration=0						).eval()
     SCREAMING_SNAKE_CASE_:	Dict            =[i.cuda() for i in self.prepare_inputs(self.model_id						)]

     set_seed(0						)
     model.priors[0].cuda()
     SCREAMING_SNAKE_CASE_:	Dict            =[torch.zeros(1    ,						0    ,						dtype=torch.long						).cuda() for _ in range(3						)]
     SCREAMING_SNAKE_CASE_:	str            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[0]    ,						sample_length=60 * model.priors[0].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     torch.testing.assert_allclose(zs[0][0].cpu()    ,						torch.tensor(self.EXPECTED_GPU_OUTPUTS_2						)						)
     model.priors[0].cpu()

     set_seed(0						)
     model.priors[1].cuda()
     SCREAMING_SNAKE_CASE_:	Optional[int]            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[1]    ,						sample_length=60 * model.priors[1].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     torch.testing.assert_allclose(zs[1][0].cpu()    ,						torch.tensor(self.EXPECTED_GPU_OUTPUTS_1						)						)
     model.priors[1].cpu()

     set_seed(0						)
     model.priors[2].cuda()
     SCREAMING_SNAKE_CASE_:	Dict            =model._sample(__UpperCamelCase    ,						__UpperCamelCase    ,						[2]    ,						sample_length=60 * model.priors[2].raw_to_tokens    ,						save_results=__UpperCamelCase						)
     torch.testing.assert_allclose(zs[2][0].cpu()    ,						torch.tensor(self.EXPECTED_GPU_OUTPUTS_0						)						)





  @slow
  def 		lowerCamelCase__    (  self	:   Union[str, Any]						)       ->   Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Dict            ="""ArthurZ/jukebox_prior_0"""
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =JukeboxPrior.from_pretrained(__UpperCamelCase    ,						min_duration=0						).eval().half().to("""cuda"""						)

     SCREAMING_SNAKE_CASE_:	Optional[Any]            =self.prepare_inputs(__UpperCamelCase						)[0].cuda()
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =model.get_metadata(__UpperCamelCase    ,						0    ,						7680    ,						0						)
     set_seed(0						)
     SCREAMING_SNAKE_CASE_:	Any            =model.sample(1    ,						metadata=__UpperCamelCase    ,						sample_tokens=60						)
     self.assertIn(outputs[0].cpu().tolist()    ,						[self.EXPECTED_GPU_OUTPUTS_2, self.EXPECTED_GPU_OUTPUTS_2_PT_2]						)








"""simple docstring"""
import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPImageProcessor, CLIPVisionConfig

from diffusers import AutoencoderKL, PaintByExamplePipeline, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.paint_by_example import PaintByExampleImageEncoder
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()
class    a		(					UpperCAmelCase__		, unittest.TestCase    ):
  UpperCamelCase		:			Dict         =   PaintByExamplePipeline
  UpperCamelCase		:			str         =   IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
  UpperCamelCase		:			Tuple         =   IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
  UpperCamelCase		:			List[str]         =   frozenset([]    )  # TO_DO: update the image_prams once refactored VaeImageProcessor.preprocess



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


     '''simple docstring'''




     torch.manual_seed(0						)
     SCREAMING_SNAKE_CASE_:	Any            =UNetaDConditionModel(
         block_out_channels=(32, 64)    ,						layers_per_block=2    ,						sample_size=32    ,						in_channels=9    ,						out_channels=4    ,						down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")    ,						up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")    ,						cross_attention_dim=32    ,						)
     SCREAMING_SNAKE_CASE_:	int            =PNDMScheduler(skip_prk_steps=lowerCAmelCase						)
     torch.manual_seed(0						)
     SCREAMING_SNAKE_CASE_:	str            =AutoencoderKL(
         block_out_channels=[32, 64]    ,						in_channels=3    ,						out_channels=3    ,						down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]    ,						up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]    ,						latent_channels=4    ,						)
     torch.manual_seed(0						)
     SCREAMING_SNAKE_CASE_:	Tuple            =CLIPVisionConfig(
         hidden_size=32    ,						projection_dim=32    ,						intermediate_size=37    ,						layer_norm_eps=1E-05    ,						num_attention_heads=4    ,						num_hidden_layers=5    ,						image_size=32    ,						patch_size=4    ,						)
     SCREAMING_SNAKE_CASE_:	List[Any]            =PaintByExampleImageEncoder(lowerCAmelCase    ,						proj_size=32						)
     SCREAMING_SNAKE_CASE_:	Tuple            =CLIPImageProcessor(crop_size=32    ,						size=32						)

     SCREAMING_SNAKE_CASE_:	Any            ={
         """unet""": unet,
         """scheduler""": scheduler,
         """vae""": vae,
         """image_encoder""": image_encoder,
         """safety_checker""": None,
         """feature_extractor""": feature_extractor,
     }
     return components



  def 		lowerCamelCase__    (  self	:   str    ,						lowerCAmelCase	:   Dict						)       ->   Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Union[str, Any]            =np.array(image.convert("""RGB"""						)						)
     SCREAMING_SNAKE_CASE_:	Optional[int]            =image[None].transpose(0    ,						3    ,						1    ,						2						)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =torch.from_numpy(lowerCAmelCase						).to(dtype=torch.floataa						) / 1_2_7.5 - 1.0
     return image



  def 		lowerCamelCase__    (  self	:   Union[str, Any]    ,						lowerCAmelCase	:   int="cpu"    ,						lowerCAmelCase	:   Dict=0						)       ->   Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	str            =floats_tensor((1, 3, 32, 32)    ,						rng=random.Random(lowerCAmelCase						)						).to(lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	Tuple            =image.cpu().permute(0    ,						2    ,						3    ,						1						)[0]
     SCREAMING_SNAKE_CASE_:	Any            =Image.fromarray(np.uinta(lowerCAmelCase						)						).convert("""RGB"""						).resize((64, 64)						)
     SCREAMING_SNAKE_CASE_:	Tuple            =Image.fromarray(np.uinta(image + 4						)						).convert("""RGB"""						).resize((64, 64)						)
     SCREAMING_SNAKE_CASE_:	List[str]            =Image.fromarray(np.uinta(lowerCAmelCase						)						).convert("""RGB"""						).resize((32, 32)						)

     if str(lowerCAmelCase						).startswith("""mps"""						):
        SCREAMING_SNAKE_CASE_:	Dict            =torch.manual_seed(lowerCAmelCase						)
     else:
        SCREAMING_SNAKE_CASE_:	Optional[Any]            =torch.Generator(device=lowerCAmelCase						).manual_seed(lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	str            ={
         """example_image""": example_image,
         """image""": init_image,
         """mask_image""": mask_image,
         """generator""": generator,
         """num_inference_steps""": 2,
         """guidance_scale""": 6.0,
         """output_type""": """numpy""",
     }
     return inputs



  def 		lowerCamelCase__    (  self	:   List[Any]						)       ->   Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Tuple            =self.get_dummy_components()

     # make sure here that pndm scheduler skips prk
     SCREAMING_SNAKE_CASE_:	Union[str, Any]            =PaintByExamplePipeline(**lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	Any            =pipe.to("""cpu"""						)
     pipe.set_progress_bar_config(disable=lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:	Optional[int]            =self.get_dummy_inputs()
     SCREAMING_SNAKE_CASE_:	int            =pipe(**lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	int            =output.images

     SCREAMING_SNAKE_CASE_:	List[str]            =image[0, -3:, -3:, -1]

     assert image.shape == (1, 64, 64, 3)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =np.array([0.4_6_8_6, 0.5_6_8_7, 0.4_0_0_7, 0.5_2_1_8, 0.5_7_4_1, 0.4_4_8_2, 0.4_9_4_0, 0.4_6_2_9, 0.4_5_0_3]						)

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



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Optional[Any]            ="""cpu"""
     SCREAMING_SNAKE_CASE_:	Any            =self.get_dummy_inputs()
     inputs.pop("""mask_image"""						)
     SCREAMING_SNAKE_CASE_:	List[str]            =self.convert_to_pt(inputs.pop("""image"""						)						)
     SCREAMING_SNAKE_CASE_:	int            =image.clamp(0    ,						1						) / 2

     # make sure here that pndm scheduler skips prk
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =PaintByExamplePipeline(**self.get_dummy_components()						)
     SCREAMING_SNAKE_CASE_:	List[Any]            =pipe.to(lowerCAmelCase						)
     pipe.set_progress_bar_config(disable=lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:	int            =pipe(image=lowerCAmelCase    ,						mask_image=mask_image[:, 0]    ,						**lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	int            =output.images

     SCREAMING_SNAKE_CASE_:	str            =image.cpu().permute(0    ,						2    ,						3    ,						1						)[0]
     SCREAMING_SNAKE_CASE_:	List[Any]            =mask_image.cpu().permute(0    ,						2    ,						3    ,						1						)[0]

     SCREAMING_SNAKE_CASE_:	str            =Image.fromarray(np.uinta(lowerCAmelCase						)						).convert("""RGB"""						)
     SCREAMING_SNAKE_CASE_:	Tuple            =Image.fromarray(np.uinta(lowerCAmelCase						)						).convert("""RGB"""						)

     SCREAMING_SNAKE_CASE_:	int            =pipe(**self.get_dummy_inputs()						)
     SCREAMING_SNAKE_CASE_:	Optional[int]            =output.images

     assert out_a.shape == (1, 64, 64, 3)
     assert np.abs(out_a.flatten() - out_a.flatten()						).max() < 5E-2





  def 		lowerCamelCase__    (  self	:   Optional[Any]						)       ->   Dict:


     '''simple docstring'''




     super().test_inference_batch_single_identical(expected_max_diff=3E-3						)







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



  def 		lowerCamelCase__    (  self	:   Dict						)       ->   Any:


     '''simple docstring'''




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





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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	List[str]            =load_image(
         """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
         """/paint_by_example/dog_in_bucket.png"""						)
     SCREAMING_SNAKE_CASE_:	Tuple            =load_image(
         """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
         """/paint_by_example/mask.png"""						)
     SCREAMING_SNAKE_CASE_:	List[str]            =load_image(
         """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
         """/paint_by_example/panda.jpg"""						)

     SCREAMING_SNAKE_CASE_:	Tuple            =PaintByExamplePipeline.from_pretrained("""Fantasy-Studio/Paint-by-Example"""						)
     SCREAMING_SNAKE_CASE_:	Optional[int]            =pipe.to(lowerCAmelCase						)
     pipe.set_progress_bar_config(disable=lowerCAmelCase						)

     SCREAMING_SNAKE_CASE_:	str            =torch.manual_seed(321						)
     SCREAMING_SNAKE_CASE_:	Optional[Any]            =pipe(
         image=lowerCAmelCase    ,						mask_image=lowerCAmelCase    ,						example_image=lowerCAmelCase    ,						generator=lowerCAmelCase    ,						guidance_scale=5.0    ,						num_inference_steps=50    ,						output_type="""np"""    ,						)

     SCREAMING_SNAKE_CASE_:	Union[str, Any]            =output.images

     SCREAMING_SNAKE_CASE_:	Any            =image[0, -3:, -3:, -1]

     assert image.shape == (1, 512, 512, 3)
     SCREAMING_SNAKE_CASE_:	Any            =np.array([0.4_8_3_4, 0.4_8_1_1, 0.4_8_7_4, 0.5_1_2_2, 0.5_0_8_1, 0.5_1_4_4, 0.5_2_9_1, 0.5_2_9_0, 0.5_3_7_4]						)

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



