from transformers import BertTokenizer, EncoderDecoderModel, SeqaSeqTrainer, SeqaSeqTrainingArguments
from transformers.testing_utils import TestCasePlus, require_torch, slow
from transformers.utils import is_datasets_available


if is_datasets_available():
    import datasets


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    @slow
    @require_torch
    def 			UpperCamelCase__   (	self)       ->	str:
        __UpperCamelCase     :Tuple			  =		EncoderDecoderModel.from_encoder_decoder_pretrained('''prajjwal1/bert-tiny''' , '''prajjwal1/bert-tiny''')
        __UpperCamelCase     :Tuple			  =		BertTokenizer.from_pretrained('''bert-base-uncased''')

        __UpperCamelCase     :Optional[int]			  =		bertabert.config.encoder.vocab_size
        __UpperCamelCase     :Optional[int]			  =		tokenizer.sep_token_id
        __UpperCamelCase     :str			  =		tokenizer.cls_token_id
        __UpperCamelCase     :Any			  =		128

        __UpperCamelCase     :Any			  =		datasets.load_dataset('''cnn_dailymail''' , '''3.0.0''' , split='''train[:1%]''')
        __UpperCamelCase     :Any			  =		datasets.load_dataset('''cnn_dailymail''' , '''3.0.0''' , split='''validation[:1%]''')

        __UpperCamelCase     :Optional[int]			  =		train_dataset.select(range(32))
        __UpperCamelCase     :List[str]			  =		val_dataset.select(range(16))

        __UpperCamelCase     :str			  =		4

        def _map_to_encoder_decoder_inputs(__lowercase):
            # Tokenizer will automatically set [BOS] <text> [EOS]
            __UpperCamelCase     :List[str]			  =		tokenizer(batch['''article'''] , padding='''max_length''' , truncation=__a , max_length=512)
            __UpperCamelCase     :Any			  =		tokenizer(batch['''highlights'''] , padding='''max_length''' , truncation=__a , max_length=128)
            __UpperCamelCase     :Any			  =		inputs.input_ids
            __UpperCamelCase     :Any			  =		inputs.attention_mask

            __UpperCamelCase     :Any			  =		outputs.input_ids
            __UpperCamelCase     :Optional[int]			  =		outputs.input_ids.copy()
            __UpperCamelCase     :Any			  =		[
                [-100 if token == tokenizer.pad_token_id else token for token in labels] for labels in batch['''labels''']
            ]
            __UpperCamelCase     :Union[str, Any]			  =		outputs.attention_mask

            assert all(len(__a) == 512 for x in inputs.input_ids)
            assert all(len(__a) == 128 for x in outputs.input_ids)

            return batch

        def _compute_metrics(__lowercase):
            __UpperCamelCase     :Optional[Any]			  =		pred.label_ids
            __UpperCamelCase     :Union[str, Any]			  =		pred.predictions

            # all unnecessary tokens are removed
            __UpperCamelCase     :Optional[Any]			  =		tokenizer.batch_decode(__a , skip_special_tokens=__a)
            __UpperCamelCase     :str			  =		tokenizer.batch_decode(__a , skip_special_tokens=__a)

            __UpperCamelCase     :str			  =		sum([int(pred_str[i] == label_str[i]) for i in range(len(__a))]) / len(__a)

            return {"accuracy": accuracy}

        # map train dataset
        __UpperCamelCase     :List[Any]			  =		train_dataset.map(
            _map_to_encoder_decoder_inputs , batched=__a , batch_size=__a , remove_columns=['''article''', '''highlights'''] , )
        train_dataset.set_format(
            type='''torch''' , columns=['''input_ids''', '''attention_mask''', '''decoder_input_ids''', '''decoder_attention_mask''', '''labels'''] , )

        # same for validation dataset
        __UpperCamelCase     :int			  =		val_dataset.map(
            _map_to_encoder_decoder_inputs , batched=__a , batch_size=__a , remove_columns=['''article''', '''highlights'''] , )
        val_dataset.set_format(
            type='''torch''' , columns=['''input_ids''', '''attention_mask''', '''decoder_input_ids''', '''decoder_attention_mask''', '''labels'''] , )

        __UpperCamelCase     :Any			  =		self.get_auto_remove_tmp_dir()

        __UpperCamelCase     :Optional[int]			  =		SeqaSeqTrainingArguments(
            output_dir=__a , per_device_train_batch_size=__a , per_device_eval_batch_size=__a , predict_with_generate=__a , evaluation_strategy='''steps''' , do_train=__a , do_eval=__a , warmup_steps=0 , eval_steps=2 , logging_steps=2 , )

        # instantiate trainer
        __UpperCamelCase     :Optional[Any]			  =		SeqaSeqTrainer(
            model=__a , args=__a , compute_metrics=_compute_metrics , train_dataset=__a , eval_dataset=__a , tokenizer=__a , )

        # start training
        trainer.train()







"""simple docstring"""





def       lowerCamelCase__		(			__snake_case = 10_00	)							->		int:


					"""simple docstring"""





					_UpperCamelCase							 =  2**power
					_UpperCamelCase							 =  str(__snake_case	)
					_UpperCamelCase							 =  list(__snake_case	)
					_UpperCamelCase							 =  0

					for i in list_num:
										sum_of_num += int(__snake_case	)

					return sum_of_num


if __name__ == "__main__":
				_a														=		int(input("""Enter the power of 2: """).strip())
				print("""2 ^ """, power, """ = """, 2**power)
				_a														=		solution(power)
				print("""Sum of the digits is: """, result)






