





import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

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


if is_torch_available():
  import torch

  from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
  from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder




def _a (  SCREAMING_SNAKE_CASE__      :  List[str]			,				SCREAMING_SNAKE_CASE__      :  Optional[int]			,				SCREAMING_SNAKE_CASE__      :  Optional[Any]			,				SCREAMING_SNAKE_CASE__      :  int=None			,				SCREAMING_SNAKE_CASE__      :  Any=None			,				SCREAMING_SNAKE_CASE__      :  Optional[int]=None			,				SCREAMING_SNAKE_CASE__      :  Tuple=None			,				SCREAMING_SNAKE_CASE__      :  Optional[Any]=None			,				)	->    Optional[Any]:

       '''simple docstring'''






       if attention_mask is None:
              SCREAMING_SNAKE_CASE__       :      int     =						input_ids.ne(config.pad_token_id       )
       if decoder_attention_mask is None:
              SCREAMING_SNAKE_CASE__       :      int     =						decoder_input_ids.ne(config.pad_token_id       )
       if head_mask is None:
              SCREAMING_SNAKE_CASE__       :      int     =						torch.ones(config.encoder_layers			,				config.encoder_attention_heads			,				device=A__       )
       if decoder_head_mask is None:
              SCREAMING_SNAKE_CASE__       :      int     =						torch.ones(config.decoder_layers			,				config.decoder_attention_heads			,				device=A__       )
       if cross_attn_head_mask is None:
              SCREAMING_SNAKE_CASE__       :      Dict     =						torch.ones(config.decoder_layers			,				config.decoder_attention_heads			,				device=A__       )
       return {
           "input_ids": input_ids,
           "decoder_input_ids": decoder_input_ids,
           "attention_mask": attention_mask,
           "decoder_attention_mask": attention_mask,
           "head_mask": head_mask,
           "decoder_head_mask": decoder_head_mask,
           "cross_attn_head_mask": cross_attn_head_mask,
       }


