



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      __lowerCAmelCase     (		unittest.TestCase      ):
					"""simple docstring"""






					def __init__(     self					:       List[Any]				,					_snake_case					:       int				,					_snake_case					:       List[Any]=13				,					_snake_case					:       List[str]=7				,					_snake_case					:       Any=True				,					_snake_case					:       str=True				,					_snake_case					:       str=True				,					_snake_case					:       int=True				,					_snake_case					:       int=99				,					_snake_case					:       Union[str, Any]=32				,					_snake_case					:       Optional[int]=5				,					_snake_case					:       int=4				,					_snake_case					:       List[str]=37				,					_snake_case					:       int="gelu"				,					_snake_case					:       Union[str, Any]=0.1				,					_snake_case					:       Optional[int]=0.1				,					_snake_case					:       Optional[int]=5_12				,					_snake_case					:       Optional[int]=16				,					_snake_case					:       Tuple=2				,					_snake_case					:       Tuple=0.02				,					_snake_case					:       Tuple=4				,					):






								"""simple docstring"""


								A__       =    parent
								A__       =    batch_size
								A__       =    seq_length
								A__       =    is_training
								A__       =    use_attention_mask
								A__       =    use_token_type_ids
								A__       =    use_labels
								A__       =    vocab_size
								A__       =    hidden_size
								A__       =    num_hidden_layers
								A__       =    num_attention_heads
								A__       =    intermediate_size
								A__       =    hidden_act
								A__       =    hidden_dropout_prob
								A__       =    attention_probs_dropout_prob
								A__       =    max_position_embeddings
								A__       =    type_vocab_size
								A__       =    type_sequence_label_size
								A__       =    initializer_range
								A__       =    num_choices



					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


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

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

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

								A__       =    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=_snake_case				,					initializer_range=self.initializer_range				,					)

								return config, input_ids, token_type_ids, attention_mask



					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


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



					def     _a							(     self					:       int					):






								"""simple docstring"""


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

								A__       =    True
								A__       =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
								A__       =    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      __lowerCAmelCase     (		UpperCAmelCase_							,     unittest.TestCase      ):
					"""simple docstring"""






					A__				:		Dict			       =    True

					A__				:		Optional[int]			       =    (
					    (
					        FlaxRobertaModel,
					        FlaxRobertaForCausalLM,
					        FlaxRobertaForMaskedLM,
					        FlaxRobertaForSequenceClassification,
					        FlaxRobertaForTokenClassification,
					        FlaxRobertaForMultipleChoice,
					        FlaxRobertaForQuestionAnswering,
					    )
					    if is_flax_available()
					    else ()
					)



					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    FlaxRobertaModelTester(self					)



					@slow
					def     _a							(     self					:       List[Any]					):






								"""simple docstring"""


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









import pytest

import datasets


# Import fixture modules as plugins
SCREAMING_SNAKE_CASE__       =      ['''tests.fixtures.files''', '''tests.fixtures.hub''', '''tests.fixtures.fsspec''']


def A						(       __UpperCamelCase ,	__UpperCamelCase					)						->      Optional[int]:
			# Mark tests as "unit" by default if not marked as "integration" (or already marked as "unit")
			for item in items:
						if any(marker in item.keywords for marker in ['integration', 'unit']					):
									continue
						item.add_marker(pytest.mark.unit					)


def A						(       __UpperCamelCase					)						->      str:
			config.addinivalue_line('markers' ,	'torchaudio_latest: mark test to run with torchaudio>=0.12'					)


@pytest.fixture(autouse=__UpperCamelCase					)
def A						(       __UpperCamelCase ,	__UpperCamelCase					)						->      Union[str, Any]:
			# test_hf_cache_home = tmp_path_factory.mktemp("cache")  # TODO: why a cache dir per test function does not work?
			A__       =    tmp_path_factory.getbasetemp() / 'cache'
			A__       =    test_hf_cache_home / 'datasets'
			A__       =    test_hf_cache_home / 'metrics'
			A__       =    test_hf_cache_home / 'modules'
			monkeypatch.setattr('datasets.config.HF_DATASETS_CACHE' ,	str(__UpperCamelCase					)					)
			monkeypatch.setattr('datasets.config.HF_METRICS_CACHE' ,	str(__UpperCamelCase					)					)
			monkeypatch.setattr('datasets.config.HF_MODULES_CACHE' ,	str(__UpperCamelCase					)					)
			A__       =    test_hf_datasets_cache / 'downloads'
			monkeypatch.setattr('datasets.config.DOWNLOADED_DATASETS_PATH' ,	str(__UpperCamelCase					)					)
			A__       =    test_hf_datasets_cache / 'downloads' / 'extracted'
			monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH' ,	str(__UpperCamelCase					)					)


@pytest.fixture(autouse=__UpperCamelCase ,	scope='session'					)
def A						(       )						->      Union[str, Any]:
			datasets.disable_progress_bar()


@pytest.fixture(autouse=__UpperCamelCase					)
def A						(       __UpperCamelCase					)						->      int:
			# don't take tests into account when counting downloads
			monkeypatch.setattr('datasets.config.HF_UPDATE_DOWNLOAD_COUNTS' ,	__UpperCamelCase					)






@pytest.fixture
def A						(       __UpperCamelCase					)						->      Any:
			# Required to suppress RemovedIn20Warning when feature(s) are not compatible with SQLAlchemy 2.0
			# To be removed once SQLAlchemy 2.0 supported
			monkeypatch.setattr('sqlalchemy.util.deprecations.SILENCE_UBER_WARNING' ,	__UpperCamelCase					)




