



'''simple docstring'''

import unittest

from transformers import AutoTokenizer, FalconConfig, 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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    FalconForCausalLM,
							    FalconForQuestionAnswering,
							    FalconForSequenceClassification,
							    FalconForTokenClassification,
							    FalconModel,
							)

class       __magic_name__		:







							def __init__(				self   :			str      ,_UpperCAmelCase   :			Any      ,_UpperCAmelCase   :			str=3      ,_UpperCAmelCase   :			List[Any]=7      ,_UpperCAmelCase   :			Dict=True      ,_UpperCAmelCase   :			Optional[Any]=True      ,_UpperCAmelCase   :			str=False      ,_UpperCAmelCase   :			int=True      ,_UpperCAmelCase   :			int=99      ,_UpperCAmelCase   :			Optional[int]=32      ,_UpperCAmelCase   :			int=5      ,_UpperCAmelCase   :			int=4      ,_UpperCAmelCase   :			Dict=37      ,_UpperCAmelCase   :			Any="gelu"      ,_UpperCAmelCase   :			Optional[Any]=0.1      ,_UpperCAmelCase   :			Optional[int]=0.1      ,_UpperCAmelCase   :			List[str]=512      ,_UpperCAmelCase   :			List[Any]=16      ,_UpperCAmelCase   :			Any=2      ,_UpperCAmelCase   :			Union[str, Any]=0.02      ,_UpperCAmelCase   :			Any=3      ,_UpperCAmelCase   :			Union[str, Any]=4      ,_UpperCAmelCase   :			str=None      ,):
									_a	: Tuple								=				parent
									_a	: Any								=				batch_size
									_a	: Optional[int]								=				seq_length
									_a	: str								=				is_training
									_a	: Union[str, Any]								=				use_input_mask
									_a	: Optional[Any]								=				use_token_type_ids
									_a	: List[Any]								=				use_labels
									_a	: List[str]								=				vocab_size
									_a	: Optional[Any]								=				hidden_size
									_a	: List[Any]								=				num_hidden_layers
									_a	: Optional[int]								=				num_attention_heads
									_a	: Dict								=				intermediate_size
									_a	: int								=				hidden_act
									_a	: str								=				hidden_dropout_prob
									_a	: Optional[Any]								=				attention_probs_dropout_prob
									_a	: Optional[int]								=				max_position_embeddings
									_a	: Dict								=				type_vocab_size
									_a	: List[Any]								=				type_sequence_label_size
									_a	: Dict								=				initializer_range
									_a	: int								=				num_labels
									_a	: Any								=				num_choices
									_a	: List[str]								=				scope







							def 				__lowercase     (				self   :			Any						):
									_a	: Tuple								=				ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size						)

									_a	: Union[str, Any]								=				None
									if self.use_input_mask:
											_a	: List[Any]								=				random_attention_mask([self.batch_size, self.seq_length]						)

									_a	: str								=				None

									_a	: Dict								=				None
									_a	: str								=				None
									_a	: Optional[Any]								=				None
									if self.use_labels:
											_a	: Tuple								=				ids_tensor([self.batch_size]      ,self.type_sequence_label_size						)
											_a	: Optional[int]								=				ids_tensor([self.batch_size, self.seq_length]      ,self.num_labels						)
											_a	: Tuple								=				ids_tensor([self.batch_size]      ,self.num_choices						)

									_a	: Tuple								=				self.get_config()

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







							def 				__lowercase     (				self   :			Optional[Any]						):
									return FalconConfig(
									    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      ,pad_token_id=1      ,new_decoder_architecture=_UpperCAmelCase      ,)







							def 				__lowercase     (				self   :			Optional[int]      ,_UpperCAmelCase   :			Any      ,_UpperCAmelCase   :			List[Any]      ,_UpperCAmelCase   :			int      ,_UpperCAmelCase   :			Optional[int]      ,_UpperCAmelCase   :			Union[str, Any]      ,_UpperCAmelCase   :			List[str]      ,_UpperCAmelCase   :			List[str]						):
									_a	: Tuple								=				FalconModel(config=_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: Optional[Any]								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase						)
									_a	: Optional[Any]								=				model(_UpperCAmelCase						)
									self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)						)







							def 				__lowercase     (				self   :			int      ,_UpperCAmelCase   :			List[str]      ,_UpperCAmelCase   :			List[str]      ,_UpperCAmelCase   :			List[Any]      ,_UpperCAmelCase   :			List[str]      ,_UpperCAmelCase   :			Dict      ,_UpperCAmelCase   :			Union[str, Any]      ,_UpperCAmelCase   :			Tuple      ,_UpperCAmelCase   :			List[Any]      ,_UpperCAmelCase   :			Union[str, Any]      ,):
									_a	: Any								=				True
									_a	: str								=				FalconModel(_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: Union[str, Any]								=				model(
									    _UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,encoder_hidden_states=_UpperCAmelCase      ,encoder_attention_mask=_UpperCAmelCase      ,)
									_a	: Union[str, Any]								=				model(
									    _UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,encoder_hidden_states=_UpperCAmelCase      ,)
									_a	: Dict								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase						)
									self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)						)







							def 				__lowercase     (				self   :			Dict      ,_UpperCAmelCase   :			Tuple      ,_UpperCAmelCase   :			List[Any]      ,_UpperCAmelCase   :			Dict      ,_UpperCAmelCase   :			str      ,_UpperCAmelCase   :			Union[str, Any]      ,_UpperCAmelCase   :			Optional[int]      ,_UpperCAmelCase   :			int      ,_UpperCAmelCase   :			List[str]      ,_UpperCAmelCase   :			Tuple      ,):
									_a	: Union[str, Any]								=				FalconForCausalLM(config=_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: int								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,labels=_UpperCAmelCase						)
									self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.vocab_size)						)







							def 				__lowercase     (				self   :			Dict      ,_UpperCAmelCase   :			int      ,_UpperCAmelCase   :			str      ,_UpperCAmelCase   :			Dict      ,_UpperCAmelCase   :			Tuple      ,_UpperCAmelCase   :			Optional[int]      ,_UpperCAmelCase   :			Optional[Any]      ,_UpperCAmelCase   :			Tuple      ,_UpperCAmelCase   :			List[Any]      ,_UpperCAmelCase   :			str      ,):
									_a	: Tuple								=				True
									_a	: Optional[int]								=				True
									_a	: Optional[Any]								=				FalconForCausalLM(config=_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()

									# first forward pass
									_a	: List[Any]								=				model(
									    _UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,encoder_hidden_states=_UpperCAmelCase      ,encoder_attention_mask=_UpperCAmelCase      ,use_cache=_UpperCAmelCase      ,)
									_a	: List[str]								=				outputs.past_key_values

									# create hypothetical multiple next token and extent to next_input_ids
									_a	: List[str]								=				ids_tensor((self.batch_size, 3)      ,config.vocab_size						)
									_a	: Optional[int]								=				ids_tensor((self.batch_size, 3)      ,vocab_size=2						)

									# append to next input_ids and
									_a	: Optional[Any]								=				torch.cat([input_ids, next_tokens]      ,dim=-1						)
									_a	: Tuple								=				torch.cat([input_mask, next_mask]      ,dim=-1						)

									_a	: Any								=				model(
									    _UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,encoder_hidden_states=_UpperCAmelCase      ,encoder_attention_mask=_UpperCAmelCase      ,output_hidden_states=_UpperCAmelCase      ,)['hidden_states'][0]
									_a	: Optional[int]								=				model(
									    _UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,encoder_hidden_states=_UpperCAmelCase      ,encoder_attention_mask=_UpperCAmelCase      ,past_key_values=_UpperCAmelCase      ,output_hidden_states=_UpperCAmelCase      ,)['hidden_states'][0]

									# select random slice
									_a	: str								=				ids_tensor((1,)      ,output_from_past.shape[-1]						).item()
									_a	: int								=				output_from_no_past[:, -3:, random_slice_idx].detach()
									_a	: int								=				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(_UpperCAmelCase      ,_UpperCAmelCase      ,atol=1E-3						)						)







							def 				__lowercase     (				self   :			Any						):
									_a	: List[Any]								=				self.prepare_config_and_inputs()
									(
									    (
									    _a
									)			,   (
									    _a
									)			,   (
									    _a
									)			,   (
									    _a
									)			,   (
									    _a
									)			,   (
									    _a
									)			,   (
									    _a
									)			,   
									)	: Any								=				config_and_inputs
									_a	: Union[str, Any]								=				{'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict

@require_torch
class       __magic_name__		(       _UpperCamelCase     ,		_UpperCamelCase     ,		_UpperCamelCase     ,		unittest.TestCase  ):
							lowerCAmelCase			:       List[Any]  							=   (
							    (
							        FalconModel,
							        FalconForCausalLM,
							        FalconForSequenceClassification,
							        FalconForTokenClassification,
							        FalconForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							lowerCAmelCase			:       Any  							=   (FalconForCausalLM,) if is_torch_available() else ()
							lowerCAmelCase			:       int  							=   (
							    {
							        'feature-extraction': FalconModel,
							        'text-classification': FalconForSequenceClassification,
							        'text-generation': FalconForCausalLM,
							        'question-answering': FalconForQuestionAnswering,
							        'token-classification': FalconForTokenClassification,
							        'zero-shot': FalconForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							lowerCAmelCase			:       List[str]  							=   False
							lowerCAmelCase			:       str  							=   False







							def 				__lowercase     (				self   :			str						):
									_a	: int								=				FalconModelTester(self						)
									_a	: Tuple								=				ConfigTester(self      ,config_class=_UpperCAmelCase      ,hidden_size=37						)







							def 				__lowercase     (				self   :			Any						):
									self.config_tester.run_common_tests()







							def 				__lowercase     (				self   :			Any						):
									_a	: str								=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCAmelCase						)







							def 				__lowercase     (				self   :			Optional[int]						):
									_a			,   *_a	: Tuple								=				self.model_tester.prepare_config_and_inputs()
									for alibi in [True, False]:
											_a	: Optional[Any]								=				alibi
											self.model_tester.create_and_check_model(_UpperCAmelCase      ,*_UpperCAmelCase						)







							def 				__lowercase     (				self   :			str						):
									_a			,   _a	: Tuple								=				self.model_tester.prepare_config_and_inputs_for_common()
									_a	: int								=				3
									_a	: Tuple								=				input_dict['input_ids']
									_a	: Union[str, Any]								=				input_ids.ne(1						).to(_UpperCAmelCase						)
									_a	: Tuple								=				ids_tensor([self.model_tester.batch_size]      ,self.model_tester.type_sequence_label_size						)
									_a	: Dict								=				FalconForSequenceClassification(_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: Any								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,labels=_UpperCAmelCase						)
									self.assertEqual(result.logits.shape      ,(self.model_tester.batch_size, self.model_tester.num_labels)						)







							def 				__lowercase     (				self   :			Dict						):
									_a			,   _a	: Dict								=				self.model_tester.prepare_config_and_inputs_for_common()
									_a	: Tuple								=				3
									_a	: Optional[int]								=				'single_label_classification'
									_a	: List[Any]								=				input_dict['input_ids']
									_a	: Any								=				input_ids.ne(1						).to(_UpperCAmelCase						)
									_a	: List[Any]								=				ids_tensor([self.model_tester.batch_size]      ,self.model_tester.type_sequence_label_size						)
									_a	: Union[str, Any]								=				FalconForSequenceClassification(_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: List[Any]								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,labels=_UpperCAmelCase						)
									self.assertEqual(result.logits.shape      ,(self.model_tester.batch_size, self.model_tester.num_labels)						)







							def 				__lowercase     (				self   :			Tuple						):
									_a			,   _a	: Optional[Any]								=				self.model_tester.prepare_config_and_inputs_for_common()
									_a	: Tuple								=				input_dict['input_ids']
									_a	: int								=				FalconForCausalLM(_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: List[Any]								=				model(_UpperCAmelCase      ,use_cache=_UpperCAmelCase						)
									_a	: str								=				input_ids.shape[0]
									_a	: Optional[Any]								=				model._convert_to_rw_cache(result.past_key_values						)
									_a	: Union[str, Any]								=				model._convert_cache_to_standard_format(_UpperCAmelCase      ,_UpperCAmelCase						)
									for layer in range(len(_UpperCAmelCase						)						):
											for tensor_idx in range(2						):
													self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3						)
													self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4						)
													self.assertTrue(
													    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]						)						)







							def 				__lowercase     (				self   :			Optional[Any]						):
									_a			,   _a	: List[Any]								=				self.model_tester.prepare_config_and_inputs_for_common()
									_a	: List[str]								=				3
									_a	: List[Any]								=				'multi_label_classification'
									_a	: List[str]								=				input_dict['input_ids']
									_a	: str								=				input_ids.ne(1						).to(_UpperCAmelCase						)
									_a	: Optional[int]								=				ids_tensor(
									    [self.model_tester.batch_size, config.num_labels]      ,self.model_tester.type_sequence_label_size						).to(torch.float						)
									_a	: Optional[Any]								=				FalconForSequenceClassification(_UpperCAmelCase						)
									model.to(_UpperCAmelCase						)
									model.eval()
									_a	: Optional[int]								=				model(_UpperCAmelCase      ,attention_mask=_UpperCAmelCase      ,labels=_UpperCAmelCase						)
									self.assertEqual(result.logits.shape      ,(self.model_tester.batch_size, self.model_tester.num_labels)						)







							def 				__lowercase     (				self   :			List[Any]						):
									# Falcon can have different numbers of KV-heads than the number of query heads, so we need
									# to override this test to use the right head counts.
									for model_class in self.all_generative_model_classes:
											_a			,   _a	: Dict								=				self.model_tester.prepare_config_and_inputs_for_common()

											# If it doesn't support cache, pass the test
											if not hasattr(_UpperCAmelCase      ,'use_cache'						):
													return

											_a	: List[Any]								=				model_class(_UpperCAmelCase						).to(_UpperCAmelCase						)
											if "use_cache" not in inputs:
													_a	: Any								=				True
											_a	: Dict								=				model(**_UpperCAmelCase						)

											# If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
											if "past_key_values" not in outputs:
													return

											_a	: List[Any]								=				(
											    getattr(_UpperCAmelCase      ,'decoder_layers'      ,_UpperCAmelCase						)
											    or getattr(_UpperCAmelCase      ,'num_decoder_layers'      ,_UpperCAmelCase						)
											    or config.num_hidden_layers
											)
											_a	: List[str]								=				getattr(_UpperCAmelCase      ,'num_kv_heads'      ,config.num_attention_heads						)
											_a	: Optional[Any]								=				getattr(_UpperCAmelCase      ,'d_model'      ,config.hidden_size						)
											_a	: Tuple								=				embed_dim // num_attention_heads

											_a	: Optional[int]								=				outputs['past_key_values']
											self.assertEqual(len(_UpperCAmelCase						)      ,_UpperCAmelCase						)

											_a			,   _a	: Optional[Any]								=				inputs['input_ids'].shape
											for i in range(_UpperCAmelCase						):
													if config.new_decoder_architecture:
															_a	: List[str]								=				config.num_attention_heads
													elif config.multi_query:
															_a	: Tuple								=				1
													self.assertEqual(len(past_kv[0]						)      ,2						)  # K V for the decoder = 2
													self.assertEqual(
													    past_kv[i][0].shape      ,(batch_size, num_attention_heads, seq_length, per_head_embed_dim)						)
													self.assertEqual(
													    past_kv[i][1].shape      ,(batch_size, num_attention_heads, seq_length, per_head_embed_dim)						)

@require_torch
class       __magic_name__		(       unittest.TestCase  ):







							@slow
							def 				__lowercase     (				self   :			Dict						):
									_a	: List[Any]								=				AutoTokenizer.from_pretrained('Rocketknight1/falcon-rw-1b'						)
									_a	: Union[str, Any]								=				FalconForCausalLM.from_pretrained('Rocketknight1/falcon-rw-1b'						)
									model.eval()
									model.to(_UpperCAmelCase						)
									_a	: Tuple								=				tokenizer('My favorite food is'      ,return_tensors='pt'						).to(_UpperCAmelCase						)

									_a	: List[str]								=				(
									    'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
									)

									_a	: Optional[Any]								=				model.generate(**_UpperCAmelCase      ,do_sample=_UpperCAmelCase      ,max_new_tokens=19						)
									_a	: Any								=				tokenizer.batch_decode(_UpperCAmelCase						)[0]

									self.assertEqual(_UpperCAmelCase      ,_UpperCAmelCase						)







							@slow
							def 				__lowercase     (				self   :			Tuple						):
									# The big models are way too big for the CI, so we use tiny random models that resemble their
									# architectures but with much smaller and fewer layers
									for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
											_a	: Any								=				AutoTokenizer.from_pretrained(_UpperCAmelCase						)
											_a	: Union[str, Any]								=				FalconForCausalLM.from_pretrained(_UpperCAmelCase						)
											model.eval()
											model.to(_UpperCAmelCase						)
											_a	: Any								=				tokenizer('My favorite food is'      ,return_tensors='pt'						).to(_UpperCAmelCase						)

											# We just test that these run without errors - the models are randomly initialized
											# and so the actual text outputs will be garbage
											model.generate(**_UpperCAmelCase      ,do_sample=_UpperCAmelCase      ,max_new_tokens=4						)
											model.generate(**_UpperCAmelCase      ,do_sample=_UpperCAmelCase      ,max_new_tokens=4						)
											model.generate(**_UpperCAmelCase      ,num_beams=2      ,max_new_tokens=4						)







							@slow
							def 				__lowercase     (				self   :			Optional[Any]						):
									# The big models are way too big for the CI, so we use tiny random models that resemble their
									# architectures but with much smaller and fewer layers
									with torch.no_grad():
											for repo in [
											    "Rocketknight1/falcon-rw-1b",
											    "Rocketknight1/tiny-random-falcon-7b",
											    "Rocketknight1/tiny-random-falcon-40b",
											]:
													_a	: Any								=				AutoTokenizer.from_pretrained(_UpperCAmelCase						)
													_a	: List[Any]								=				FalconForCausalLM.from_pretrained(_UpperCAmelCase						)
													model.eval()
													model.to(device=_UpperCAmelCase						)
													_a	: Union[str, Any]								=				tokenizer('My favorite food is'      ,return_tensors='pt'						).to(_UpperCAmelCase						)

													# Test results are the same with and without cache
													_a	: str								=				model.generate(**_UpperCAmelCase      ,do_sample=_UpperCAmelCase      ,max_new_tokens=20      ,use_cache=_UpperCAmelCase						)
													_a	: Optional[int]								=				model.generate(**_UpperCAmelCase      ,do_sample=_UpperCAmelCase      ,max_new_tokens=20      ,use_cache=_UpperCAmelCase						)
													self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0						)









'''simple docstring'''

def 	__lowerCamelCase	( lowerCAmelCase_    )     -> bool:
		if not all(x.isalpha() for x in string    ):
				raise ValueError('String must only contain alphabetic characters.'    )

		_a	: Tuple								=				sorted(string.lower()    )
		return len(lowerCAmelCase_    ) == len(set(lowerCAmelCase_    )    )


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

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




