





"""simple docstring"""



import collections
import json
import os
import re
from typing import TYPE_CHECKING, List, Optional, Tuple

import numpy as np

from ...tokenization_utils_fast import PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
       from transformers.pipelines.conversational import Conversation


a_					=     logging.get_logger(__name__)

a_					=     {"""vocab_file""": """vocab.txt""", """emoji_file""": """emoji.json"""}

a_					=     {
    """vocab_file""": {
        """abeja/gpt-neox-japanese-2.7b""": """https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/vocab.txt""",
    },
    """emoji_file""": {
        """abeja/gpt-neox-japanese-2.7b""": """https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/emoji.json""",
    },
}

a_					=     {
    """abeja/gpt-neox-japanese-2.7b""": 2048,
}







def 						__lowercase	(  snake_case_    :    int							,snake_case_    :    int		)  ->Dict:



    '''simple docstring'''







    with open(snake_case_							,'''r'''							,encoding='''utf-8'''		) as f:
        __A       :		List[Any]							=	json.loads(f.read()		)

    __A       :		Optional[int]							=	collections.OrderedDict()
    __A       :		Dict							=	collections.OrderedDict()
    __A       :		List[Any]							=	collections.OrderedDict()
    with open(snake_case_							,'''r'''							,encoding='''utf-8'''		) as f:
        __A       :		Optional[Any]							=	f.readlines()
    __A       :		List[str]							=	[[t.rstrip('''\n'''		)] if (t == ''',''' or ''',''' not in t) else t.rstrip('''\n'''		).split(''','''		) for t in token]
    for idx, b in enumerate(snake_case_		):
        __A       :		List[str]							=	b
        __A       :		List[Any]							=	idx
        for wd in b:
            __A       :		Optional[int]							=	idx

    return vocab, raw_vocab, ids_to_tokens, emoji






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	VOCAB_FILES_NAMES
 _lowerCamelCase								=	PRETRAINED_VOCAB_FILES_MAP
 _lowerCamelCase								=	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 _lowerCamelCase								=	["""input_ids""", """attention_mask"""]

 def __init__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase="<|endoftext|>"   ,		__lowerCamelCase="<|endoftext|>"   ,		__lowerCamelCase="<|startoftext|>"   ,		__lowerCamelCase="<|endoftext|>"   ,		__lowerCamelCase=False   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(
         unk_token=__lowerCamelCase   ,		pad_token=__lowerCamelCase   ,		bos_token=__lowerCamelCase   ,		eos_token=__lowerCamelCase   ,		do_clean_text=__lowerCamelCase   ,		**__lowerCamelCase   ,		)
     if not os.path.isfile(__lowerCamelCase    ):
         raise ValueError(
             F"""Can't find a vocabulary file at path '{vocab_file}'. To load the vocabulary from a Google pretrained"""
             ''' model use `tokenizer = GPTNeoXJapaneseokenizer.from_pretrained(PRETRAINED_MODEL_NAME)`'''    )
     if not os.path.isfile(__lowerCamelCase    ):
         raise ValueError(
             F"""Can't find a emoji file at path '{emoji_file}'. To load the emoji information from a Google"""
             ''' pretrained model use `tokenizer = GPTNeoXJapaneseokenizer.from_pretrained(PRETRAINED_MODEL_NAME)`'''    )
     __A       :		Optional[Any]							=	do_clean_text
     __A					,			__A					,			__A					,			__A       :		Dict							=	load_vocab_and_emoji(__lowerCamelCase   ,		__lowerCamelCase    )
     __A       :		Optional[int]							=	SubWordJapaneseTokenizer(
         vocab=self.vocab   ,		ids_to_tokens=self.ids_to_tokens   ,		emoji=self.emoji    )

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return len(self.raw_vocab    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return dict(self.raw_vocab   ,		**self.added_tokens_encoder    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     return self.subword_tokenizer.tokenize(__lowerCamelCase   ,		clean=self.do_clean_text    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     return self.vocab.get(__lowerCamelCase   ,		self.vocab.get(self.unk_token    )    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     return self.subword_tokenizer.convert_id_to_token(__lowerCamelCase    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Optional[Any]							=	''''''.join(__lowerCamelCase    ).strip()
     return out_string

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Union[str, Any]							=	[]
     for is_user, text in conversation.iter_texts():
         input_ids.extend(self.encode(__lowerCamelCase   ,		add_special_tokens=__lowerCamelCase    ) + [self.eos_token_id]    )

     if len(__lowerCamelCase    ) > self.model_max_length:
         __A       :		Any							=	input_ids[-self.model_max_length :]
     return input_ids







 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = None    ):



     '''simple docstring'''




     __A       :		Any							=	0
     if os.path.isdir(__lowerCamelCase    ):
         __A       :		List[str]							=	os.path.join(
             __lowerCamelCase   ,		(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']    )
         __A       :		Optional[int]							=	os.path.join(
             __lowerCamelCase   ,		(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''emoji_file''']    )
     else:
         __A       :		Optional[int]							=	(
             (filename_prefix + '''-''' if filename_prefix else '''''') + save_directory + VOCAB_FILES_NAMES['''vocab_file''']
         )
         __A       :		List[str]							=	(
             (filename_prefix + '''-''' if filename_prefix else '''''') + save_directory + VOCAB_FILES_NAMES['''emoji_file''']
         )
     with open(__lowerCamelCase   ,		'''w'''   ,		encoding='''utf-8'''    ) as writer:
         for token_index, token in self.ids_to_tokens.items():
             if index != token_index:
                 logger.warning(
                     F"""Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."""
                     ''' Please check that the vocabulary is not corrupted!'''    )
                 __A       :		List[Any]							=	token_index
             writer.write(''','''.join(__lowerCamelCase    ) + '''\n'''    )
             index += 1
     with open(__lowerCamelCase   ,		'''w'''   ,		encoding='''utf-8'''    ) as writer:
         json.dump(self.emoji   ,		__lowerCamelCase    )
     return vocab_file, emoji_file






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 def __init__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Optional[int]							=	vocab  # same as swe
     __A       :		Tuple							=	ids_to_tokens  # same as bpe
     __A       :		Union[str, Any]							=	emoji
     __A       :		List[Any]							=	np.max([len(__lowerCamelCase    ) for w in self.vocab.keys()]    )
     __A       :		Tuple							=	re.compile(r'''(https?|ftp)(:\/\/[-_\.!~*\'()a-zA-Z0-9;\/?:\@&=\+$,%#]+)'''    )
     __A       :		Optional[int]							=	re.compile(r'''[A-Za-z0-9\._+]*@[\-_0-9A-Za-z]+(\.[A-Za-z]+)*'''    )
     __A       :		Tuple							=	re.compile(r'''[\(]{0,1}[0-9]{2,4}[\)\-\(]{0,1}[0-9]{2,4}[\)\-]{0,1}[0-9]{3,4}'''    )
     __A       :		Dict							=	re.compile(
         r'''([12]\d{3}[/\-年])*(0?[1-9]|1[0-2])[/\-月]((0?[1-9]|[12][0-9]|3[01])日?)*(\d{1,2}|:|\d{1,2}時|\d{1,2}分|\(日\)|\(月\)|\(火\)|\(水\)|\(木\)|\(金\)|\(土\)|㈰|㈪|㈫|㈬|㈭|㈮|㈯)*'''    )
     __A       :		Optional[Any]							=	re.compile(
         r'''(明治|大正|昭和|平成|令和|㍾|㍽|㍼|㍻|\u32ff)\d{1,2}年(0?[1-9]|1[0-2])月(0?[1-9]|[12][0-9]|3[01])日(\d{1,2}|:|\d{1,2}時|\d{1,2}分|\(日\)|\(月\)|\(火\)|\(水\)|\(木\)|\(金\)|\(土\)|㈰|㈪|㈫|㈬|㈭|㈮|㈯)*'''    )
     __A       :		Dict							=	re.compile(
         r'''((0|[1-9]\d*|[1-9]\d{0,2}(,\d{3})+)*億)*((0|[1-9]\d*|[1-9]\d{0,2}(,\d{3})+)*万)*((0|[1-9]\d*|[1-9]\d{0,2}(,\d{3})+)*千)*(0|[1-9]\d*|[1-9]\d{0,2}(,\d{3})+)*(千円|万円|千万円|円|千ドル|万ドル|千万ドル|ドル|千ユーロ|万ユーロ|千万ユーロ|ユーロ)+(\(税込\)|\(税抜\)|\+tax)*'''    )
     __A       :		List[str]							=	'''─━│┃┄┅┆┇┈┉┊┋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛├┝┞┟┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯┰┱┲┳┴┵┶┷┸┹┺┻┼┽┾┿╀╁╂╃╄╅╆╇╈╉╊╋╌╍╎╏═║╒╓╔╕╖╗╘╙╚╛╜╝╞╟╠╡╢╣╤╥╦╧╨╩╪╫╬╭╮╯╰╱╲╳╴╵╶╷╸╹╺╻╼╽╾╿'''
     __A       :		Optional[int]							=	'''▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟'''
     __A       :		List[Any]							=	str.maketrans({k: '''<BLOCK>''' for k in keisen + blocks}    )

 def __len__(       self    ):



     '''simple docstring'''




     return len(self.ids_to_tokens    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		int							=	self.content_repattera.sub('''<URL>'''   ,		__lowerCamelCase    )
     __A       :		int							=	self.content_repattera.sub('''<EMAIL>'''   ,		__lowerCamelCase    )
     __A       :		List[str]							=	self.content_repattera.sub('''<TEL>'''   ,		__lowerCamelCase    )
     __A       :		Dict							=	self.content_repattera.sub('''<DATE>'''   ,		__lowerCamelCase    )
     __A       :		int							=	self.content_repattera.sub('''<DATE>'''   ,		__lowerCamelCase    )
     __A       :		Union[str, Any]							=	self.content_repattera.sub('''<PRICE>'''   ,		__lowerCamelCase    )
     __A       :		List[str]							=	content.translate(self.content_transa    )
     while "<BLOCK><BLOCK>" in content:
         __A       :		Tuple							=	content.replace('''<BLOCK><BLOCK>'''   ,		'''<BLOCK>'''    )
     return content

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase=False    ):



     '''simple docstring'''




     __A       :		Tuple							=	text.replace(''' '''   ,		'''<SP>'''    )
     __A       :		Optional[Any]							=	text.replace('''　'''   ,		'''<SP>'''    )
     __A       :		Union[str, Any]							=	text.replace('''\r\n'''   ,		'''<BR>'''    )
     __A       :		int							=	text.replace('''\n'''   ,		'''<BR>'''    )
     __A       :		Optional[Any]							=	text.replace('''\r'''   ,		'''<BR>'''    )
     __A       :		Dict							=	text.replace('''\t'''   ,		'''<TAB>'''    )
     __A       :		List[str]							=	text.replace('''—'''   ,		'''ー'''    )
     __A       :		Dict							=	text.replace('''−'''   ,		'''ー'''    )
     for k, v in self.emoji["emoji"].items():
         if k in text:
             __A       :		str							=	text.replace(__lowerCamelCase   ,		__lowerCamelCase    )
     if clean:
         __A       :		Any							=	self.clean_text(__lowerCamelCase    )

     def check_simbol(__lowerCamelCase    ):
         __A       :		Union[str, Any]							=	x.encode()
         if len(__lowerCamelCase    ) == 1 and len(__lowerCamelCase    ) == 2:
             __A       :		Tuple							=	(int(e[0]    ) << 8) + int(e[1]    )
             if (
                 (c >= 0XC_2_A_1 and c <= 0XC_2_B_F)
                 or (c >= 0XC_7_8_0 and c <= 0XC_7_8_3)
                 or (c >= 0XC_A_B_9 and c <= 0XC_B_B_F)
                 or (c >= 0XC_C_8_0 and c <= 0XC_D_A_2)
             ):
                 return True
         return False

     def checkuae(__lowerCamelCase    ):
         __A       :		List[Any]							=	x.encode()
         if len(__lowerCamelCase    ) == 1 and len(__lowerCamelCase    ) == 3:
             __A       :		Dict							=	(int(e[0]    ) << 16) + (int(e[1]    ) << 8) + int(e[2]    )
             if c >= 0XE_2_8_0_8_0 and c <= 0XE_2_B_0_7_F:
                 return True
         return False

     __A       :		str							=	0
     __A       :		Any							=	[]
     while pos < len(__lowerCamelCase    ):
         __A       :		List[str]							=	min(len(__lowerCamelCase    )   ,		pos + self.maxlen + 1    ) if text[pos] == '''<''' else pos + 3
         __A       :		int							=	[]  # (token_id, token, pos)
         for e in range(__lowerCamelCase   ,		__lowerCamelCase   ,		-1    ):
             __A       :		Tuple							=	text[pos:e]
             if wd in self.vocab:
                 if wd[0] == "<" and len(__lowerCamelCase    ) > 2:
                     __A       :		Dict							=	[(self.vocab[wd], wd, e)]
                     break
                 else:
                     candidates.append((self.vocab[wd], wd, e)    )
         if len(__lowerCamelCase    ) > 0:
             # the smallest token_id is adopted
             __A					,			__A					,			__A       :		Optional[int]							=	sorted(__lowerCamelCase   ,		key=lambda __lowerCamelCase    : x[0]    )[0]
             result.append(__lowerCamelCase    )
             __A       :		Optional[Any]							=	e
         else:
             __A       :		Optional[int]							=	pos + 1
             __A       :		Any							=	text[pos:end]
             if check_simbol(__lowerCamelCase    ):
                 result.append('''<KIGOU>'''    )
             elif checkuae(__lowerCamelCase    ):
                 result.append('''<U2000U2BFF>'''    )
             else:
                 for i in wd.encode('''utf-8'''    ):
                     result.append('''<|byte%d|>''' % i    )
             __A       :		Dict							=	end
     return result







 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase="\n"    ):



     '''simple docstring'''




     __A       :		List[Any]							=	[]
     __A       :		Optional[Any]							=	[]
     __A       :		Dict							=	self.ids_to_tokens[index][0]
     if word[:6] == "<|byte" and word[-2:] == "|>":
         byte_tokens.append(int(word[6:-2]    )    )
     else:
         if len(__lowerCamelCase    ) > 0:
             words.append(bytearray(__lowerCamelCase    ).decode('''utf-8'''   ,		errors='''replace'''    )    )
             __A       :		int							=	[]
         if word[:7] == "<|emoji" and word[-2:] == "|>":
             words.append(self.emoji['''emoji_inv'''][word]    )
         elif word == "<SP>":
             words.append(''' '''    )
         elif word == "<BR>":
             words.append(__lowerCamelCase    )
         elif word == "<TAB>":
             words.append('''\t'''    )
         elif word == "<BLOCK>":
             words.append('''▀'''    )
         elif word == "<KIGOU>":
             words.append('''ǀ'''    )
         elif word == "<U2000U2BFF>":
             words.append('''‖'''    )
         else:
             words.append(__lowerCamelCase    )
     if len(__lowerCamelCase    ) > 0:
         words.append(bytearray(__lowerCamelCase    ).decode('''utf-8'''   ,		errors='''replace'''    )    )
     __A       :		Dict							=	''''''.join(__lowerCamelCase    )
     return text











"""simple docstring"""



import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






class 						__snake_case   (						unittest.TestCase	):





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		List[Any]							=	UNetaDModel(
         sample_size=(32, 64)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')   ,		)
     return model

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		str							=	UNetaDConditionModel(
         sample_size=(64, 32)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''CrossAttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''CrossAttnUpBlock2D''')   ,		cross_attention_dim=10   ,		)
     return model

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     torch.manual_seed(0    )
     __A       :		int							=	AutoencoderKL(
         sample_size=(128, 64)   ,		in_channels=1   ,		out_channels=1   ,		latent_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''DownEncoderBlock2D''', '''DownEncoderBlock2D''')   ,		up_block_types=('''UpDecoderBlock2D''', '''UpDecoderBlock2D''')   ,		)
     __A       :		int							=	UNetaDModel(
         sample_size=(64, 32)   ,		in_channels=1   ,		out_channels=1   ,		layers_per_block=2   ,		block_out_channels=(128, 128)   ,		down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')   ,		up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')   ,		)
     return vqvae, unet







 @slow
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
     __A       :		Union[str, Any]							=	Mel(
         x_res=self.dummy_unet.config.sample_size[1]   ,		y_res=self.dummy_unet.config.sample_size[0]   ,		)

     __A       :		List[Any]							=	DDPMScheduler()
     __A       :		Optional[Any]							=	AudioDiffusionPipeline(vqvae=__lowerCamelCase   ,		unet=self.dummy_unet   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Tuple							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		Tuple							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		List[str]							=	pipe(generator=__lowerCamelCase   ,		steps=4    )
     __A       :		Union[str, Any]							=	output.audios[0]
     __A       :		str							=	output.images[0]

     __A       :		List[Any]							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		Any							=	pipe(generator=__lowerCamelCase   ,		steps=4   ,		return_dict=__lowerCamelCase    )
     __A       :		int							=	output[0][0]

     assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
     assert (
         image.height == self.dummy_unet.config.sample_size[0]
         and image.width == self.dummy_unet.config.sample_size[1]
     )
     __A       :		Tuple							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		str							=	np.frombuffer(image_from_tuple.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Any							=	np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0
     assert np.abs(image_from_tuple_slice.flatten() - expected_slice    ).max() == 0

     __A       :		int							=	Mel(
         x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]   ,		y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]   ,		)

     __A       :		Any							=	DDIMScheduler()
     __A       :		Optional[Any]							=	self.dummy_vqvae_and_unet
     __A       :		int							=	AudioDiffusionPipeline(
         vqvae=self.dummy_vqvae_and_unet[0]   ,		unet=dummy_vqvae_and_unet[1]   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Any							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     np.random.seed(0    )
     __A       :		str							=	np.random.uniform(-1   ,		1   ,		((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,)    )
     __A       :		Union[str, Any]							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		int							=	pipe(raw_audio=__lowerCamelCase   ,		generator=__lowerCamelCase   ,		start_step=5   ,		steps=10    )
     __A       :		Any							=	output.images[0]

     assert (
         image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
         and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
     )
     __A       :		str							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Optional[Any]							=	np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0

     __A       :		Union[str, Any]							=	self.dummy_unet_condition
     __A       :		List[str]							=	AudioDiffusionPipeline(
         vqvae=self.dummy_vqvae_and_unet[0]   ,		unet=__lowerCamelCase   ,		mel=__lowerCamelCase   ,		scheduler=__lowerCamelCase    )
     __A       :		Dict							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     np.random.seed(0    )
     __A       :		int							=	torch.rand((1, 1, 10)    )
     __A       :		Optional[Any]							=	pipe(generator=__lowerCamelCase   ,		encoding=__lowerCamelCase    )
     __A       :		str							=	output.images[0]
     __A       :		Optional[Any]							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Tuple							=	np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0






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





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		int							=	torch_device

     __A       :		List[Any]							=	DiffusionPipeline.from_pretrained('''teticio/audio-diffusion-ddim-256'''    )
     __A       :		List[Any]							=	pipe.to(__lowerCamelCase    )
     pipe.set_progress_bar_config(disable=__lowerCamelCase    )

     __A       :		Dict							=	torch.Generator(device=__lowerCamelCase    ).manual_seed(42    )
     __A       :		str							=	pipe(generator=__lowerCamelCase    )
     __A       :		Dict							=	output.audios[0]
     __A       :		List[Any]							=	output.images[0]

     assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
     assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
     __A       :		Optional[int]							=	np.frombuffer(image.tobytes()   ,		dtype='''uint8'''    )[:10]
     __A       :		Optional[Any]							=	np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]    )

     assert np.abs(image_slice.flatten() - expected_slice    ).max() == 0




