



"""simple docstring"""






import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, PLBartTokenizer, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase__              =							get_tests_dir('''fixtures/test_sentencepiece.model''')


if is_torch_available():
   from transformers.models.plbart.modeling_plbart import shift_tokens_right

lowerCAmelCase__              =							50003
lowerCAmelCase__              =							50002






@require_sentencepiece
@require_tokenizers
class 			__snake_case			(      _lowercase    ,	unittest.TestCase):
  snake_case__							:  Tuple         =		PLBartTokenizer
  snake_case__							:  Optional[int]         =		None
  snake_case__							:  List[str]         =		False




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         super().setUp()

         # We have a SentencePiece fixture for testing
         _lowerCamelCase		:							Optional[int]            =					PLBartTokenizer(__lowerCAmelCase		,   language_codes='''base'''		,   keep_accents=__lowerCAmelCase						)
         tokenizer.save_pretrained(self.tmpdirname						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[int]            =					PLBartTokenizer(__lowerCAmelCase		,   language_codes='''base'''		,   keep_accents=__lowerCAmelCase						)

         _lowerCamelCase		:							Optional[Any]            =					tokenizer.tokenize('''This is a test'''						)
         self.assertListEqual(__lowerCAmelCase		,   ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']						)

         self.assertListEqual(
             tokenizer.convert_tokens_to_ids(__lowerCAmelCase						)		,   [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]		,   )

         _lowerCamelCase		:							Optional[int]            =					tokenizer.tokenize('''I was born in 92000, and this is falsé.'''						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 SPIECE_UNDERLINE + '''I''',
                 SPIECE_UNDERLINE + '''was''',
                 SPIECE_UNDERLINE + '''b''',
                 '''or''',
                 '''n''',
                 SPIECE_UNDERLINE + '''in''',
                 SPIECE_UNDERLINE + '''''',
                 '''9''',
                 '''2''',
                 '''0''',
                 '''0''',
                 '''0''',
                 ''',''',
                 SPIECE_UNDERLINE + '''and''',
                 SPIECE_UNDERLINE + '''this''',
                 SPIECE_UNDERLINE + '''is''',
                 SPIECE_UNDERLINE + '''f''',
                 '''al''',
                 '''s''',
                 '''é''',
                 '''.''',
             ]		,   )
         _lowerCamelCase		:							Union[str, Any]            =					tokenizer.convert_tokens_to_ids(__lowerCAmelCase						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 value + tokenizer.fairseq_offset
                 for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
             ]		,   )

         _lowerCamelCase		:							Any            =					tokenizer.convert_ids_to_tokens(__lowerCAmelCase						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 SPIECE_UNDERLINE + '''I''',
                 SPIECE_UNDERLINE + '''was''',
                 SPIECE_UNDERLINE + '''b''',
                 '''or''',
                 '''n''',
                 SPIECE_UNDERLINE + '''in''',
                 SPIECE_UNDERLINE + '''''',
                 '''<unk>''',
                 '''2''',
                 '''0''',
                 '''0''',
                 '''0''',
                 ''',''',
                 SPIECE_UNDERLINE + '''and''',
                 SPIECE_UNDERLINE + '''this''',
                 SPIECE_UNDERLINE + '''is''',
                 SPIECE_UNDERLINE + '''f''',
                 '''al''',
                 '''s''',
                 '''<unk>''',
                 '''.''',
             ]		,   )

         _lowerCamelCase		:							Dict            =					tokenizer.vocab_size
         _lowerCamelCase		:							Union[str, Any]            =					[tokenizer.convert_ids_to_tokens(__lowerCAmelCase						) for x in range(end - 4		,   __lowerCAmelCase						)]

         self.assertListEqual(__lowerCAmelCase		,   ['''__java__''', '''__python__''', '''__en_XX__''', '''<mask>''']						)

         _lowerCamelCase		:							Tuple            =					'''java.lang.Exception, python.lang.Exception, javascript, php, ruby, go'''
         _lowerCamelCase		:							Any            =					tokenizer(__lowerCAmelCase						).input_ids
         self.assertEqual(
             tokenizer.decode(__lowerCAmelCase		,   skip_special_tokens=__lowerCAmelCase		,   clean_up_tokenization_spaces=__lowerCAmelCase						)		,   __lowerCAmelCase		,   )




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         _lowerCamelCase		:							List[Any]            =					PLBartTokenizer(__lowerCAmelCase		,   language_codes='''multi'''		,   keep_accents=__lowerCAmelCase						)

         _lowerCamelCase		:							Optional[int]            =					tokenizer.tokenize('''This is a test'''						)
         self.assertListEqual(__lowerCAmelCase		,   ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']						)

         self.assertListEqual(
             tokenizer.convert_tokens_to_ids(__lowerCAmelCase						)		,   [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]		,   )

         _lowerCamelCase		:							Union[str, Any]            =					tokenizer.tokenize('''I was born in 92000, and this is falsé.'''						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 SPIECE_UNDERLINE + '''I''',
                 SPIECE_UNDERLINE + '''was''',
                 SPIECE_UNDERLINE + '''b''',
                 '''or''',
                 '''n''',
                 SPIECE_UNDERLINE + '''in''',
                 SPIECE_UNDERLINE + '''''',
                 '''9''',
                 '''2''',
                 '''0''',
                 '''0''',
                 '''0''',
                 ''',''',
                 SPIECE_UNDERLINE + '''and''',
                 SPIECE_UNDERLINE + '''this''',
                 SPIECE_UNDERLINE + '''is''',
                 SPIECE_UNDERLINE + '''f''',
                 '''al''',
                 '''s''',
                 '''é''',
                 '''.''',
             ]		,   )
         _lowerCamelCase		:							Tuple            =					tokenizer.convert_tokens_to_ids(__lowerCAmelCase						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 value + tokenizer.fairseq_offset
                 for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
             ]		,   )

         _lowerCamelCase		:							Optional[int]            =					tokenizer.convert_ids_to_tokens(__lowerCAmelCase						)
         self.assertListEqual(
             __lowerCAmelCase		,   [
                 SPIECE_UNDERLINE + '''I''',
                 SPIECE_UNDERLINE + '''was''',
                 SPIECE_UNDERLINE + '''b''',
                 '''or''',
                 '''n''',
                 SPIECE_UNDERLINE + '''in''',
                 SPIECE_UNDERLINE + '''''',
                 '''<unk>''',
                 '''2''',
                 '''0''',
                 '''0''',
                 '''0''',
                 ''',''',
                 SPIECE_UNDERLINE + '''and''',
                 SPIECE_UNDERLINE + '''this''',
                 SPIECE_UNDERLINE + '''is''',
                 SPIECE_UNDERLINE + '''f''',
                 '''al''',
                 '''s''',
                 '''<unk>''',
                 '''.''',
             ]		,   )
         _lowerCamelCase		:							str            =					tokenizer.vocab_size
         _lowerCamelCase		:							Any            =					[tokenizer.convert_ids_to_tokens(__lowerCAmelCase						) for x in range(end - 7		,   __lowerCAmelCase						)]

         self.assertListEqual(
             __lowerCAmelCase		,   ['''__java__''', '''__python__''', '''__en_XX__''', '''__javascript__''', '''__php__''', '''__ruby__''', '''__go__''']						)
         _lowerCamelCase		:							Tuple            =					'''java.lang.Exception, python.lang.Exception, javascript, php, ruby, go'''
         _lowerCamelCase		:							Optional[Any]            =					tokenizer(__lowerCAmelCase						).input_ids
         self.assertEqual(
             tokenizer.decode(__lowerCAmelCase		,   skip_special_tokens=__lowerCAmelCase		,   clean_up_tokenization_spaces=__lowerCAmelCase						)		,   __lowerCAmelCase		,   )






