



from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import (
			    TFConvBertForMaskedLM,
			    TFConvBertForMultipleChoice,
			    TFConvBertForQuestionAnswering,
			    TFConvBertForSequenceClassification,
			    TFConvBertForTokenClassification,
			    TFConvBertModel,
			)


class 						lowercase    :
						'''simple docstring'''


						def __init__(  self    :				Tuple       ,	snake_case    :				Any       ,	snake_case    :				Optional[int]=13       ,	snake_case    :				Optional[int]=7       ,	snake_case    :				int=True       ,	snake_case    :				List[str]=True       ,	snake_case    :				Union[str, Any]=True       ,	snake_case    :				str=True       ,	snake_case    :				str=99       ,	snake_case    :				Dict=32       ,	snake_case    :				List[Any]=2       ,	snake_case    :				Any=4       ,	snake_case    :				str=37       ,	snake_case    :				Tuple="gelu"       ,	snake_case    :				List[str]=0.1       ,	snake_case    :				Union[str, Any]=0.1       ,	snake_case    :				List[str]=512       ,	snake_case    :				Any=16       ,	snake_case    :				Union[str, Any]=2       ,	snake_case    :				Optional[Any]=0.02       ,	snake_case    :				Any=3       ,	snake_case    :				Union[str, Any]=4       ,	snake_case    :				Tuple=None       ,	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Tuple						=				parent
											SCREAMING_SNAKE_CASE							:     List[Any]						=				13
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				7
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				True
											SCREAMING_SNAKE_CASE							:     str						=				True
											SCREAMING_SNAKE_CASE							:     int						=				True
											SCREAMING_SNAKE_CASE							:     Any						=				True
											SCREAMING_SNAKE_CASE							:     Any						=				99
											SCREAMING_SNAKE_CASE							:     List[Any]						=				384
											SCREAMING_SNAKE_CASE							:     int						=				2
											SCREAMING_SNAKE_CASE							:     Tuple						=				4
											SCREAMING_SNAKE_CASE							:     Tuple						=				37
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				'gelu'
											SCREAMING_SNAKE_CASE							:     Any						=				0.1
											SCREAMING_SNAKE_CASE							:     str						=				0.1
											SCREAMING_SNAKE_CASE							:     int						=				512
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				16
											SCREAMING_SNAKE_CASE							:     Any						=				2
											SCREAMING_SNAKE_CASE							:     List[Any]						=				0.02
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				3
											SCREAMING_SNAKE_CASE							:     Any						=				4
											SCREAMING_SNAKE_CASE							:     str						=				128
											SCREAMING_SNAKE_CASE							:     str						=				2
											SCREAMING_SNAKE_CASE							:     List[Any]						=				9
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				1
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				None







						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[str]						=				ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size	)

											SCREAMING_SNAKE_CASE							:     Optional[int]						=				None
											if self.use_input_mask:
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				random_attention_mask([self.batch_size, self.seq_length]	)

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

											SCREAMING_SNAKE_CASE							:     Tuple						=				None
											SCREAMING_SNAKE_CASE							:     Any						=				None
											SCREAMING_SNAKE_CASE							:     int						=				None
											if self.use_labels:
																SCREAMING_SNAKE_CASE							:     Tuple						=				ids_tensor([self.batch_size]       ,	self.type_sequence_label_size	)
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				ids_tensor([self.batch_size, self.seq_length]       ,	self.num_labels	)
																SCREAMING_SNAKE_CASE							:     List[Any]						=				ids_tensor([self.batch_size]       ,	self.num_choices	)

											SCREAMING_SNAKE_CASE							:     List[Any]						=				ConvBertConfig(
											    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       ,	initializer_range=self.initializer_range       ,	return_dict=snake_case       ,	)

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







						def       lowerCamelCase_				(  self    :				Dict       ,	snake_case    :				Dict       ,	snake_case    :				Tuple       ,	snake_case    :				Union[str, Any]       ,	snake_case    :				Optional[Any]       ,	snake_case    :				str       ,	snake_case    :				str       ,	snake_case    :				Optional[int]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[str]						=				TFConvBertModel(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     List[str]						=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

											SCREAMING_SNAKE_CASE							:     Tuple						=				[input_ids, input_mask]
											SCREAMING_SNAKE_CASE							:     str						=				model(snake_case	)

											SCREAMING_SNAKE_CASE							:     Optional[int]						=				model(snake_case	)

											self.parent.assertEqual(result.last_hidden_state.shape       ,	(self.batch_size, self.seq_length, self.hidden_size)	)







						def       lowerCamelCase_				(  self    :				Union[str, Any]       ,	snake_case    :				Optional[Any]       ,	snake_case    :				List[Any]       ,	snake_case    :				Tuple       ,	snake_case    :				int       ,	snake_case    :				List[Any]       ,	snake_case    :				List[str]       ,	snake_case    :				Optional[int]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				TFConvBertForMaskedLM(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     Tuple						=				{
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											    'token_type_ids': token_type_ids,
											}
											SCREAMING_SNAKE_CASE							:     List[str]						=				model(snake_case	)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.vocab_size)	)







						def       lowerCamelCase_				(  self    :				Tuple       ,	snake_case    :				List[Any]       ,	snake_case    :				Any       ,	snake_case    :				Union[str, Any]       ,	snake_case    :				str       ,	snake_case    :				Optional[int]       ,	snake_case    :				List[str]       ,	snake_case    :				List[str]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				self.num_labels
											SCREAMING_SNAKE_CASE							:     int						=				TFConvBertForSequenceClassification(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     str						=				{
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											    'token_type_ids': token_type_ids,
											}

											SCREAMING_SNAKE_CASE							:     Tuple						=				model(snake_case	)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_labels)	)







						def       lowerCamelCase_				(  self    :				Union[str, Any]       ,	snake_case    :				List[str]       ,	snake_case    :				Tuple       ,	snake_case    :				str       ,	snake_case    :				int       ,	snake_case    :				str       ,	snake_case    :				List[str]       ,	snake_case    :				List[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				self.num_choices
											SCREAMING_SNAKE_CASE							:     Any						=				TFConvBertForMultipleChoice(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				tf.tile(tf.expand_dims(snake_case       ,	1	)       ,	(1, self.num_choices, 1)	)
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				tf.tile(tf.expand_dims(snake_case       ,	1	)       ,	(1, self.num_choices, 1)	)
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				tf.tile(tf.expand_dims(snake_case       ,	1	)       ,	(1, self.num_choices, 1)	)
											SCREAMING_SNAKE_CASE							:     Any						=				{
											    'input_ids': multiple_choice_inputs_ids,
											    'attention_mask': multiple_choice_input_mask,
											    'token_type_ids': multiple_choice_token_type_ids,
											}
											SCREAMING_SNAKE_CASE							:     Dict						=				model(snake_case	)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_choices)	)







						def       lowerCamelCase_				(  self    :				str       ,	snake_case    :				Optional[Any]       ,	snake_case    :				Tuple       ,	snake_case    :				int       ,	snake_case    :				str       ,	snake_case    :				int       ,	snake_case    :				Optional[Any]       ,	snake_case    :				Union[str, Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     int						=				self.num_labels
											SCREAMING_SNAKE_CASE							:     str						=				TFConvBertForTokenClassification(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     Any						=				{
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											    'token_type_ids': token_type_ids,
											}
											SCREAMING_SNAKE_CASE							:     Any						=				model(snake_case	)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.num_labels)	)







						def       lowerCamelCase_				(  self    :				Any       ,	snake_case    :				Any       ,	snake_case    :				Any       ,	snake_case    :				Tuple       ,	snake_case    :				List[Any]       ,	snake_case    :				List[Any]       ,	snake_case    :				Tuple       ,	snake_case    :				Optional[int]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				TFConvBertForQuestionAnswering(config=snake_case	)
											SCREAMING_SNAKE_CASE							:     Tuple						=				{
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											    'token_type_ids': token_type_ids,
											}

											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				model(snake_case	)
											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       lowerCamelCase_				(  self    :				Union[str, Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				self.prepare_config_and_inputs()
											(
											    (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  (
											    SCREAMING_SNAKE_CASE
											)					,  
											)							:     List[str]						=				config_and_inputs
											SCREAMING_SNAKE_CASE							:     int						=				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
											return config, inputs_dict


@require_tf
class 						lowercase    (							SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_      ,    unittest.TestCase):
						'''simple docstring'''


						UpperCAmelCase			:		Tuple		=		(
						    (
						        TFConvBertModel,
						        TFConvBertForMaskedLM,
						        TFConvBertForQuestionAnswering,
						        TFConvBertForSequenceClassification,
						        TFConvBertForTokenClassification,
						        TFConvBertForMultipleChoice,
						    )
						    if is_tf_available()
						    else ()
						)
						UpperCAmelCase			:		List[Any]		=		(
						    {
						        'feature-extraction': TFConvBertModel,
						        'fill-mask': TFConvBertForMaskedLM,
						        'question-answering': TFConvBertForQuestionAnswering,
						        'text-classification': TFConvBertForSequenceClassification,
						        'token-classification': TFConvBertForTokenClassification,
						        'zero-shot': TFConvBertForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						UpperCAmelCase			:		str		=		False
						UpperCAmelCase			:		Dict		=		False
						UpperCAmelCase			:		str		=		False







						def       lowerCamelCase_				(  self    :				Dict	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[str]						=				TFConvBertModelTester(self	)
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				ConfigTester(self       ,	config_class=snake_case       ,	hidden_size=37	)







						def       lowerCamelCase_				(  self    :				List[str]	):



											'''simple docstring'''


											self.config_tester.run_common_tests()







						def       lowerCamelCase_				(  self    :				str	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*snake_case	)







						def       lowerCamelCase_				(  self    :				str	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*snake_case	)







						def       lowerCamelCase_				(  self    :				List[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*snake_case	)







						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[int]						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*snake_case	)







						def       lowerCamelCase_				(  self    :				Union[str, Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Any						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*snake_case	)







						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[Any]						=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*snake_case	)







						@slow
						def       lowerCamelCase_				(  self    :				Optional[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Optional[Any]						=				self.model_tester.prepare_config_and_inputs_for_common()
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				True
											SCREAMING_SNAKE_CASE							:     int						=				True

											if hasattr(snake_case       ,	'use_cache'	):
																SCREAMING_SNAKE_CASE							:     str						=				True

											SCREAMING_SNAKE_CASE							:     str						=				getattr(self.model_tester       ,	'encoder_seq_length'       ,	self.model_tester.seq_length	)
											SCREAMING_SNAKE_CASE							:     Tuple						=				getattr(self.model_tester       ,	'key_length'       ,	snake_case	)

											for model_class in self.all_model_classes:
																SCREAMING_SNAKE_CASE							:     Optional[Any]						=				self._prepare_for_class(snake_case       ,	snake_case	)
																SCREAMING_SNAKE_CASE							:     Optional[Any]						=				model_class(snake_case	)
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				len(model(snake_case	)	)

																with tempfile.TemporaryDirectory() as tmpdirname:
																					model.save_pretrained(snake_case       ,	saved_model=snake_case	)
																					SCREAMING_SNAKE_CASE							:     List[Any]						=				os.path.join(snake_case       ,	'saved_model'       ,	'1'	)
																					SCREAMING_SNAKE_CASE							:     List[Any]						=				tf.keras.models.load_model(snake_case	)
																					SCREAMING_SNAKE_CASE							:     Dict						=				model(snake_case	)

																					if self.is_encoder_decoder:
																										SCREAMING_SNAKE_CASE							:     List[Any]						=				outputs['encoder_hidden_states']
																										SCREAMING_SNAKE_CASE							:     Optional[Any]						=				outputs['encoder_attentions']
																					else:
																										SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				outputs['hidden_states']
																										SCREAMING_SNAKE_CASE							:     Optional[int]						=				outputs['attentions']

																					self.assertEqual(len(snake_case	)       ,	snake_case	)

																					SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				getattr(
																					    self.model_tester       ,	'expected_num_hidden_layers'       ,	self.model_tester.num_hidden_layers + 1	)

																					self.assertEqual(len(snake_case	)       ,	snake_case	)
																					self.assertListEqual(
																					    list(output_hidden_states[0].shape[-2:]	)       ,	[self.model_tester.seq_length, self.model_tester.hidden_size]       ,	)

																					self.assertEqual(len(snake_case	)       ,	self.model_tester.num_hidden_layers	)
																					self.assertListEqual(
																					    list(output_attentions[0].shape[-3:]	)       ,	[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,	)







						@slow
						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Any						=				TFConvBertModel.from_pretrained('YituTech/conv-bert-base'	)
											self.assertIsNotNone(snake_case	)







						def       lowerCamelCase_				(  self    :				Optional[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				self.model_tester.prepare_config_and_inputs_for_common()
											SCREAMING_SNAKE_CASE							:     List[Any]						=				True
											SCREAMING_SNAKE_CASE							:     Tuple						=				getattr(self.model_tester       ,	'decoder_seq_length'       ,	self.model_tester.seq_length	)
											SCREAMING_SNAKE_CASE							:     List[str]						=				getattr(self.model_tester       ,	'encoder_seq_length'       ,	self.model_tester.seq_length	)
											SCREAMING_SNAKE_CASE							:     Tuple						=				getattr(self.model_tester       ,	'key_length'       ,	snake_case	)
											SCREAMING_SNAKE_CASE							:     List[Any]						=				getattr(self.model_tester       ,	'key_length'       ,	snake_case	)

											def check_decoder_attentions_output(snake_case    :				Dict	):
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				len(snake_case	)
																self.assertEqual(out_len % 2       ,	0	)
																SCREAMING_SNAKE_CASE							:     Dict						=				outputs.decoder_attentions
																self.assertEqual(len(snake_case	)       ,	self.model_tester.num_hidden_layers	)
																self.assertListEqual(
																    list(decoder_attentions[0].shape[-3:]	)       ,	[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]       ,	)

											def check_encoder_attentions_output(snake_case    :				Any	):
																SCREAMING_SNAKE_CASE							:     Dict						=				[
																    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
																]
																self.assertEqual(len(snake_case	)       ,	self.model_tester.num_hidden_layers	)
																self.assertListEqual(
																    list(attentions[0].shape[-3:]	)       ,	[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]       ,	)

											for model_class in self.all_model_classes:
																SCREAMING_SNAKE_CASE							:     Optional[int]						=				True
																SCREAMING_SNAKE_CASE							:     Any						=				False
																SCREAMING_SNAKE_CASE							:     List[str]						=				model_class(snake_case	)
																SCREAMING_SNAKE_CASE							:     Dict						=				model(self._prepare_for_class(snake_case       ,	snake_case	)	)
																SCREAMING_SNAKE_CASE							:     Optional[int]						=				len(snake_case	)
																self.assertEqual(config.output_hidden_states       ,	snake_case	)
																check_encoder_attentions_output(snake_case	)

																if self.is_encoder_decoder:
																					SCREAMING_SNAKE_CASE							:     Dict						=				model_class(snake_case	)
																					SCREAMING_SNAKE_CASE							:     List[Any]						=				model(self._prepare_for_class(snake_case       ,	snake_case	)	)
																					self.assertEqual(config.output_hidden_states       ,	snake_case	)
																					check_decoder_attentions_output(snake_case	)

																# Check that output attentions can also be changed via the config
																del inputs_dict["output_attentions"]
																SCREAMING_SNAKE_CASE							:     Tuple						=				True
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				model_class(snake_case	)
																SCREAMING_SNAKE_CASE							:     List[Any]						=				model(self._prepare_for_class(snake_case       ,	snake_case	)	)
																self.assertEqual(config.output_hidden_states       ,	snake_case	)
																check_encoder_attentions_output(snake_case	)

																# Check attention is always last and order is fine
																SCREAMING_SNAKE_CASE							:     List[str]						=				True
																SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				True
																SCREAMING_SNAKE_CASE							:     List[Any]						=				model_class(snake_case	)
																SCREAMING_SNAKE_CASE							:     Tuple						=				model(self._prepare_for_class(snake_case       ,	snake_case	)	)

																self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)       ,	len(snake_case	)	)
																self.assertEqual(model.config.output_hidden_states       ,	snake_case	)
																check_encoder_attentions_output(snake_case	)


@require_tf
class 						lowercase    (							unittest.TestCase):
						'''simple docstring'''


						@slow
						def       lowerCamelCase_				(  self    :				List[str]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				TFConvBertModel.from_pretrained('YituTech/conv-bert-base'	)
											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				tf.constant([[0, 1, 2, 3, 4, 5]]	)
											SCREAMING_SNAKE_CASE							:     Dict						=				model(snake_case	)[0]

											SCREAMING_SNAKE_CASE							:     str						=				[1, 6, 768]
											self.assertEqual(output.shape       ,	snake_case	)

											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				tf.constant(
											    [
											        [
											            [-0.03475493, -0.4686034, -0.30638832],
											            [0.22637248, -0.26988646, -0.7423424],
											            [0.10324868, -0.45013508, -0.58280784],
											        ]
											    ]	)
											tf.debugging.assert_near(output[:, :3, :3]       ,	snake_case       ,	atol=1E-4	)




from datetime import datetime

import matplotlib.pyplot as plt
import torch

def        __a			(   __lowerCAmelCase   )     ->     int:
					for param in module.parameters():
										SCREAMING_SNAKE_CASE							:     List[Any]						=				False

def        __a			(   )     ->     List[str]:
					SCREAMING_SNAKE_CASE							:     List[Any]						=				'cuda' if torch.cuda.is_available() else 'cpu'
					if torch.backends.mps.is_available() and torch.backends.mps.is_built():
										SCREAMING_SNAKE_CASE							:     List[str]						=				'mps'
					if device == "mps":
										print(
										    'WARNING: MPS currently doesn\'t seem to work, and messes up backpropagation without any visible torch'
										    ' errors. I recommend using CUDA on a colab notebook or CPU instead if you\'re facing inexplicable issues'
										    ' with generations.'   )
					return device

def        __a			(   __lowerCAmelCase   )     ->     List[Any]:
					SCREAMING_SNAKE_CASE							:     Optional[int]						=				plt.imshow(__lowerCAmelCase   )
					fig.axes.get_xaxis().set_visible(__lowerCAmelCase   )
					fig.axes.get_yaxis().set_visible(__lowerCAmelCase   )
					plt.show()



def        __a			(   )     ->     Optional[Any]:
					SCREAMING_SNAKE_CASE							:     str						=				datetime.now()
					SCREAMING_SNAKE_CASE							:     Optional[int]						=				current_time.strftime('%H:%M:%S'   )
					return timestamp