




'''simple docstring'''


import unittest

from transformers import BertGenerationConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import BertGenerationDecoder, BertGenerationEncoder
class 						a_				:




	def __init__(       self     :  Any       ,		__lowerCAmelCase     :  int       ,		__lowerCAmelCase     :  Union[str, Any]=1_3       ,		__lowerCAmelCase     :  Optional[Any]=7       ,		__lowerCAmelCase     :  Tuple=True       ,		__lowerCAmelCase     :  Any=True       ,		__lowerCAmelCase     :  Tuple=9_9       ,		__lowerCAmelCase     :  str=3_2       ,		__lowerCAmelCase     :  Optional[Any]=5       ,		__lowerCAmelCase     :  Dict=4       ,		__lowerCAmelCase     :  str=3_7       ,		__lowerCAmelCase     :  List[str]="gelu"       ,		__lowerCAmelCase     :  List[Any]=0.1       ,		__lowerCAmelCase     :  str=0.1       ,		__lowerCAmelCase     :  Optional[int]=5_0       ,		__lowerCAmelCase     :  Any=0.02       ,		__lowerCAmelCase     :  List[str]=True       ,		__lowerCAmelCase     :  List[Any]=None       ,		):
							__snake_case						 =   parent
							__snake_case						 =   batch_size
							__snake_case						 =   seq_length
							__snake_case						 =   is_training
							__snake_case						 =   use_input_mask
							__snake_case						 =   vocab_size
							__snake_case						 =   hidden_size
							__snake_case						 =   num_hidden_layers
							__snake_case						 =   num_attention_heads
							__snake_case						 =   intermediate_size
							__snake_case						 =   hidden_act
							__snake_case						 =   hidden_dropout_prob
							__snake_case						 =   attention_probs_dropout_prob
							__snake_case						 =   max_position_embeddings
							__snake_case						 =   initializer_range
							__snake_case						 =   use_labels
							__snake_case						 =   scope




	def   lowercase__   (       self     :  Optional[int]      ):
							__snake_case						 =   ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size      )

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

							if self.use_labels:
													__snake_case						 =   ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size      )

							__snake_case						 =   self.get_config()

							return config, input_ids, input_mask, token_labels




	def   lowercase__   (       self     :  int      ):
							return BertGenerationConfig(
							    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       ,		is_decoder=__lowerCAmelCase       ,		initializer_range=self.initializer_range       ,		)




	def   lowercase__   (       self     :  List[Any]      ):
							(
							    (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       
							)						 =   self.prepare_config_and_inputs()

							__snake_case						 =   True
							__snake_case						 =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
							__snake_case						 =   ids_tensor([self.batch_size, self.seq_length]       ,		vocab_size=2      )

							return (
							    config,
							    input_ids,
							    input_mask,
							    token_labels,
							    encoder_hidden_states,
							    encoder_attention_mask,
							)




	def   lowercase__   (       self     :  Optional[int]       ,		__lowerCAmelCase     :  Any       ,		__lowerCAmelCase     :  Union[str, Any]       ,		__lowerCAmelCase     :  List[str]       ,		__lowerCAmelCase     :  Optional[int]       ,		**__lowerCAmelCase     :  Dict       ,		):
							__snake_case						 =   BertGenerationEncoder(config=__lowerCAmelCase      )
							model.to(__lowerCAmelCase      )
							model.eval()
							__snake_case						 =   model(__lowerCAmelCase       ,		attention_mask=__lowerCAmelCase      )
							__snake_case						 =   model(__lowerCAmelCase      )
							self.parent.assertEqual(result.last_hidden_state.shape       ,		(self.batch_size, self.seq_length, self.hidden_size)      )




	def   lowercase__   (       self     :  int       ,		__lowerCAmelCase     :  Dict       ,		__lowerCAmelCase     :  Any       ,		__lowerCAmelCase     :  str       ,		__lowerCAmelCase     :  Tuple       ,		__lowerCAmelCase     :  int       ,		__lowerCAmelCase     :  int       ,		**__lowerCAmelCase     :  Any       ,		):
							__snake_case						 =   True
							__snake_case						 =   BertGenerationEncoder(config=__lowerCAmelCase      )
							model.to(__lowerCAmelCase      )
							model.eval()
							__snake_case						 =   model(
							    __lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		encoder_hidden_states=__lowerCAmelCase       ,		encoder_attention_mask=__lowerCAmelCase       ,		)
							__snake_case						 =   model(
							    __lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		encoder_hidden_states=__lowerCAmelCase       ,		)
							self.parent.assertEqual(result.last_hidden_state.shape       ,		(self.batch_size, self.seq_length, self.hidden_size)      )




	def   lowercase__   (       self     :  List[Any]       ,		__lowerCAmelCase     :  List[str]       ,		__lowerCAmelCase     :  Any       ,		__lowerCAmelCase     :  Any       ,		__lowerCAmelCase     :  Dict       ,		__lowerCAmelCase     :  int       ,		__lowerCAmelCase     :  Dict       ,		**__lowerCAmelCase     :  List[str]       ,		):
							__snake_case						 =   True
							__snake_case						 =   True
							__snake_case						 =   BertGenerationDecoder(config=__lowerCAmelCase      ).to(__lowerCAmelCase      ).eval()

							# first forward pass
							__snake_case						 =   model(
							    __lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		encoder_hidden_states=__lowerCAmelCase       ,		encoder_attention_mask=__lowerCAmelCase       ,		use_cache=__lowerCAmelCase       ,		)
							__snake_case						 =   outputs.past_key_values

							# create hypothetical multiple next token and extent to next_input_ids
							__snake_case						 =   ids_tensor((self.batch_size, 3)       ,		config.vocab_size      )
							__snake_case						 =   ids_tensor((self.batch_size, 3)       ,		vocab_size=2      )

							# append to next input_ids and
							__snake_case						 =   torch.cat([input_ids, next_tokens]       ,		dim=-1      )
							__snake_case						 =   torch.cat([input_mask, next_mask]       ,		dim=-1      )

							__snake_case						 =   model(
							    __lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		encoder_hidden_states=__lowerCAmelCase       ,		encoder_attention_mask=__lowerCAmelCase       ,		output_hidden_states=__lowerCAmelCase       ,		)['hidden_states'][0]
							__snake_case						 =   model(
							    __lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		encoder_hidden_states=__lowerCAmelCase       ,		encoder_attention_mask=__lowerCAmelCase       ,		past_key_values=__lowerCAmelCase       ,		output_hidden_states=__lowerCAmelCase       ,		)['hidden_states'][0]

							# select random slice
							__snake_case						 =   ids_tensor((1,)       ,		output_from_past.shape[-1]      ).item()
							__snake_case						 =   output_from_no_past[:, -3:, random_slice_idx].detach()
							__snake_case						 =   output_from_past[:, :, random_slice_idx].detach()

							self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]      )

							# test that outputs are equal for slice
							self.parent.assertTrue(torch.allclose(__lowerCAmelCase       ,		__lowerCAmelCase       ,		atol=1E-3      )      )




	def   lowercase__   (       self     :  List[Any]       ,		__lowerCAmelCase     :  Optional[int]       ,		__lowerCAmelCase     :  Tuple       ,		__lowerCAmelCase     :  Any       ,		__lowerCAmelCase     :  Dict       ,		*__lowerCAmelCase     :  List[Any]       ,		):
							__snake_case						 =   BertGenerationDecoder(__lowerCAmelCase      )
							model.to(__lowerCAmelCase      )
							model.eval()
							__snake_case						 =   model(__lowerCAmelCase       ,		attention_mask=__lowerCAmelCase       ,		labels=__lowerCAmelCase      )
							self.parent.assertEqual(result.logits.shape       ,		(self.batch_size, self.seq_length, self.vocab_size)      )




	def   lowercase__   (       self     :  Optional[Any]      ):
							__snake_case ,       __snake_case ,       __snake_case ,       __snake_case						 =   self.prepare_config_and_inputs()
							__snake_case						 =   {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict





@require_torch
class 						a_				(			UpperCAmelCase__     ,						UpperCAmelCase__     ,						UpperCAmelCase__     ,						unittest.TestCase						):
	lowercase_       :     int			  =      (BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
	lowercase_       :     Dict			  =      (BertGenerationDecoder,) if is_torch_available() else ()
	lowercase_       :     Any			  =      (
	    {'''feature-extraction''': BertGenerationEncoder, '''text-generation''': BertGenerationDecoder}
	    if is_torch_available()
	    else {}
	)




	def   lowercase__   (       self     :  List[Any]      ):
							__snake_case						 =   BertGenerationEncoderTester(self      )
							__snake_case						 =   ConfigTester(self       ,		config_class=__lowerCAmelCase       ,		hidden_size=3_7      )




	def   lowercase__   (       self     :  int      ):
							self.config_tester.run_common_tests()




	def   lowercase__   (       self     :  str      ):
							__snake_case						 =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__lowerCAmelCase      )




	def   lowercase__   (       self     :  int      ):
							__snake_case ,       __snake_case ,       __snake_case ,       __snake_case						 =   self.model_tester.prepare_config_and_inputs()
							__snake_case						 =   'bert'
							self.model_tester.create_and_check_model(__lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase      )




	def   lowercase__   (       self     :  Optional[int]      ):
							__snake_case						 =   self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(*__lowerCAmelCase      )




	def   lowercase__   (       self     :  Tuple      ):
							__snake_case						 =   self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_decoder_model_past_large_inputs(*__lowerCAmelCase      )




	def   lowercase__   (       self     :  Tuple      ):
							# This regression test was failing with PyTorch < 1.3
							(
							    (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       (
							    __snake_case
							) ,       
							)						 =   self.model_tester.prepare_config_and_inputs_for_decoder()

							__snake_case						 =   None

							self.model_tester.create_and_check_model_as_decoder(
							    __lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase       ,		__lowerCAmelCase       ,		)




	def   lowercase__   (       self     :  Dict      ):
							__snake_case						 =   self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_for_causal_lm(*__lowerCAmelCase      )




	@slow
	def   lowercase__   (       self     :  Dict      ):
							__snake_case						 =   BertGenerationEncoder.from_pretrained('google/bert_for_seq_generation_L-24_bbc_encoder'      )
							self.assertIsNotNone(__lowerCAmelCase      )





@require_torch
class 						a_				(			unittest.TestCase						):




	@slow
	def   lowercase__   (       self     :  Optional[Any]      ):
							__snake_case						 =   BertGenerationEncoder.from_pretrained('google/bert_for_seq_generation_L-24_bbc_encoder'      )
							__snake_case						 =   torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]      )
							with torch.no_grad():
													__snake_case						 =   model(__lowerCAmelCase      )[0]
							__snake_case						 =   torch.Size([1, 8, 1_0_2_4]      )
							self.assertEqual(output.shape       ,		__lowerCAmelCase      )
							__snake_case						 =   torch.tensor(
							    [[[0.1775, 0.0083, -0.0321], [1.6002, 0.1287, 0.3912], [2.1473, 0.5791, 0.6066]]]      )
							self.assertTrue(torch.allclose(output[:, :3, :3]       ,		__lowerCAmelCase       ,		atol=1E-4      )      )