@require_torch
@require_sentencepiece
@require_tokenizers
class 			__snake_case			(      unittest.TestCase):
  snake_case__							:  Optional[Any]         =		"uclanlp/plbart-python-en_XX"
  snake_case__							:  Optional[int]         =		[
      "def maximum(a,b,c):NEW_LINE_INDENTreturn max([a,b,c])",
      "def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])",
  ]
  snake_case__							:  List[Any]         =		[
      "Returns the maximum value of a b c.",
      "Sums the values of a b c.",
  ]
  snake_case__							:  Union[str, Any]         =		[
      1_3_4,
      5_4_5_2,
      3_3_4_6_0,
      3_3_4_4_1,
      3_3_4_6_3,
      3_3_4_6_5,
      3_3_4_6_3,
      3_3_4_4_9,
      9_8_8,
      2_0,
      3_3_4_5_6,
      1_9,
      3_3_4_5_6,
      7_7_1,
      3_9,
      4_2_5_8,
      8_8_9,
      3_3_1_8,
      3_3_4_4_1,
      3_3_4_6_3,
      3_3_4_6_5,
      3_3_4_6_3,
      3_3_4_4_9,
      2_4_7_1,
      2,
      PYTHON_CODE,
  ]




  @classmethod
  def 		SCREAMING_SNAKE_CASE							(					cls	:		List[str]						):






         """simple docstring"""






         _lowerCamelCase		:							PLBartTokenizer            =					PLBartTokenizer.from_pretrained(
             cls.checkpoint_name		,   language_codes='''base'''		,   src_lang='''python'''		,   tgt_lang='''en_XX'''						)
         _lowerCamelCase		:							int            =					1
         return cls




  def 		SCREAMING_SNAKE_CASE							(					self	:		Any						):






         """simple docstring"""






         self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__java__''']		,   5_0_0_0_1						)
         self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__python__''']		,   5_0_0_0_2						)
         self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''__en_XX__''']		,   5_0_0_0_3						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Optional[Any]						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					self.tokenizer.batch_encode_plus(self.src_text						).input_ids[0]
         self.assertListEqual(self.expected_src_tokens		,   __lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         self.assertIn(__lowerCAmelCase		,   self.tokenizer.all_special_ids						)
         _lowerCamelCase		:							List[Any]            =					[EN_CODE, 9_0_3_7, 3_3_4_4_2, 5_7, 7_5_2, 1_5_3, 1_4, 5_6, 1_8, 9, 2]
         _lowerCamelCase		:							str            =					self.tokenizer.decode(__lowerCAmelCase		,   skip_special_tokens=__lowerCAmelCase						)
         _lowerCamelCase		:							Optional[Any]            =					self.tokenizer.decode(generated_ids[1:]		,   skip_special_tokens=__lowerCAmelCase						)
         self.assertEqual(__lowerCAmelCase		,   __lowerCAmelCase						)
         self.assertNotIn(self.tokenizer.eos_token		,   __lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         _lowerCamelCase		:							int            =					['''def sum(a,b,c):NEW_LINE_INDENTreturn sum([a,b,c])''' * 2_0]
         self.assertIsInstance(src_text[0]		,   __lowerCAmelCase						)
         _lowerCamelCase		:							List[str]            =					1_0
         _lowerCamelCase		:							List[Any]            =					self.tokenizer(__lowerCAmelCase		,   max_length=__lowerCAmelCase		,   truncation=__lowerCAmelCase						).input_ids[0]
         self.assertEqual(ids[-2]		,   2						)
         self.assertEqual(ids[-1]		,   __lowerCAmelCase						)
         self.assertEqual(len(__lowerCAmelCase						)		,   __lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['''<mask>''', '''__java__''']						)		,   [5_0_0_0_4, 5_0_0_0_1]						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Any						):






         """simple docstring"""






         _lowerCamelCase		:							List[str]            =					tempfile.mkdtemp()
         _lowerCamelCase		:							Optional[int]            =					self.tokenizer.fairseq_tokens_to_ids
         self.tokenizer.save_pretrained(__lowerCAmelCase						)
         _lowerCamelCase		:							Optional[int]            =					PLBartTokenizer.from_pretrained(__lowerCAmelCase						)
         self.assertDictEqual(new_tok.fairseq_tokens_to_ids		,   __lowerCAmelCase						)




  @require_torch
  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					self.tokenizer(self.src_text		,   text_target=self.tgt_text		,   padding=__lowerCAmelCase		,   return_tensors='''pt'''						)
         _lowerCamelCase		:							int            =					shift_tokens_right(batch['''labels''']		,   self.tokenizer.pad_token_id						)

         # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
         self.assertEqual(batch.input_ids[1][-2:].tolist()		,   [2, PYTHON_CODE]						)
         self.assertEqual(batch.decoder_input_ids[1][0]		,   __lowerCAmelCase						)
         self.assertEqual(batch.decoder_input_ids[1][-1]		,   2						)
         self.assertEqual(batch.labels[1][-2:].tolist()		,   [2, EN_CODE]						)




  @require_torch
  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					self.tokenizer(
             self.src_text		,   text_target=self.tgt_text		,   padding=__lowerCAmelCase		,   truncation=__lowerCAmelCase		,   max_length=len(self.expected_src_tokens						)		,   return_tensors='''pt'''		,   )
         _lowerCamelCase		:							Union[str, Any]            =					shift_tokens_right(batch['''labels''']		,   self.tokenizer.pad_token_id						)

         self.assertIsInstance(__lowerCAmelCase		,   __lowerCAmelCase						)

         self.assertEqual((2, 2_6)		,   batch.input_ids.shape						)
         self.assertEqual((2, 2_6)		,   batch.attention_mask.shape						)
         _lowerCamelCase		:							Tuple            =					batch.input_ids.tolist()[0]
         self.assertListEqual(self.expected_src_tokens		,   __lowerCAmelCase						)
         self.assertEqual(2		,   batch.decoder_input_ids[0, -1]						)  # EOS
         # Test that special tokens are reset
         self.assertEqual(self.tokenizer.prefix_tokens		,   []						)
         self.assertEqual(self.tokenizer.suffix_tokens		,   [self.tokenizer.eos_token_id, PYTHON_CODE]						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[Any]            =					self.tokenizer(self.src_text		,   padding=__lowerCAmelCase		,   truncation=__lowerCAmelCase		,   max_length=3		,   return_tensors='''pt'''						)
         _lowerCamelCase		:							str            =					self.tokenizer(
             text_target=self.tgt_text		,   padding=__lowerCAmelCase		,   truncation=__lowerCAmelCase		,   max_length=1_0		,   return_tensors='''pt'''						)
         _lowerCamelCase		:							Tuple            =					targets['''input_ids''']
         _lowerCamelCase		:							Union[str, Any]            =					shift_tokens_right(__lowerCAmelCase		,   self.tokenizer.pad_token_id						)

         self.assertEqual(batch.input_ids.shape[1]		,   3						)
         self.assertEqual(batch.decoder_input_ids.shape[1]		,   1_0						)




  @require_torch
  def 		SCREAMING_SNAKE_CASE							(					self	:		Dict						):






         """simple docstring"""






         _lowerCamelCase		:							List[Any]            =					self.tokenizer._build_translation_inputs(
             '''A test'''		,   return_tensors='''pt'''		,   src_lang='''en_XX'''		,   tgt_lang='''java'''						)

         self.assertEqual(
             nested_simplify(__lowerCAmelCase						)		,   {
                 # A, test, EOS, en_XX
                 '''input_ids''': [[1_5_0, 2_4_2, 2, 5_0_0_0_3]],
                 '''attention_mask''': [[1, 1, 1, 1]],
                 # java
                 '''forced_bos_token_id''': 5_0_0_0_1,
             }		,   )










'''simple docstring'''







import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import TransformeraDModel, VQDiffusionPipeline, VQDiffusionScheduler, VQModel
from diffusers.pipelines.vq_diffusion.pipeline_vq_diffusion import LearnedClassifierFreeSamplingEmbeddings
from diffusers.utils import load_numpy, slow, torch_device
from diffusers.utils.testing_utils import require_torch_gpu


__lowerCAmelCase        =							False




class   __SCREAMING_SNAKE_CASE       (unittest.TestCase       ):


  """simple docstring"""


  def    _a       (			self	):






         """simple docstring"""


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







  @property
  def    _a       (			self	):






         """simple docstring"""


         return 12







  @property
  def    _a       (			self	):






         """simple docstring"""


         return 12







  @property
  def    _a       (			self	):






         """simple docstring"""


         return 32







  @property
  def    _a       (			self	):






         """simple docstring"""


         torch.manual_seed(0	)
         a_						     =			VQModel(
             block_out_channels=[32, 64]   ,	in_channels=3   ,	out_channels=3   ,	down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']   ,	up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']   ,	latent_channels=3   ,	num_vq_embeddings=self.num_embed   ,	vq_embed_dim=3   ,	)
         return model







  @property
  def    _a       (			self	):






         """simple docstring"""


         a_						     =			CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'	)
         return tokenizer







  @property
  def    _a       (			self	):






         """simple docstring"""


         torch.manual_seed(0	)
         a_						     =			CLIPTextConfig(
             bos_token_id=0   ,	eos_token_id=2   ,	hidden_size=self.text_embedder_hidden_size   ,	intermediate_size=37   ,	layer_norm_eps=1e-05   ,	num_attention_heads=4   ,	num_hidden_layers=5   ,	pad_token_id=1   ,	vocab_size=1_000   ,	)
         return CLIPTextModel(UpperCamelCase__	)







  @property
  def    _a       (			self	):






         """simple docstring"""


         torch.manual_seed(0	)

         a_						     =			12
         a_						     =			12

         a_						     =			{
             'attention_bias': True,
             'cross_attention_dim': 32,
             'attention_head_dim': height * width,
             'num_attention_heads': 1,
             'num_vector_embeds': self.num_embed,
             'num_embeds_ada_norm': self.num_embeds_ada_norm,
             'norm_num_groups': 32,
             'sample_size': width,
             'activation_fn': 'geglu-approximate',
         }

         a_						     =			TransformeraDModel(**UpperCamelCase__	)
         return model







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			'cpu'

         a_						     =			self.dummy_vqvae
         a_						     =			self.dummy_text_encoder
         a_						     =			self.dummy_tokenizer
         a_						     =			self.dummy_transformer
         a_						     =			VQDiffusionScheduler(self.num_embed	)
         a_						     =			LearnedClassifierFreeSamplingEmbeddings(learnable=UpperCamelCase__	)

         a_						     =			VQDiffusionPipeline(
             vqvae=UpperCamelCase__   ,	text_encoder=UpperCamelCase__   ,	tokenizer=UpperCamelCase__   ,	transformer=UpperCamelCase__   ,	scheduler=UpperCamelCase__   ,	learned_classifier_free_sampling_embeddings=UpperCamelCase__   ,	)
         a_						     =			pipe.to(UpperCamelCase__	)
         pipe.set_progress_bar_config(disable=UpperCamelCase__	)

         a_						     =			'teddy bear playing in the pool'

         a_						     =			torch.Generator(device=UpperCamelCase__	).manual_seed(0	)
         a_						     =			pipe([prompt]   ,	generator=UpperCamelCase__   ,	num_inference_steps=2   ,	output_type='np'	)
         a_						     =			output.images

         a_						     =			torch.Generator(device=UpperCamelCase__	).manual_seed(0	)
         a_						     =			pipe(
             [prompt]   ,	generator=UpperCamelCase__   ,	output_type='np'   ,	return_dict=UpperCamelCase__   ,	num_inference_steps=2	)[0]

         a_						     =			image[0, -3:, -3:, -1]
         a_						     =			image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 24, 24, 3)

         a_						     =			np.array([0.6_551, 0.6_168, 0.5_008, 0.5_676, 0.5_659, 0.4_295, 0.6_073, 0.5_599, 0.4_992]	)

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







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			'cpu'

         a_						     =			self.dummy_vqvae
         a_						     =			self.dummy_text_encoder
         a_						     =			self.dummy_tokenizer
         a_						     =			self.dummy_transformer
         a_						     =			VQDiffusionScheduler(self.num_embed	)
         a_						     =			LearnedClassifierFreeSamplingEmbeddings(
             learnable=UpperCamelCase__   ,	hidden_size=self.text_embedder_hidden_size   ,	length=tokenizer.model_max_length	)

         a_						     =			VQDiffusionPipeline(
             vqvae=UpperCamelCase__   ,	text_encoder=UpperCamelCase__   ,	tokenizer=UpperCamelCase__   ,	transformer=UpperCamelCase__   ,	scheduler=UpperCamelCase__   ,	learned_classifier_free_sampling_embeddings=UpperCamelCase__   ,	)
         a_						     =			pipe.to(UpperCamelCase__	)
         pipe.set_progress_bar_config(disable=UpperCamelCase__	)

         a_						     =			'teddy bear playing in the pool'

         a_						     =			torch.Generator(device=UpperCamelCase__	).manual_seed(0	)
         a_						     =			pipe([prompt]   ,	generator=UpperCamelCase__   ,	num_inference_steps=2   ,	output_type='np'	)
         a_						     =			output.images

         a_						     =			torch.Generator(device=UpperCamelCase__	).manual_seed(0	)
         a_						     =			pipe(
             [prompt]   ,	generator=UpperCamelCase__   ,	output_type='np'   ,	return_dict=UpperCamelCase__   ,	num_inference_steps=2	)[0]

         a_						     =			image[0, -3:, -3:, -1]
         a_						     =			image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 24, 24, 3)

         a_						     =			np.array([0.6_693, 0.6_075, 0.4_959, 0.5_701, 0.5_583, 0.4_333, 0.6_171, 0.5_684, 0.4_988]	)

         assert np.abs(image_slice.flatten() - expected_slice	).max() < 2.0
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice	).max() < 1e-2





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


  """simple docstring"""


  def    _a       (			self	):






         """simple docstring"""


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







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			load_numpy(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
             '/vq_diffusion/teddy_bear_pool_classifier_free_sampling.npy'	)

         a_						     =			VQDiffusionPipeline.from_pretrained('microsoft/vq-diffusion-ithq'	)
         a_						     =			pipeline.to(UpperCamelCase__	)
         pipeline.set_progress_bar_config(disable=UpperCamelCase__	)

         # requires GPU generator for gumbel softmax
         # don't use GPU generator in tests though
         a_						     =			torch.Generator(device=UpperCamelCase__	).manual_seed(0	)
         a_						     =			pipeline(
             'teddy bear playing in the pool'   ,	num_images_per_prompt=1   ,	generator=UpperCamelCase__   ,	output_type='np'   ,	)

         a_						     =			output.images[0]

         assert image.shape == (256, 256, 3)
         assert np.abs(expected_image - image	).max() < 2.0




