






'''simple docstring'''



import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
      import jax.numpy as jnp

      from transformers.models.albert.modeling_flax_albert import (
          FlaxAlbertForMaskedLM,
          FlaxAlbertForMultipleChoice,
          FlaxAlbertForPreTraining,
          FlaxAlbertForQuestionAnswering,
          FlaxAlbertForSequenceClassification,
          FlaxAlbertForTokenClassification,
          FlaxAlbertModel,
      )
class UpperCAmelCase_       (     unittest.TestCase					):




      """simple docstring"""




      def __init__(			self      :		Tuple  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Dict=13  ,   UpperCAmelCase      :		Optional[Any]=7  ,   UpperCAmelCase      :		Tuple=True  ,   UpperCAmelCase      :		Dict=True  ,   UpperCAmelCase      :		List[Any]=True  ,   UpperCAmelCase      :		Union[str, Any]=True  ,   UpperCAmelCase      :		List[str]=99  ,   UpperCAmelCase      :		Any=32  ,   UpperCAmelCase      :		int=5  ,   UpperCAmelCase      :		Tuple=4  ,   UpperCAmelCase      :		Dict=37  ,   UpperCAmelCase      :		List[str]="gelu"  ,   UpperCAmelCase      :		Any=0.1  ,   UpperCAmelCase      :		Union[str, Any]=0.1  ,   UpperCAmelCase      :		List[str]=512  ,   UpperCAmelCase      :		List[str]=16  ,   UpperCAmelCase      :		str=2  ,   UpperCAmelCase      :		int=0.0_2  ,   UpperCAmelCase      :		int=4  ,   )	->	Optional[Any]:


       '''simple docstring'''

       lowercase       : int						=parent
       lowercase       : Tuple						=batch_size
       lowercase       : List[Any]						=seq_length
       lowercase       : List[Any]						=is_training
       lowercase       : str						=use_attention_mask
       lowercase       : str						=use_token_type_ids
       lowercase       : Optional[Any]						=use_labels
       lowercase       : Optional[Any]						=vocab_size
       lowercase       : Dict						=hidden_size
       lowercase       : Optional[int]						=num_hidden_layers
       lowercase       : Any						=num_attention_heads
       lowercase       : Dict						=intermediate_size
       lowercase       : int						=hidden_act
       lowercase       : List[str]						=hidden_dropout_prob
       lowercase       : Optional[Any]						=attention_probs_dropout_prob
       lowercase       : Any						=max_position_embeddings
       lowercase       : Any						=type_vocab_size
       lowercase       : Tuple						=type_sequence_label_size
       lowercase       : int						=initializer_range
       lowercase       : int						=num_choices






      def 					A__   (			self      :		Tuple		)	->	Optional[int]:


       '''simple docstring'''

       lowercase       : Union[str, Any]						=ids_tensor([self.batch_size, self.seq_length]  ,   self.vocab_size		)

       lowercase       : Optional[Any]						=None
       if self.use_attention_mask:
        lowercase       : Tuple						=random_attention_mask([self.batch_size, self.seq_length]		)

       lowercase       : Union[str, Any]						=None
       if self.use_token_type_ids:
        lowercase       : Union[str, Any]						=ids_tensor([self.batch_size, self.seq_length]  ,   self.type_vocab_size		)

       lowercase       : Union[str, Any]						=AlbertConfig(
           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=UpperCAmelCase  ,   initializer_range=self.initializer_range  ,   )

       return config, input_ids, token_type_ids, attention_mask






      def 					A__   (			self      :		Dict		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : Optional[int]						=self.prepare_config_and_inputs()
       lowercase	,		lowercase	,		lowercase	,		lowercase       : int						=config_and_inputs
       lowercase       : int						={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict





@require_flax
class UpperCAmelCase_       (     __A					,							unittest.TestCase					):




      """simple docstring"""




      UpperCamelCase_             =      (
          (
              FlaxAlbertModel,
              FlaxAlbertForPreTraining,
              FlaxAlbertForMaskedLM,
              FlaxAlbertForMultipleChoice,
              FlaxAlbertForQuestionAnswering,
              FlaxAlbertForSequenceClassification,
              FlaxAlbertForTokenClassification,
              FlaxAlbertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )






      def 					A__   (			self      :		List[Any]		)	->	List[str]:


       '''simple docstring'''

       lowercase       : Optional[int]						=FlaxAlbertModelTester(self		)






      @slow
      def 					A__   (			self      :		Dict		)	->	Optional[int]:


       '''simple docstring'''

       for model_class_name in self.all_model_classes:
        lowercase       : int						=model_class_name.from_pretrained('''albert-base-v2'''		)
        lowercase       : Optional[Any]						=model(np.ones((1, 1)		)		)
        self.assertIsNotNone(UpperCAmelCase		)





@require_flax
class UpperCAmelCase_       (     unittest.TestCase					):




      """simple docstring"""




      @slow
      def 					A__   (			self      :		List[Any]		)	->	List[str]:


       '''simple docstring'''

       lowercase       : List[str]						=FlaxAlbertModel.from_pretrained('''albert-base-v2'''		)
       lowercase       : Tuple						=np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
       lowercase       : str						=np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
       lowercase       : Dict						=model(UpperCAmelCase  ,   attention_mask=UpperCAmelCase		)[0]
       lowercase       : Any						=(1, 11, 768)
       self.assertEqual(output.shape  ,   UpperCAmelCase		)
       lowercase       : int						=np.array(
           [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]		)

       self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]  ,   UpperCAmelCase  ,   atol=1e-4		)		)







"""simple docstring"""

import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline


@pytest.mark.integration
def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT			):
  with pytest.raises(UpperCamelCase__			):
   requests.request("""GET"""					, """https://huggingface.co"""			)
  with pytest.raises(requests.exceptions.ConnectTimeout			):
   requests.request("""GET"""					, """https://huggingface.co"""					, timeout=1.0			)


@pytest.mark.integration
def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.CONNECTION_FAILS			):
  with pytest.raises(requests.exceptions.ConnectionError			):
   requests.request("""GET"""					, """https://huggingface.co"""			)


def lowerCAmelCase_   (					):






 """simple docstring"""







 with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1			):
  with pytest.raises(UpperCamelCase__			):
   http_head("""https://huggingface.co"""			)
