
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        SCREAMING_SNAKE_CASE__    (							unittest.TestCase    ):

							"""simple docstring"""






							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.0_2     ,	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     A__		(  self			)->   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       =			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=SCREAMING_SNAKE_CASE_     ,	initializer_range=self.initializer_range     ,	)

													return config, input_ids, token_type_ids, attention_mask



							def     A__		(  self			)->   Dict:





													'''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






@require_flax
class        SCREAMING_SNAKE_CASE__    (							SCREAMING_SNAKE_CASE_   ,		unittest.TestCase    ):

							"""simple docstring"""






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



							def     A__		(  self			)->   str:





													'''simple docstring'''






													__UpperCamelCase       =			FlaxAlbertModelTester(self			)



							@slow
							def     A__		(  self			)->   Tuple:





													'''simple docstring'''






													for model_class_name in self.all_model_classes:
																			__UpperCamelCase       =			model_class_name.from_pretrained('''albert-base-v2'''			)
																			__UpperCamelCase       =			model(np.ones((1, 1)			)			)
																			self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)






@require_flax
class        SCREAMING_SNAKE_CASE__    (							unittest.TestCase    ):

							"""simple docstring"""






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





													'''simple docstring'''






													__UpperCamelCase       =			FlaxAlbertModel.from_pretrained('''albert-base-v2'''			)
													__UpperCamelCase       =			np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]			)
													__UpperCamelCase       =			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
													__UpperCamelCase       =			model(SCREAMING_SNAKE_CASE_     ,	attention_mask=SCREAMING_SNAKE_CASE_			)[0]
													__UpperCamelCase       =			(1, 11, 768)
													self.assertEqual(output.shape     ,	SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			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]     ,	SCREAMING_SNAKE_CASE_     ,	atol=1E-4			)			)






# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import platform
import sys


lowercase__							:							List[str]									=			"3"

print("Python version:", sys.version)

print("OS platform:", platform.platform())
print("OS architecture:", platform.machine())

try:
				import torch

				print("Torch version:", torch.__version__)
				print("Cuda available:", torch.cuda.is_available())
				print("Cuda version:", torch.version.cuda)
				print("CuDNN version:", torch.backends.cudnn.version())
				print("Number of GPUs available:", torch.cuda.device_count())
except ImportError:
				print("Torch version:", None)

try:
				import transformers

				print("transformers version:", transformers.__version__)
except ImportError:
				print("transformers version:", None)




