

"""simple docstring"""

import unittest

from transformers import SpeechaTextaConfig
from transformers.testing_utils import is_torch_available, require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers.models.speech_to_text_a.modeling_speech_to_text_a import (
							    SpeechaTextaDecoder,
							    SpeechaTextaForCausalLM,
							)


@require_torch
class 			_snake_case     :







						def __init__(self     ,							UpperCAmelCase_     ,							UpperCAmelCase_=9_9     ,							UpperCAmelCase_=1_3     ,							UpperCAmelCase_=1_6     ,							UpperCAmelCase_=7     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=False     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=2     ,							UpperCAmelCase_=3_2     ,							UpperCAmelCase_=4     ,							UpperCAmelCase_=4     ,							UpperCAmelCase_=3_0     ,							UpperCAmelCase_=0     ,							UpperCAmelCase_=1     ,							UpperCAmelCase_=2     ,							UpperCAmelCase_=None     ,							)			->						Any:
											__lowercase												=			parent
											__lowercase												=			batch_size
											__lowercase												=			decoder_seq_length
											# For common tests
											__lowercase												=			self.decoder_seq_length
											__lowercase												=			is_training
											__lowercase												=			use_attention_mask
											__lowercase												=			use_labels

											__lowercase												=			vocab_size
											__lowercase												=			d_model
											__lowercase												=			d_model
											__lowercase												=			decoder_layers
											__lowercase												=			decoder_layers
											__lowercase												=			decoder_ffn_dim
											__lowercase												=			decoder_attention_heads
											__lowercase												=			decoder_attention_heads
											__lowercase												=			eos_token_id
											__lowercase												=			bos_token_id
											__lowercase												=			pad_token_id
											__lowercase												=			decoder_start_token_id
											__lowercase												=			use_cache
											__lowercase												=			max_position_embeddings

											__lowercase												=			None
											__lowercase												=			decoder_seq_length
											__lowercase												=			2
											__lowercase												=			1







						def        _UpperCamelCase    (self							)			->						Optional[Any]:
											__lowercase												=			ids_tensor([self.batch_size, self.decoder_seq_length]     ,							self.vocab_size							)

											__lowercase												=			None
											if self.use_attention_mask:
																__lowercase												=			ids_tensor([self.batch_size, self.decoder_seq_length]     ,							vocab_size=2							)

											__lowercase												=			None
											if self.use_labels:
																__lowercase												=			ids_tensor([self.batch_size, self.decoder_seq_length]     ,							self.vocab_size							)

											__lowercase												=			SpeechaTextaConfig(
											    vocab_size=self.vocab_size     ,							d_model=self.d_model     ,							decoder_layers=self.decoder_layers     ,							decoder_ffn_dim=self.decoder_ffn_dim     ,							decoder_attention_heads=self.decoder_attention_heads     ,							eos_token_id=self.eos_token_id     ,							bos_token_id=self.bos_token_id     ,							use_cache=self.use_cache     ,							pad_token_id=self.pad_token_id     ,							decoder_start_token_id=self.decoder_start_token_id     ,							max_position_embeddings=self.max_position_embeddings     ,							)

											return (
											    config,
											    input_ids,
											    attention_mask,
											    lm_labels,
											)







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							)			->						List[Any]:
											__lowercase												=			True
											__lowercase												=			SpeechaTextaDecoder(config=UpperCAmelCase_							).to(UpperCAmelCase_							).eval()
											__lowercase												=			input_ids[:2]

											input_ids[input_ids == 0] += 1
											# first forward pass
											__lowercase												=			model(UpperCAmelCase_     ,							use_cache=UpperCAmelCase_							)
											__lowercase												=			model(UpperCAmelCase_							)
											__lowercase												=			model(UpperCAmelCase_     ,							use_cache=UpperCAmelCase_							)

											self.parent.assertTrue(len(UpperCAmelCase_							) == len(UpperCAmelCase_							)							)
											self.parent.assertTrue(len(UpperCAmelCase_							) == len(UpperCAmelCase_							) + 1							)

											__lowercase												=			outputs['''past_key_values''']

											# create hypothetical next token and extent to next_input_ids
											__lowercase												=			ids_tensor((2, 1)     ,							config.vocab_size - 1							) + 1

											# append to next input_ids and
											__lowercase												=			torch.cat([input_ids, next_tokens]     ,							dim=-1							)

											print(UpperCAmelCase_							)

											__lowercase												=			model(UpperCAmelCase_							)['''last_hidden_state''']
											__lowercase												=			model(UpperCAmelCase_     ,							past_key_values=UpperCAmelCase_							)['''last_hidden_state''']

											# select random slice
											__lowercase												=			ids_tensor((1,)     ,							output_from_past.shape[-1]							).item()
											__lowercase												=			output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
											__lowercase												=			output_from_past[:, 0, random_slice_idx].detach()

											# test that outputs are equal for slice
											assert torch.allclose(UpperCAmelCase_     ,							UpperCAmelCase_     ,							atol=1e-3							)







						def        _UpperCamelCase    (self							)			->						int:
											__lowercase												=			self.prepare_config_and_inputs()
											(
											    (
											    __lowercase
											)						, (
											    __lowercase
											)						, (
											    __lowercase
											)						, (
											    __lowercase
											)						, 
											)												=			config_and_inputs

											__lowercase												=			{
											    '''input_ids''': input_ids,
											    '''attention_mask''': attention_mask,
											}
											return config, inputs_dict



@require_torch
class 			_snake_case     (						UpperCamelCase						,			UpperCamelCase						,			UpperCamelCase						,			unittest.TestCase       ):
						__snake_case 			=     (SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
						__snake_case 			=     (SpeechaTextaForCausalLM,) if is_torch_available() else ()
						__snake_case 			=     {'text-generation': SpeechaTextaForCausalLM} if is_torch_available() else {}
						__snake_case 			=     True
						__snake_case 			=     False







						def        _UpperCamelCase    (self     ,							)			->						Any:
											__lowercase												=			SpeechaTextaStandaloneDecoderModelTester(self     ,							is_training=UpperCAmelCase_							)
											__lowercase												=			ConfigTester(self     ,							config_class=UpperCAmelCase_							)







						def        _UpperCamelCase    (self							)			->						List[Any]:
											pass







						def        _UpperCamelCase    (self							)			->						Tuple:
											pass







						def        _UpperCamelCase    (self							)			->						Dict:
											pass







						def        _UpperCamelCase    (self							)			->						Tuple:
											self.config_tester.run_common_tests()







						def        _UpperCamelCase    (self							)			->						str:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_decoder_model_past(*UpperCAmelCase_							)







						def        _UpperCamelCase    (self							)			->						Optional[Any]:
											return





"""simple docstring"""

import unittest
import warnings

from datasets.utils import experimental





@experimental
def 				__UpperCamelCase   (    )				->			Optional[Any]:




					"""simple docstring"""



					return "success"


class 			_snake_case     (						unittest.TestCase       ):







						def        _UpperCamelCase    (self							)			->						Tuple:
											with warnings.catch_warnings(record=UpperCAmelCase_							) as w:
																warnings.simplefilter('''always'''							)
																self.assertEqual(dummy_function()     ,							'''success'''							)
											self.assertEqual(len(UpperCAmelCase_							)     ,							1							)


