
'''simple docstring'''



import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    DistilBertForMaskedLM,
						    DistilBertForMultipleChoice,
						    DistilBertForQuestionAnswering,
						    DistilBertForSequenceClassification,
						    DistilBertForTokenClassification,
						    DistilBertModel,
						)




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						def __init__( self   ,       _lowercase   ,       _lowercase=13   ,       _lowercase=7   ,       _lowercase=True   ,       _lowercase=True   ,       _lowercase=False   ,       _lowercase=True   ,       _lowercase=99   ,       _lowercase=32   ,       _lowercase=5   ,       _lowercase=4   ,       _lowercase=37   ,       _lowercase="gelu"   ,       _lowercase=0.1   ,       _lowercase=0.1   ,       _lowercase=512   ,       _lowercase=16   ,       _lowercase=2   ,       _lowercase=0.02   ,       _lowercase=3   ,       _lowercase=4   ,       _lowercase=None   ,       ):

												"""simple docstring"""



												_lowerCAmelCase  						=			parent
												_lowerCAmelCase  						=			batch_size
												_lowerCAmelCase  						=			seq_length
												_lowerCAmelCase  						=			is_training
												_lowerCAmelCase  						=			use_input_mask
												_lowerCAmelCase  						=			use_token_type_ids
												_lowerCAmelCase  						=			use_labels
												_lowerCAmelCase  						=			vocab_size
												_lowerCAmelCase  						=			hidden_size
												_lowerCAmelCase  						=			num_hidden_layers
												_lowerCAmelCase  						=			num_attention_heads
												_lowerCAmelCase  						=			intermediate_size
												_lowerCAmelCase  						=			hidden_act
												_lowerCAmelCase  						=			hidden_dropout_prob
												_lowerCAmelCase  						=			attention_probs_dropout_prob
												_lowerCAmelCase  						=			max_position_embeddings
												_lowerCAmelCase  						=			type_vocab_size
												_lowerCAmelCase  						=			type_sequence_label_size
												_lowerCAmelCase  						=			initializer_range
												_lowerCAmelCase  						=			num_labels
												_lowerCAmelCase  						=			num_choices
												_lowerCAmelCase  						=			scope




						def  _lowercase     ( self				):

												"""simple docstring"""



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

												_lowerCAmelCase  						=			None
												if self.use_input_mask:
																		_lowerCAmelCase  						=			random_attention_mask([self.batch_size, self.seq_length]				)

												_lowerCAmelCase  						=			None
												_lowerCAmelCase  						=			None
												_lowerCAmelCase  						=			None
												if self.use_labels:
																		_lowerCAmelCase  						=			ids_tensor([self.batch_size]   ,       self.type_sequence_label_size				)
																		_lowerCAmelCase  						=			ids_tensor([self.batch_size, self.seq_length]   ,       self.num_labels				)
																		_lowerCAmelCase  						=			ids_tensor([self.batch_size]   ,       self.num_choices				)

												_lowerCAmelCase  						=			self.get_config()

												return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels




						def  _lowercase     ( self				):

												"""simple docstring"""



												return DistilBertConfig(
												    vocab_size=self.vocab_size   ,       dim=self.hidden_size   ,       n_layers=self.num_hidden_layers   ,       n_heads=self.num_attention_heads   ,       hidden_dim=self.intermediate_size   ,       hidden_act=self.hidden_act   ,       dropout=self.hidden_dropout_prob   ,       attention_dropout=self.attention_probs_dropout_prob   ,       max_position_embeddings=self.max_position_embeddings   ,       initializer_range=self.initializer_range   ,       )




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			DistilBertModel(config=_lowercase				)
												model.to(_lowercase				)
												model.eval()
												_lowerCAmelCase  						=			model(_lowercase   ,       _lowercase				)
												_lowerCAmelCase  						=			model(_lowercase				)
												self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, self.seq_length, self.hidden_size)				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			DistilBertForMaskedLM(config=_lowercase				)
												model.to(_lowercase				)
												model.eval()
												_lowerCAmelCase  						=			model(_lowercase   ,       attention_mask=_lowercase   ,       labels=_lowercase				)
												self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.seq_length, self.vocab_size)				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			DistilBertForQuestionAnswering(config=_lowercase				)
												model.to(_lowercase				)
												model.eval()
												_lowerCAmelCase  						=			model(
												    _lowercase   ,       attention_mask=_lowercase   ,       start_positions=_lowercase   ,       end_positions=_lowercase				)
												self.parent.assertEqual(result.start_logits.shape   ,       (self.batch_size, self.seq_length)				)
												self.parent.assertEqual(result.end_logits.shape   ,       (self.batch_size, self.seq_length)				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.num_labels
												_lowerCAmelCase  						=			DistilBertForSequenceClassification(_lowercase				)
												model.to(_lowercase				)
												model.eval()
												_lowerCAmelCase  						=			model(_lowercase   ,       attention_mask=_lowercase   ,       labels=_lowercase				)
												self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.num_labels)				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.num_labels
												_lowerCAmelCase  						=			DistilBertForTokenClassification(config=_lowercase				)
												model.to(_lowercase				)
												model.eval()

												_lowerCAmelCase  						=			model(_lowercase   ,       attention_mask=_lowercase   ,       labels=_lowercase				)
												self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.seq_length, self.num_labels)				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.num_choices
												_lowerCAmelCase  						=			DistilBertForMultipleChoice(config=_lowercase				)
												model.to(_lowercase				)
												model.eval()
												_lowerCAmelCase  						=			input_ids.unsqueeze(1				).expand(-1   ,       self.num_choices   ,       -1				).contiguous()
												_lowerCAmelCase  						=			input_mask.unsqueeze(1				).expand(-1   ,       self.num_choices   ,       -1				).contiguous()
												_lowerCAmelCase  						=			model(
												    _lowercase   ,       attention_mask=_lowercase   ,       labels=_lowercase   ,       )
												self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.num_choices)				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.prepare_config_and_inputs()
												((_lowerCAmelCase)						,   (_lowerCAmelCase)						,   (_lowerCAmelCase)						,   (_lowerCAmelCase)						,   (_lowerCAmelCase)						,   (_lowerCAmelCase))  						=			config_and_inputs
												_lowerCAmelCase  						=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
												return config, inputs_dict






