


import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
		from transformers.models.roberta.modeling_flax_roberta import (
		    FlaxRobertaForCausalLM,
		    FlaxRobertaForMaskedLM,
		    FlaxRobertaForMultipleChoice,
		    FlaxRobertaForQuestionAnswering,
		    FlaxRobertaForSequenceClassification,
		    FlaxRobertaForTokenClassification,
		    FlaxRobertaModel,
		)

class 		__a				(    unittest.TestCase      ):
		def __init__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE=13      ,   _SCREAMING_SNAKE_CASE=7      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=True      ,   _SCREAMING_SNAKE_CASE=99      ,   _SCREAMING_SNAKE_CASE=32      ,   _SCREAMING_SNAKE_CASE=5      ,   _SCREAMING_SNAKE_CASE=4      ,   _SCREAMING_SNAKE_CASE=37      ,   _SCREAMING_SNAKE_CASE="gelu"      ,   _SCREAMING_SNAKE_CASE=0.1      ,   _SCREAMING_SNAKE_CASE=0.1      ,   _SCREAMING_SNAKE_CASE=512      ,   _SCREAMING_SNAKE_CASE=16      ,   _SCREAMING_SNAKE_CASE=2      ,   _SCREAMING_SNAKE_CASE=0.02      ,   _SCREAMING_SNAKE_CASE=4      ,   )			->	Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=      parent
									_UpperCAmelCase					=      batch_size
									_UpperCAmelCase					=      seq_length
									_UpperCAmelCase					=      is_training
									_UpperCAmelCase					=      use_attention_mask
									_UpperCAmelCase					=      use_token_type_ids
									_UpperCAmelCase					=      use_labels
									_UpperCAmelCase					=      vocab_size
									_UpperCAmelCase					=      hidden_size
									_UpperCAmelCase					=      num_hidden_layers
									_UpperCAmelCase					=      num_attention_heads
									_UpperCAmelCase					=      intermediate_size
									_UpperCAmelCase					=      hidden_act
									_UpperCAmelCase					=      hidden_dropout_prob
									_UpperCAmelCase					=      attention_probs_dropout_prob
									_UpperCAmelCase					=      max_position_embeddings
									_UpperCAmelCase					=      type_vocab_size
									_UpperCAmelCase					=      type_sequence_label_size
									_UpperCAmelCase					=      initializer_range
									_UpperCAmelCase					=      num_choices
		def      UpperCAmelCase__    (      self						)			->	List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=      ids_tensor([self.batch_size, self.seq_length]      ,   self.vocab_size						)

									_UpperCAmelCase					=      None
									if self.use_attention_mask:
																_UpperCAmelCase					=      random_attention_mask([self.batch_size, self.seq_length]						)

									_UpperCAmelCase					=      None
									if self.use_token_type_ids:
																_UpperCAmelCase					=      ids_tensor([self.batch_size, self.seq_length]      ,   self.type_vocab_size						)

									_UpperCAmelCase					=      RobertaConfig(
									    vocab_size=self.vocab_size      ,   hidden_size=self.hidden_size      ,   num_hidden_layers=self.num_hidden_layers      ,   num_attention_heads=self.num_attention_heads      ,   intermediate_size=self.intermediate_size      ,   hidden_act=self.hidden_act      ,   hidden_dropout_prob=self.hidden_dropout_prob      ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,   max_position_embeddings=self.max_position_embeddings      ,   type_vocab_size=self.type_vocab_size      ,   is_decoder=_SCREAMING_SNAKE_CASE      ,   initializer_range=self.initializer_range      ,   )

									return config, input_ids, token_type_ids, attention_mask
		def      UpperCAmelCase__    (      self						)			->	Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=      self.prepare_config_and_inputs()
									_UpperCAmelCase		,	_UpperCAmelCase		,	_UpperCAmelCase		,	_UpperCAmelCase					=      config_and_inputs
									_UpperCAmelCase					=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
									return config, inputs_dict






		def      UpperCAmelCase__    (      self						)			->	Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=      self.prepare_config_and_inputs()
									_UpperCAmelCase		,	_UpperCAmelCase		,	_UpperCAmelCase		,	_UpperCAmelCase					=      config_and_inputs

									_UpperCAmelCase					=      True
									_UpperCAmelCase					=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
									_UpperCAmelCase					=      ids_tensor([self.batch_size, self.seq_length]      ,   vocab_size=2						)

									return (
									    config,
									    input_ids,
									    token_type_ids,
									    encoder_hidden_states,
									    encoder_attention_mask,
									)



