





import gc
import unittest

import numpy as np
import torch

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					,							unittest.TestCase					):







 '''simple docstring'''
 lowercase_	=    DanceDiffusionPipeline
 lowercase_	=    UNCONDITIONAL_AUDIO_GENERATION_PARAMS
 lowercase_	=    PipelineTesterMixin.required_optional_params - {
     "callback",
     "latents",
     "callback_steps",
     "output_type",
     "num_images_per_prompt",
 }
 lowercase_	=    UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
 lowercase_	=    False
 lowercase_	=    False

 def 							SCREAMING_SNAKE_CASE_      (self       :     List[Any]) ->List[Any]:



   '''simple docstring'''



   torch.manual_seed(0)
   lowerCamelCase__:   str    						=UNetaDModel(
       block_out_channels=(32, 32, 64) ,				extra_in_channels=16 ,				sample_size=512 ,				sample_rate=16_000 ,				in_channels=2 ,				out_channels=2 ,				flip_sin_to_cos=__UpperCamelCase ,				use_timestep_embedding=__UpperCamelCase ,				time_embedding_type="fourier" ,				mid_block_type="UNetMidBlock1D" ,				down_block_types=("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D") ,				up_block_types=("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip") ,				)
   lowerCamelCase__:   Any    						=IPNDMScheduler()

   lowerCamelCase__:   List[str]    						={
       "unet": unet,
       "scheduler": scheduler,
   }
   return components

 def 							SCREAMING_SNAKE_CASE_      (self       :     int ,				UpperCAmelCase_       :     Union[str, Any] ,				UpperCAmelCase_       :     Any=0) ->Optional[int]:



   '''simple docstring'''



   if str(__UpperCamelCase).startswith("mps"):
     lowerCamelCase__:   Dict    						=torch.manual_seed(__UpperCamelCase)
   else:
     lowerCamelCase__:   Optional[int]    						=torch.Generator(device=__UpperCamelCase).manual_seed(__UpperCamelCase)
   lowerCamelCase__:   int    						={
       "batch_size": 1,
       "generator": generator,
       "num_inference_steps": 4,
   }
   return inputs

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



   '''simple docstring'''



   lowerCamelCase__:   Tuple    						="cpu"  # ensure determinism for the device-dependent torch.Generator
   lowerCamelCase__:   List[Any]    						=self.get_dummy_components()
   lowerCamelCase__:   Optional[int]    						=DanceDiffusionPipeline(**__UpperCamelCase)
   lowerCamelCase__:   Optional[Any]    						=pipe.to(__UpperCamelCase)
   pipe.set_progress_bar_config(disable=__UpperCamelCase)

   lowerCamelCase__:   Optional[Any]    						=self.get_dummy_inputs(__UpperCamelCase)
   lowerCamelCase__:   List[Any]    						=pipe(**__UpperCamelCase)
   lowerCamelCase__:   Optional[Any]    						=output.audios

   lowerCamelCase__:   Tuple    						=audio[0, -3:, -3:]

   assert audio.shape == (1, 2, components["unet"].sample_size)
   lowerCamelCase__:   Dict    						=np.array([-0.7265, 1.0000, -0.8388, 0.1175, 0.9498, -1.0000])
   assert np.abs(audio_slice.flatten() - expected_slice).max() < 1E-2

 @skip_mps
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[int]) ->Tuple:



   '''simple docstring'''



   return super().test_save_load_local()

 @skip_mps
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[int]) ->int:



   '''simple docstring'''



   return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3)

 @skip_mps
 def 							SCREAMING_SNAKE_CASE_      (self       :     Tuple) ->Optional[Any]:



   '''simple docstring'''



   return super().test_save_load_optional_components()

 @skip_mps
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[Any]) ->Dict:



   '''simple docstring'''



   return super().test_attention_slicing_forward_pass()







 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->int:



   '''simple docstring'''



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



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







 '''simple docstring'''

 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->Dict:



   '''simple docstring'''



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

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



   '''simple docstring'''



   lowerCamelCase__:   str    						=torch_device

   lowerCamelCase__:   Tuple    						=DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k")
   lowerCamelCase__:   Union[str, Any]    						=pipe.to(__UpperCamelCase)
   pipe.set_progress_bar_config(disable=__UpperCamelCase)

   lowerCamelCase__:   List[Any]    						=torch.manual_seed(0)
   lowerCamelCase__:   Tuple    						=pipe(generator=__UpperCamelCase ,				num_inference_steps=100 ,				audio_length_in_s=4.096)
   lowerCamelCase__:   int    						=output.audios

   lowerCamelCase__:   List[Any]    						=audio[0, -3:, -3:]

   assert audio.shape == (1, 2, pipe.unet.sample_size)
   lowerCamelCase__:   List[Any]    						=np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020])

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







 def 							SCREAMING_SNAKE_CASE_      (self       :     str) ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:   Optional[Any]    						=torch_device

   lowerCamelCase__:   Optional[Any]    						=DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k" ,				torch_dtype=torch.floataa)
   lowerCamelCase__:   Dict    						=pipe.to(__UpperCamelCase)
   pipe.set_progress_bar_config(disable=__UpperCamelCase)

   lowerCamelCase__:   str    						=torch.manual_seed(0)
   lowerCamelCase__:   List[Any]    						=pipe(generator=__UpperCamelCase ,				num_inference_steps=100 ,				audio_length_in_s=4.096)
   lowerCamelCase__:   List[str]    						=output.audios

   lowerCamelCase__:   str    						=audio[0, -3:, -3:]

   assert audio.shape == (1, 2, pipe.unet.sample_size)
   lowerCamelCase__:   int    						=np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341])

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