class 						lowerCamelCase       :







       """simple docstring"""




       def __init__( self     :					Optional[Any],			_UpperCAmelCase     :					str,			_UpperCAmelCase     :					Dict=1_3,			_UpperCAmelCase     :					Dict=7,			_UpperCAmelCase     :					Optional[int]=True,			_UpperCAmelCase     :					Dict=False,			_UpperCAmelCase     :					int=9_9,			_UpperCAmelCase     :					Tuple=1_6,			_UpperCAmelCase     :					str=2,			_UpperCAmelCase     :					List[str]=4,			_UpperCAmelCase     :					Dict=4,			_UpperCAmelCase     :					Optional[Any]="relu",			_UpperCAmelCase     :					str=0.1,			_UpperCAmelCase     :					Union[str, Any]=0.1,			_UpperCAmelCase     :					int=0.0,			_UpperCAmelCase     :					Dict=0.0,			_UpperCAmelCase     :					str=2_0,			_UpperCAmelCase     :					Union[str, Any]=2,			_UpperCAmelCase     :					Tuple=1,			_UpperCAmelCase     :					List[str]=0,			)				->			Optional[int]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						parent
              SCREAMING_SNAKE_CASE__       :      Any     =						batch_size
              SCREAMING_SNAKE_CASE__       :      List[str]     =						seq_length
              SCREAMING_SNAKE_CASE__       :      int     =						is_training
              SCREAMING_SNAKE_CASE__       :      str     =						use_labels
              SCREAMING_SNAKE_CASE__       :      int     =						vocab_size
              SCREAMING_SNAKE_CASE__       :      Dict     =						hidden_size
              SCREAMING_SNAKE_CASE__       :      Any     =						num_hidden_layers
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						num_attention_heads
              SCREAMING_SNAKE_CASE__       :      List[str]     =						intermediate_size
              SCREAMING_SNAKE_CASE__       :      Any     =						hidden_act
              SCREAMING_SNAKE_CASE__       :      List[str]     =						hidden_dropout_prob
              SCREAMING_SNAKE_CASE__       :      int     =						attention_probs_dropout_prob
              SCREAMING_SNAKE_CASE__       :      List[str]     =						encoder_layerdrop
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						decoder_layerdrop
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						max_position_embeddings
              SCREAMING_SNAKE_CASE__       :      int     =						eos_token_id
              SCREAMING_SNAKE_CASE__       :      Dict     =						pad_token_id
              SCREAMING_SNAKE_CASE__       :      Tuple     =						bos_token_id






       def  A_     ( self     :					Optional[int]						)				->			Optional[Any]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Tuple     =						ids_tensor([self.batch_size, self.seq_length],			self.vocab_size						)
              SCREAMING_SNAKE_CASE__       :      int     =						self.eos_token_id  # Eos Token
              SCREAMING_SNAKE_CASE__       :      List[str]     =						ids_tensor([self.batch_size, self.seq_length],			self.vocab_size						)

              # we need to clamp the input ids here to avoid having pad token in between
              # this is because for M2M100 the position_ids are prepared such that
              # all pad tokens have pos id = 2 and rest are between 2..seq_length
              # and the seq_length here is seq_length - num_pad_tokens
              # but when using past, there is no way of knowing if the past input ids had
              # pad tokens in them, which results in incorrect seq_lenth and which in turn results in
              # position_ids being off by num_pad_tokens in past input
              SCREAMING_SNAKE_CASE__       :      str     =						input_ids.clamp(self.pad_token_id + 1						)
              SCREAMING_SNAKE_CASE__       :      str     =						decoder_input_ids.clamp(self.pad_token_id + 1						)

              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						self.get_config()
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						prepare_mam_aaa_inputs_dict(lowercase__,			lowercase__,			lowercase__						)
              return config, inputs_dict






       def  A_     ( self     :					Optional[Any]						)				->			Optional[Any]:





              """simple docstring"""
              return MaMaaaConfig(
                  vocab_size=self.vocab_size,			d_model=self.hidden_size,			encoder_layers=self.num_hidden_layers,			decoder_layers=self.num_hidden_layers,			encoder_attention_heads=self.num_attention_heads,			decoder_attention_heads=self.num_attention_heads,			encoder_ffn_dim=self.intermediate_size,			decoder_ffn_dim=self.intermediate_size,			dropout=self.hidden_dropout_prob,			attention_dropout=self.attention_probs_dropout_prob,			encoder_layerdrop=self.encoder_layerdrop,			decoder_layerdrop=self.decoder_layerdrop,			max_position_embeddings=self.max_position_embeddings,			eos_token_id=self.eos_token_id,			bos_token_id=self.bos_token_id,			pad_token_id=self.pad_token_id,			)






       def  A_     ( self     :					Optional[int]						)				->			Any:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						self.prepare_config_and_inputs()
              return config, inputs_dict






       def  A_     ( self     :					Tuple,			_UpperCAmelCase     :					Optional[Any],			_UpperCAmelCase     :					Any						)				->			Optional[int]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      int     =						MaMaaaModel(config=lowercase__						).get_decoder().to(lowercase__						).eval()
              SCREAMING_SNAKE_CASE__       :      int     =						inputs_dict["input_ids"]
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						inputs_dict["attention_mask"]
              SCREAMING_SNAKE_CASE__       :      int     =						inputs_dict["head_mask"]

              # first forward pass
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						model(lowercase__,			attention_mask=lowercase__,			head_mask=lowercase__,			use_cache=lowercase__						)

              SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      str     =						outputs.to_tuple()

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

              # append to next input_ids and
              SCREAMING_SNAKE_CASE__       :      str     =						torch.cat([input_ids, next_tokens],			dim=-1						)
              SCREAMING_SNAKE_CASE__       :      Dict     =						torch.cat([attention_mask, next_attn_mask],			dim=-1						)

              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model(lowercase__,			attention_mask=lowercase__						)["last_hidden_state"]
              SCREAMING_SNAKE_CASE__       :      Dict     =						model(lowercase__,			attention_mask=lowercase__,			past_key_values=lowercase__						)[
                  "last_hidden_state"
              ]

              # select random slice
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						ids_tensor((1,),			output_from_past.shape[-1]						).item()
              SCREAMING_SNAKE_CASE__       :      Tuple     =						output_from_no_past[:, -3:, random_slice_idx].detach()
              SCREAMING_SNAKE_CASE__       :      str     =						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(lowercase__,			lowercase__,			atol=1E-2						)						)






       def  A_     ( self     :					List[Any],			_UpperCAmelCase     :					Any,			_UpperCAmelCase     :					Optional[Any]						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Tuple     =						MaMaaaModel(config=lowercase__						).to(lowercase__						).eval()
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						model(**lowercase__						)

              SCREAMING_SNAKE_CASE__       :      Dict     =						outputs.encoder_last_hidden_state
              SCREAMING_SNAKE_CASE__       :      Tuple     =						outputs.last_hidden_state

              with tempfile.TemporaryDirectory() as tmpdirname:
                     SCREAMING_SNAKE_CASE__       :      Any     =						model.get_encoder()
                     encoder.save_pretrained(lowercase__						)
                     SCREAMING_SNAKE_CASE__       :      Dict     =						MaMaaaEncoder.from_pretrained(lowercase__						).to(lowercase__						)

              SCREAMING_SNAKE_CASE__       :      int     =						encoder(inputs_dict["input_ids"],			attention_mask=inputs_dict["attention_mask"]						)[
                  0
              ]

              self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3						)

              with tempfile.TemporaryDirectory() as tmpdirname:
                     SCREAMING_SNAKE_CASE__       :      Tuple     =						model.get_decoder()
                     decoder.save_pretrained(lowercase__						)
                     SCREAMING_SNAKE_CASE__       :      List[Any]     =						MaMaaaDecoder.from_pretrained(lowercase__						).to(lowercase__						)

              SCREAMING_SNAKE_CASE__       :      Tuple     =						decoder(
                  input_ids=inputs_dict["decoder_input_ids"],			attention_mask=inputs_dict["decoder_attention_mask"],			encoder_hidden_states=lowercase__,			encoder_attention_mask=inputs_dict["attention_mask"],			)[0]

              self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3						)