@require_flax
class 		__a				(    UpperCAmelCase   ,				unittest.TestCase      ):
		_a     :  Dict           =     True

		_a     :  List[str]           =     (
		    (
		        FlaxRobertaModel,
		        FlaxRobertaForCausalLM,
		        FlaxRobertaForMaskedLM,
		        FlaxRobertaForSequenceClassification,
		        FlaxRobertaForTokenClassification,
		        FlaxRobertaForMultipleChoice,
		        FlaxRobertaForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)
		def      UpperCAmelCase__    (      self						)			->	Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=      FlaxRobertaModelTester(self						)






		@slow
		def      UpperCAmelCase__    (      self						)			->	Any:




									"""simple docstring"""





									for model_class_name in self.all_model_classes:
																_UpperCAmelCase					=      model_class_name.from_pretrained('roberta-base'      ,   from_pt=_SCREAMING_SNAKE_CASE						)
																_UpperCAmelCase					=      model(np.ones((1, 1)						)						)
																self.assertIsNotNone(_SCREAMING_SNAKE_CASE						)




import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin

class 		__a				(    UpperCAmelCase      ):
		_a     :  Optional[int]           =     'MCTCTFeatureExtractor'
		_a     :  int           =     'AutoTokenizer'
		def __init__(      self      ,   _SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE						)			->	List[str]:




									"""simple docstring"""





									super().__init__(_SCREAMING_SNAKE_CASE      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      self.feature_extractor
									_UpperCAmelCase					=      False
		def __call__(      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	Tuple:




									"""simple docstring"""





									if self._in_target_context_manager:
																return self.current_processor(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									if "raw_speech" in kwargs:
																warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'						)
																_UpperCAmelCase					=      kwargs.pop('raw_speech'						)
									else:
																_UpperCAmelCase					=      kwargs.pop('audio'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('sampling_rate'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('text'      ,   _SCREAMING_SNAKE_CASE						)
									if len(_SCREAMING_SNAKE_CASE						) > 0:
																_UpperCAmelCase					=      args[0]
																_UpperCAmelCase					=      args[1:]

									if audio is None and text is None:
																raise ValueError('You need to specify either an `audio` or `text` input to process.'						)

									if audio is not None:
																_UpperCAmelCase					=      self.feature_extractor(_SCREAMING_SNAKE_CASE      ,   *_SCREAMING_SNAKE_CASE      ,   sampling_rate=_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
									if text is not None:
																_UpperCAmelCase					=      self.tokenizer(_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									if text is None:
																return inputs
									elif audio is None:
																return encodings
									else:
																_UpperCAmelCase					=      encodings['input_ids']
																return inputs
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	Optional[int]:




									"""simple docstring"""





									return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	str:




									"""simple docstring"""





									if self._in_target_context_manager:
																return self.current_processor.pad(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      kwargs.pop('input_features'      ,   _SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      kwargs.pop('labels'      ,   _SCREAMING_SNAKE_CASE						)
									if len(_SCREAMING_SNAKE_CASE						) > 0:
																_UpperCAmelCase					=      args[0]
																_UpperCAmelCase					=      args[1:]

									if input_features is not None:
																_UpperCAmelCase					=      self.feature_extractor.pad(_SCREAMING_SNAKE_CASE      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)
									if labels is not None:
																_UpperCAmelCase					=      self.tokenizer.pad(_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)

									if labels is None:
																return input_features
									elif input_features is None:
																return labels
									else:
																_UpperCAmelCase					=      labels['input_ids']
																return input_features
		def      UpperCAmelCase__    (      self      ,   *_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)			->	int:




									"""simple docstring"""





									return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE      ,   **_SCREAMING_SNAKE_CASE						)






		@contextmanager
		def      UpperCAmelCase__    (      self						)			->	Optional[Any]:




									"""simple docstring"""





									warnings.warn(
									    '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
									    'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
									    'your audio inputs, or in a separate call.'						)
									_UpperCAmelCase					=      True
									_UpperCAmelCase					=      self.tokenizer
									yield
									_UpperCAmelCase					=      self.feature_extractor
									_UpperCAmelCase					=      False