@require_torch
class 						a_				(			unittest.TestCase						):




	@slow
	def   lowercase__   (       self     :  int      ):
							__snake_case						 =   BertGenerationDecoder.from_pretrained('google/bert_for_seq_generation_L-24_bbc_encoder'      )
							__snake_case						 =   torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]      )
							with torch.no_grad():
													__snake_case						 =   model(__lowerCAmelCase      )[0]
							__snake_case						 =   torch.Size([1, 8, 5_0_3_5_8]      )
							self.assertEqual(output.shape       ,		__lowerCAmelCase      )
							__snake_case						 =   torch.tensor(
							    [[[-0.5788, -2.5994, -3.7054], [0.0438, 4.7997, 1.8795], [1.5862, 6.6409, 4.4638]]]      )
							self.assertTrue(torch.allclose(output[:, :3, :3]       ,		__lowerCAmelCase       ,		atol=1E-4      )      )







'''simple docstring'''


def 						lowerCamelCase__   (				a							):
						if not all(x.isalpha() for x in string							):
												raise ValueError('String must only contain alphabetic characters.'							)

						__snake_case						 =   sorted(string.lower()							)
						return len(a							) == len(set(a							)							)


if __name__ == "__main__":
	_lowercase  =			input("""Enter a string """).strip()

	_lowercase  =			is_isogram(input_str)
	print(f'''{input_str} is {'an' if isogram else 'not an'} isogram.''')