@require_torch
class 						lowerCamelCase       (lowerCamelCase__							,     lowerCamelCase__							,     lowerCamelCase__							,     unittest.TestCase      ):







       """simple docstring"""




       UpperCAmelCase_      						=   (
           (
               MaMaaaModel,
               MaMaaaForConditionalGeneration,
           )
           if is_torch_available()
           else ()
       )
       UpperCAmelCase_      						=   (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
       UpperCAmelCase_      						=   (
           {
               'conversational': MaMaaaForConditionalGeneration,
               'feature-extraction': MaMaaaModel,
               'summarization': MaMaaaForConditionalGeneration,
               'text2text-generation': MaMaaaForConditionalGeneration,
               'translation': MaMaaaForConditionalGeneration,
           }
           if is_torch_available()
           else {}
       )
       UpperCAmelCase_      						=   True
       UpperCAmelCase_      						=   True
       UpperCAmelCase_      						=   False
       UpperCAmelCase_      						=   False






       def  A_     ( self     :					Optional[Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					str,			_UpperCAmelCase     :					List[str],			_UpperCAmelCase     :					Optional[int],			_UpperCAmelCase     :					str						)				->			Union[str, Any]:





              """simple docstring"""
              if pipeline_test_casse_name == "TranslationPipelineTests":
                     # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
                     # `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
                     return True

              return False






       def  A_     ( self     :					List[str]						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Dict     =						MaMaaaModelTester(self						)
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						ConfigTester(self,			config_class=lowercase__						)






       def  A_     ( self     :					List[Any]						)				->			str:





              """simple docstring"""
              self.config_tester.run_common_tests()






       def  A_     ( self     :					Union[str, Any]						)				->			List[str]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Tuple     =						self.model_tester.prepare_config_and_inputs()
              for model_class in self.all_model_classes:
                     SCREAMING_SNAKE_CASE__       :      Any     =						model_class(lowercase__						)

                     with tempfile.TemporaryDirectory() as tmpdirname:
                            model.save_pretrained(lowercase__						)
                            SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      int     =						model_class.from_pretrained(lowercase__,			output_loading_info=lowercase__						)
                     self.assertEqual(info["missing_keys"],			[]						)






       def  A_     ( self     :					str						)				->			Dict:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      int     =						self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowercase__						)






       def  A_     ( self     :					Dict						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self.model_tester.prepare_config_and_inputs_for_common()
              self.model_tester.check_encoder_decoder_model_standalone(*lowercase__						)






       def  A_     ( self     :					Any						)				->			Tuple:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Any     =						self.model_tester.prepare_config_and_inputs_for_common()

              for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
                     SCREAMING_SNAKE_CASE__       :      Tuple     =						model_class(lowercase__						)
                     model.to(lowercase__						)
                     model.eval()

                     SCREAMING_SNAKE_CASE__       :      List[Any]     =						copy.deepcopy(self._prepare_for_class(lowercase__,			lowercase__						)						)

                     if not self.is_encoder_decoder:
                            SCREAMING_SNAKE_CASE__       :      str     =						inputs["input_ids"]
                            del inputs["input_ids"]
                     else:
                            SCREAMING_SNAKE_CASE__       :      str     =						inputs["input_ids"]
                            SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						inputs.get("decoder_input_ids",			lowercase__						)
                            del inputs["input_ids"]
                            inputs.pop("decoder_input_ids",			lowercase__						)

                     SCREAMING_SNAKE_CASE__       :      Dict     =						model.get_input_embeddings()
                     if not self.is_encoder_decoder:
                            SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						wte(lowercase__						)
                     else:
                            SCREAMING_SNAKE_CASE__       :      List[str]     =						wte(lowercase__						)
                            SCREAMING_SNAKE_CASE__       :      List[str]     =						wte(lowercase__						)

                     with torch.no_grad():
                            model(**lowercase__						)[0]






       def  A_     ( self     :					int						)				->			int:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      str     =						self.model_tester.prepare_config_and_inputs()
              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						input_dict["input_ids"]
              SCREAMING_SNAKE_CASE__       :      int     =						input_ids.ne(1						).to(lowercase__						)
              SCREAMING_SNAKE_CASE__       :      Dict     =						MaMaaaForConditionalGeneration(lowercase__						).eval().to(lowercase__						)
              if torch_device == "cuda":
                     model.half()
              model.generate(lowercase__,			attention_mask=lowercase__						)
              model.generate(num_beams=4,			do_sample=lowercase__,			early_stopping=lowercase__,			num_return_sequences=3						)




def _a (  SCREAMING_SNAKE_CASE__      :  Optional[int]       )	->    List[str]:

       '''simple docstring'''






       return torch.tensor(A__			,				dtype=torch.long			,				device=A__       )


_lowerCamelCase :    int  							= 1e-4







@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class 						lowerCamelCase       (unittest.TestCase      ):







       """simple docstring"""




       @cached_property
       def  A_     ( self     :					List[Any]						)				->			Optional[int]:





              """simple docstring"""
              return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"						)






       def  A_     ( self     :					Optional[int]						)				->			Dict:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						MaMaaaModel.from_pretrained("facebook/m2m100_418M"						).to(lowercase__						)
              SCREAMING_SNAKE_CASE__       :      str     =						_long_tensor([[1_2_8_0_2_8, 9_8, 1_2, 3_0_5_2_7, 2_7_3_2, 1_5_9, 7_7_5_5, 6_1_9_0_4, 3_9_1_4_4, 3_8, 2]]						)
              SCREAMING_SNAKE_CASE__       :      str     =						_long_tensor([[2, 1_2_8_0_2_8, 9_8, 1_2, 3_0_5_2_7, 2_7_3_2, 1_5_9, 7_7_5_5, 6_1_9_0_4, 3_9_1_4_4, 3_8]]						)
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						prepare_mam_aaa_inputs_dict(model.config,			lowercase__,			lowercase__						)
              with torch.no_grad():
                     SCREAMING_SNAKE_CASE__       :      int     =						model(**lowercase__						)[0]
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						torch.Size((1, 1_1, 1_0_2_4)						)
              self.assertEqual(output.shape,			lowercase__						)
              # change to expected output here
              SCREAMING_SNAKE_CASE__       :      List[str]     =						torch.tensor(
                  [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]],			device=lowercase__						)
              self.assertTrue(torch.allclose(output[:, :3, :3],			lowercase__,			atol=lowercase__						)						)






       def  A_     ( self     :					Union[str, Any]						)				->			Union[str, Any]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"						).to(lowercase__						)

              # change to intended input
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						_long_tensor([[1_2_8_0_2_8, 9_8, 1_2, 3_0_5_2_7, 2_7_3_2, 1_5_9, 7_7_5_5, 6_1_9_0_4, 3_9_1_4_4, 3_8, 2]]						)
              SCREAMING_SNAKE_CASE__       :      Tuple     =						_long_tensor([[2, 1_2_8_0_2_8, 9_8, 1_2, 3_0_5_2_7, 2_7_3_2, 1_5_9, 7_7_5_5, 6_1_9_0_4, 3_9_1_4_4, 3_8]]						)
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						prepare_mam_aaa_inputs_dict(model.config,			lowercase__,			lowercase__						)
              with torch.no_grad():
                     SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model(**lowercase__						)[0]
              SCREAMING_SNAKE_CASE__       :      int     =						torch.Size((1, 1_1, model.config.vocab_size)						)
              self.assertEqual(output.shape,			lowercase__						)
              # change to expected output here
              SCREAMING_SNAKE_CASE__       :      str     =						torch.tensor(
                  [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]],			device=lowercase__						)
              self.assertTrue(torch.allclose(output[:, :3, :3],			lowercase__,			atol=lowercase__						)						)






       def  A_     ( self     :					Union[str, Any]						)				->			List[str]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      List[Any]     =						MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"						).to(lowercase__						)
              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M",			src_lang="fr",			tgt_lang="en"						)

              SCREAMING_SNAKE_CASE__       :      str     =						[
                  "L\'affaire NSA souligne l\'absence totale de débat sur le renseignement",
                  "Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.",
                  "Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"
                  " Fabius convoque l\'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"
                  " l\'ampleur de la surveillance américaine sur l\'ensemble des communications en France.",
              ]

              # The below article tests that we don't add any hypotheses outside of the top n_beams
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						tokenizer(lowercase__,			padding=lowercase__,			return_tensors="pt"						)

              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model.generate(
                  input_ids=dct["input_ids"].to(lowercase__						),			attention_mask=dct["attention_mask"].to(lowercase__						),			num_beams=5,			forced_bos_token_id=tokenizer.get_lang_id("en"						),			)

              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						[
                  "The NSA case highlights the total absence of intelligence debate",
                  "I think there are two levels of response from the French government.",
                  "When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."
                  " Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"
                  " communications in France.",
              ]

              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						tokenizer.batch_decode(
                  hypotheses_batch.tolist(),			clean_up_tokenization_spaces=lowercase__,			skip_special_tokens=lowercase__						)
              assert generated == expected_en













def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    str:

							'''simple docstring'''






							if not all(char in "01" for char in bin_string       ):
														raise ValueError("Non-binary value was passed to the function"       )
							if not bin_string:
														raise ValueError("Empty string was passed to the function"       )
							SCREAMING_SNAKE_CASE__       :      List[Any]     =						""
							while len(SCREAMING_SNAKE_CASE__       ) % 3 != 0:
														SCREAMING_SNAKE_CASE__       :      str     =						"0" + bin_string
							SCREAMING_SNAKE_CASE__       :      List[Any]     =						[
							    bin_string[index : index + 3]
							    for index in range(len(SCREAMING_SNAKE_CASE__       )       )
							    if index % 3 == 0
							]
							for bin_group in bin_string_in_3_list:
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						0
														for index, val in enumerate(SCREAMING_SNAKE_CASE__       ):
																					oct_val += int(2 ** (2 - index) * int(SCREAMING_SNAKE_CASE__       )       )
														oct_string += str(SCREAMING_SNAKE_CASE__       )
							return oct_string


if __name__ == "__main__":
		from doctest import testmod

		testmod()






