from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_								=							logging.get_logger(__name__)

UpperCAmelCase_								=							{
    '''transfo-xl-wt103''': '''https://huggingface.co/transfo-xl-wt103/resolve/main/config.json''',
}





class      lowerCAmelCase						(					_a			):
     _SCREAMING_SNAKE_CASE     :     str		="""transfo-xl"""
     _SCREAMING_SNAKE_CASE     :     int		=["""mems"""]
     _SCREAMING_SNAKE_CASE     :     str		={
         """n_token""": """vocab_size""",
         """hidden_size""": """d_model""",
         """num_attention_heads""": """n_head""",
         """num_hidden_layers""": """n_layer""",
     }



     def __init__(					self				,      lowerCAmelCase__=267735				,      lowerCAmelCase__=[20000, 40000, 200000]				,      lowerCAmelCase__=1024				,      lowerCAmelCase__=1024				,      lowerCAmelCase__=16				,      lowerCAmelCase__=64				,      lowerCAmelCase__=4096				,      lowerCAmelCase__=4				,      lowerCAmelCase__=False				,      lowerCAmelCase__=18				,      lowerCAmelCase__=1600				,      lowerCAmelCase__=1000				,      lowerCAmelCase__=True				,      lowerCAmelCase__=True				,      lowerCAmelCase__=0				,      lowerCAmelCase__=-1				,      lowerCAmelCase__=True				,      lowerCAmelCase__=0.1				,      lowerCAmelCase__=0.0				,      lowerCAmelCase__=True				,      lowerCAmelCase__="normal"				,      lowerCAmelCase__=0.01				,      lowerCAmelCase__=0.01				,      lowerCAmelCase__=0.02				,      lowerCAmelCase__=1E-5				,      lowerCAmelCase__=0				,      **lowerCAmelCase__				,      ):
            _A=	vocab_size
            _A=	[]
            self.cutoffs.extend(lowerCAmelCase__       )
            if proj_share_all_but_first:
                   _A=	[False] + [True] * len(self.cutoffs       )
            else:
                   _A=	[False] + [False] * len(self.cutoffs       )
            _A=	d_model
            _A=	d_embed
            _A=	d_head
            _A=	d_inner
            _A=	div_val
            _A=	pre_lnorm
            _A=	n_layer
            _A=	n_head
            _A=	mem_len
            _A=	same_length
            _A=	attn_type
            _A=	clamp_len
            _A=	sample_softmax
            _A=	adaptive
            _A=	dropout
            _A=	dropatt
            _A=	untie_r
            _A=	init
            _A=	init_range
            _A=	proj_init_std
            _A=	init_std
            _A=	layer_norm_epsilon
            super().__init__(eos_token_id=lowerCAmelCase__				,      **lowerCAmelCase__       )



     @property
     def 			a__  (					self       ):
            # Message copied from Transformer-XL documentation
            logger.info(f"The model {self.model_type} is one of the few models that has no sequence length limit."       )
            return -1





     @max_position_embeddings.setter
     def 			a__  (					self				,      lowerCAmelCase__       ):
            # Message copied from Transformer-XL documentation
            raise NotImplementedError(
                f"The model {self.model_type} is one of the few models that has no sequence length limit."       )
import os
import tempfile
import unittest
import uuid
from pathlib import Path

from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
from transformers.tools.agent_types import AgentAudio, AgentImage, AgentText
from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available


if is_torch_available():
      import torch

if is_soundfile_availble():
      import soundfile as sf

if is_vision_available():
      from PIL import Image

def 							UpperCamelCase				(    lowerCAmelCase_=""   )		->						str:




       '''simple docstring'''






       _A=	tempfile.mkdtemp()
       return os.path.join(lowerCAmelCase_       ,					str(uuid.uuida()   ) + suffix   )





@require_soundfile
@require_torch
class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	torch.rand(12				,      dtype=torch.floataa       ) - 0.5
            _A=	AgentAudio(lowerCAmelCase__       )
            _A=	str(agent_type.to_string()       )

            # Ensure that the tensor and the agent_type's tensor are the same
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type.to_raw()				,      atol=1E-4       )       )

            del agent_type

            # Ensure the path remains even after the object deletion
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )

            # Ensure that the file contains the same value as the original tensor
            _A,			_A=	sf.read(lowerCAmelCase__       )
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      torch.tensor(lowerCAmelCase__       )				,      atol=1E-4       )       )





     def 			a__  (					self       ):
            _A=	torch.rand(12				,      dtype=torch.floataa       ) - 0.5
            _A=	get_new_path(suffix='.wav'       )
            sf.write(lowerCAmelCase__				,      lowerCAmelCase__				,      16000       )

            _A=	AgentAudio(lowerCAmelCase__       )

            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type.to_raw()				,      atol=1E-4       )       )
            self.assertEqual(agent_type.to_string()				,      lowerCAmelCase__       )





@require_vision
@require_torch
class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	torch.randint(0				,      256				,      (64, 64, 3)       )
            _A=	AgentImage(lowerCAmelCase__       )
            _A=	str(agent_type.to_string()       )

            # Ensure that the tensor and the agent_type's tensor are the same
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type._tensor				,      atol=1E-4       )       )

            self.assertIsInstance(agent_type.to_raw()				,      Image.Image       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )



     def 			a__  (					self       ):
            _A=	Path(get_tests_dir('fixtures/tests_samples/COCO'       )       ) / '000000039769.png'
            _A=	Image.open(lowerCAmelCase__       )
            _A=	AgentImage(lowerCAmelCase__       )

            self.assertTrue(path.samefile(agent_type.to_string()       )       )
            self.assertTrue(image == agent_type.to_raw()       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )





     def 			a__  (					self       ):
            _A=	Path(get_tests_dir('fixtures/tests_samples/COCO'       )       ) / '000000039769.png'
            _A=	Image.open(lowerCAmelCase__       )
            _A=	AgentImage(lowerCAmelCase__       )

            self.assertFalse(path.samefile(agent_type.to_string()       )       )
            self.assertTrue(image == agent_type.to_raw()       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )





class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	'Hey!'
            _A=	AgentText(lowerCAmelCase__       )

            self.assertEqual(lowerCAmelCase__				,      agent_type.to_string()       )
            self.assertEqual(lowerCAmelCase__				,      agent_type.to_raw()       )
            self.assertEqual(lowerCAmelCase__				,      lowerCAmelCase__       )