import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_squeezebert import SqueezeBertTokenizer


__A             =       logging.get_logger(__name__)

__A             =       {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__A             =       {
    "vocab_file": {
        "squeezebert/squeezebert-uncased": (
            "https://huggingface.co/squeezebert/squeezebert-uncased/resolve/main/vocab.txt"
        ),
        "squeezebert/squeezebert-mnli": "https://huggingface.co/squeezebert/squeezebert-mnli/resolve/main/vocab.txt",
        "squeezebert/squeezebert-mnli-headless": (
            "https://huggingface.co/squeezebert/squeezebert-mnli-headless/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "squeezebert/squeezebert-uncased": (
            "https://huggingface.co/squeezebert/squeezebert-uncased/resolve/main/tokenizer.json"
        ),
        "squeezebert/squeezebert-mnli": (
            "https://huggingface.co/squeezebert/squeezebert-mnli/resolve/main/tokenizer.json"
        ),
        "squeezebert/squeezebert-mnli-headless": (
            "https://huggingface.co/squeezebert/squeezebert-mnli-headless/resolve/main/tokenizer.json"
        ),
    },
}

__A             =       {
    "squeezebert/squeezebert-uncased": 512,
    "squeezebert/squeezebert-mnli": 512,
    "squeezebert/squeezebert-mnli-headless": 512,
}


__A             =       {
    "squeezebert/squeezebert-uncased": {"do_lower_case": True},
    "squeezebert/squeezebert-mnli": {"do_lower_case": True},
    "squeezebert/squeezebert-mnli-headless": {"do_lower_case": True},
}



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    VOCAB_FILES_NAMES
 lowercase_	=    PRETRAINED_VOCAB_FILES_MAP
 lowercase_	=    PRETRAINED_INIT_CONFIGURATION
 lowercase_	=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowercase_	=    SqueezeBertTokenizer

 def __init__(self       :     Any ,				UpperCAmelCase_       :     int=None ,				UpperCAmelCase_       :     List[str]=None ,				UpperCAmelCase_       :     int=True ,				UpperCAmelCase_       :     Optional[int]="[UNK]" ,				UpperCAmelCase_       :     int="[SEP]" ,				UpperCAmelCase_       :     Optional[Any]="[PAD]" ,				UpperCAmelCase_       :     Optional[int]="[CLS]" ,				UpperCAmelCase_       :     str="[MASK]" ,				UpperCAmelCase_       :     Union[str, Any]=True ,				UpperCAmelCase_       :     Optional[Any]=None ,				**UpperCAmelCase_       :     Dict ,				) ->Union[str, Any]:



   '''simple docstring'''



   super().__init__(
       UpperCAmelCase_ ,				tokenizer_file=UpperCAmelCase_ ,				do_lower_case=UpperCAmelCase_ ,				unk_token=UpperCAmelCase_ ,				sep_token=UpperCAmelCase_ ,				pad_token=UpperCAmelCase_ ,				cls_token=UpperCAmelCase_ ,				mask_token=UpperCAmelCase_ ,				tokenize_chinese_chars=UpperCAmelCase_ ,				strip_accents=UpperCAmelCase_ ,				**UpperCAmelCase_ ,				)

   lowerCamelCase__:   Dict    						=json.loads(self.backend_tokenizer.normalizer.__getstate__())
   if (
       normalizer_state.get("lowercase" ,				UpperCAmelCase_) != do_lower_case
       or normalizer_state.get("strip_accents" ,				UpperCAmelCase_) != strip_accents
       or normalizer_state.get("handle_chinese_chars" ,				UpperCAmelCase_) != tokenize_chinese_chars
   ):
     lowerCamelCase__:   Any    						=getattr(UpperCAmelCase_ ,				normalizer_state.pop("type"))
     lowerCamelCase__:   Union[str, Any]    						=do_lower_case
     lowerCamelCase__:   Optional[Any]    						=strip_accents
     lowerCamelCase__:   Optional[int]    						=tokenize_chinese_chars
     lowerCamelCase__:   int    						=normalizer_class(**UpperCAmelCase_)

   lowerCamelCase__:   Any    						=do_lower_case

 def 							SCREAMING_SNAKE_CASE_      (self       :     str ,				UpperCAmelCase_       :     List[str] ,				UpperCAmelCase_       :     str=None) ->Dict:



   '''simple docstring'''



   lowerCamelCase__:   List[str]    						=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

   if token_ids_a:
     output += token_ids_a + [self.sep_token_id]

   return output

 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[int] ,				UpperCAmelCase_       :     List[int] ,				UpperCAmelCase_       :     Optional[List[int]] = None) ->List[int]:



   '''simple docstring'''



   lowerCamelCase__:   Dict    						=[self.sep_token_id]
   lowerCamelCase__:   Tuple    						=[self.cls_token_id]
   if token_ids_a is None:
     return len(cls + token_ids_a + sep) * [0]
   return len(cls + token_ids_a + sep) * [0] + len(token_ids_a + sep) * [1]







 def 							SCREAMING_SNAKE_CASE_      (self       :     Union[str, Any] ,				UpperCAmelCase_       :     str ,				UpperCAmelCase_       :     Optional[str] = None) ->Tuple[str]:



   '''simple docstring'''



   lowerCamelCase__:   Optional[int]    						=self._tokenizer.model.save(UpperCAmelCase_ ,				name=UpperCAmelCase_)
   return tuple(UpperCAmelCase_)