@require_torch
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE	,							_SCREAMING_SNAKE_CASE	,							unittest.TestCase			):






						'''simple docstring'''






						_lowercase		:				List[str]									=       (
						    (
						        DistilBertModel,
						        DistilBertForMaskedLM,
						        DistilBertForMultipleChoice,
						        DistilBertForQuestionAnswering,
						        DistilBertForSequenceClassification,
						        DistilBertForTokenClassification,
						    )
						    if is_torch_available()
						    else None
						)
						_lowercase		:				Optional[Any]									=       (
						    {
						        '''feature-extraction''': DistilBertModel,
						        '''fill-mask''': DistilBertForMaskedLM,
						        '''question-answering''': DistilBertForQuestionAnswering,
						        '''text-classification''': DistilBertForSequenceClassification,
						        '''token-classification''': DistilBertForTokenClassification,
						        '''zero-shot''': DistilBertForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						_lowercase		:				int									=       True
						_lowercase		:				Optional[Any]									=       True
						_lowercase		:				Any									=       True
						_lowercase		:				Tuple									=       True




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			DistilBertModelTester(self				)
												_lowerCAmelCase  						=			ConfigTester(self   ,       config_class=_lowercase   ,       dim=37				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												self.config_tester.run_common_tests()




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_model(*_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_for_masked_lm(*_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_for_question_answering(*_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_for_sequence_classification(*_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_for_token_classification(*_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_distilbert_for_multiple_choice(*_lowercase				)




						@slow
						def  _lowercase     ( self				):

												"""simple docstring"""



												for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		_lowerCAmelCase  						=			DistilBertModel.from_pretrained(_lowercase				)
																		self.assertIsNotNone(_lowercase				)




						@slow
						@require_torch_gpu
						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase						,   _lowerCAmelCase  						=			self.model_tester.prepare_config_and_inputs_for_common()
												for model_class in self.all_model_classes:
																		# BertForMultipleChoice behaves incorrectly in JIT environments.
																		if model_class == DistilBertForMultipleChoice:
																								return

																		_lowerCAmelCase  						=			True
																		_lowerCAmelCase  						=			model_class(config=_lowercase				)

																		_lowerCAmelCase  						=			self._prepare_for_class(_lowercase   ,       _lowercase				)
																		_lowerCAmelCase  						=			torch.jit.trace(
																		    _lowercase   ,       (inputs_dict["""input_ids"""].to("""cpu"""				), inputs_dict["""attention_mask"""].to("""cpu"""				))				)

																		with tempfile.TemporaryDirectory() as tmp:
																								torch.jit.save(_lowercase   ,       os.path.join(_lowercase   ,       """traced_model.pt"""				)				)
																								_lowerCAmelCase  						=			torch.jit.load(os.path.join(_lowercase   ,       """traced_model.pt"""				)   ,       map_location=_lowercase				)
																								loaded(inputs_dict["""input_ids"""].to(_lowercase				)   ,       inputs_dict["""attention_mask"""].to(_lowercase				)				)






@require_torch
class   UpperCAmelCase_					(		unittest.TestCase			):






						'''simple docstring'''






						@slow
						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			DistilBertModel.from_pretrained("""distilbert-base-uncased"""				)
												_lowerCAmelCase  						=			torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]				)
												_lowerCAmelCase  						=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
												with torch.no_grad():
																		_lowerCAmelCase  						=			model(_lowercase   ,       attention_mask=_lowercase				)[0]
												_lowerCAmelCase  						=			torch.Size((1, 11, 768)				)
												self.assertEqual(output.shape   ,       _lowercase				)
												_lowerCAmelCase  						=			torch.tensor(
												    [[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]				)

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


'''simple docstring'''



def A				(__lowerCamelCase				:list[int]			,     __lowerCamelCase				:list[int]		):

						# Check if the input is valid
						if not len(__lowerCamelCase		) == len(__lowerCamelCase		) == 3:
												raise ValueError("""Please enter a valid equation."""		)
						if equationa[0] == equationa[1] == equationa[0] == equationa[1] == 0:
												raise ValueError("""Both a & b of two equations can't be zero."""		)

						# Extract the coefficients
						_lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase  						=			equationa
						_lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase  						=			equationa

						# Calculate the determinants of the matrices
						_lowerCAmelCase  						=			aa * ba - aa * ba
						_lowerCAmelCase  						=			ca * ba - ca * ba
						_lowerCAmelCase  						=			aa * ca - aa * ca

						# Check if the system of linear equations has a solution (using Cramer's rule)
						if determinant == 0:
												if determinant_x == determinant_y == 0:
																		raise ValueError("""Infinite solutions. (Consistent system)"""		)
												else:
																		raise ValueError("""No solution. (Inconsistent system)"""		)
						else:
												if determinant_x == determinant_y == 0:
																		# Trivial solution (Inconsistent system)
																		return (0.0, 0.0)
												else:
																		_lowerCAmelCase  						=			determinant_x / determinant
																		_lowerCAmelCase  						=			determinant_y / determinant
																		# Non-Trivial Solution (Consistent system)
																		return (x, y)
