






from __future__ import annotations

import unittest

from transformers import AutoTokenizer, GPTJConfig, is_tf_available
from transformers.testing_utils import require_tf, slow, tooslow

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


if is_tf_available():
					import tensorflow as tf

					from transformers.models.gptj.modeling_tf_gptj import (
					    TFGPTJForCausalLM,
					    TFGPTJForQuestionAnswering,
					    TFGPTJForSequenceClassification,
					    TFGPTJModel,
					    shape_list,
					)


class      __SCREAMING_SNAKE_CASE       :






						def __init__(						self  ,    _UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    parent
												lowerCAmelCase__         =    13
												lowerCAmelCase__         =    7
												lowerCAmelCase__         =    True
												lowerCAmelCase__         =    True
												lowerCAmelCase__         =    True
												lowerCAmelCase__         =    True
												lowerCAmelCase__         =    True
												lowerCAmelCase__         =    99
												lowerCAmelCase__         =    32
												lowerCAmelCase__         =    4
												lowerCAmelCase__         =    2
												lowerCAmelCase__         =    4
												lowerCAmelCase__         =    37
												lowerCAmelCase__         =    'gelu'
												lowerCAmelCase__         =    0.1
												lowerCAmelCase__         =    0.1
												lowerCAmelCase__         =    5_12
												lowerCAmelCase__         =    16
												lowerCAmelCase__         =    2
												lowerCAmelCase__         =    0.02
												lowerCAmelCase__         =    3
												lowerCAmelCase__         =    4
												lowerCAmelCase__         =    None
												lowerCAmelCase__         =    self.vocab_size - 1
												lowerCAmelCase__         =    self.vocab_size - 1
												lowerCAmelCase__         =    self.vocab_size - 1






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ids_tensor([self.batch_size, self.seq_length]  ,    self.vocab_size )

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

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

												lowerCAmelCase__         =    None
												if self.use_mc_token_ids:
																		lowerCAmelCase__         =    ids_tensor([self.batch_size, self.num_choices]  ,    self.seq_length )

												lowerCAmelCase__         =    None
												lowerCAmelCase__         =    None
												lowerCAmelCase__         =    None
												if self.use_labels:
																		lowerCAmelCase__         =    ids_tensor([self.batch_size]  ,    self.type_sequence_label_size )
																		lowerCAmelCase__         =    ids_tensor([self.batch_size, self.seq_length]  ,    self.num_labels )
																		lowerCAmelCase__         =    ids_tensor([self.batch_size]  ,    self.num_choices )

												lowerCAmelCase__         =    GPTJConfig(
												    vocab_size=self.vocab_size  ,    n_embd=self.hidden_size  ,    n_layer=self.num_hidden_layers  ,    n_head=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  ,    n_positions=self.max_position_embeddings  ,    type_vocab_size=self.type_vocab_size  ,    initializer_range=self.initializer_range  ,    bos_token_id=self.bos_token_id  ,    eos_token_id=self.eos_token_id  ,    pad_token_id=self.pad_token_id  ,    rotary_dim=self.rotary_dim  ,    return_dict=_lowercase  ,    )

												lowerCAmelCase__         =    ids_tensor([self.num_hidden_layers, self.num_attention_heads]  ,    2 )

												return (
												    config,
												    input_ids,
												    input_mask,
												    head_mask,
												    token_type_ids,
												    mc_token_ids,
												    sequence_labels,
												    token_labels,
												    choice_labels,
												)






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    *_UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModel(config=_lowercase )
												lowerCAmelCase__         =    {
												    'input_ids': input_ids,
												    'attention_mask': input_mask,
												    'token_type_ids': token_type_ids,
												}
												lowerCAmelCase__         =    model(_lowercase )

												lowerCAmelCase__         =    [input_ids, None, input_mask]  # None is the input for 'past'
												lowerCAmelCase__         =    model(_lowercase )

												lowerCAmelCase__         =    model(_lowercase )

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






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    *_UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModel(config=_lowercase )

												# first forward pass
												lowerCAmelCase__         =    model(_lowercase  ,    token_type_ids=_lowercase  ,    use_cache=_lowercase )
												lowerCAmelCase__         =    model(_lowercase  ,    token_type_ids=_lowercase )
												lowerCAmelCase__         =    model(_lowercase  ,    token_type_ids=_lowercase  ,    use_cache=_lowercase )

												self.parent.assertTrue(len(_lowercase ) == len(_lowercase ) )
												self.parent.assertTrue(len(_lowercase ) == len(_lowercase ) + 1 )

												lowerCAmelCase__    ,							lowerCAmelCase__         =    outputs.to_tuple()

												# create hypothetical next token and extent to next_input_ids
												lowerCAmelCase__         =    ids_tensor((self.batch_size, 1)  ,    config.vocab_size )
												lowerCAmelCase__         =    ids_tensor([self.batch_size, 1]  ,    self.type_vocab_size )

												# append to next input_ids and token_type_ids
												lowerCAmelCase__         =    tf.concat([input_ids, next_tokens]  ,    axis=-1 )
												lowerCAmelCase__         =    tf.concat([token_type_ids, next_token_types]  ,    axis=-1 )

												lowerCAmelCase__         =    model(_lowercase  ,    token_type_ids=_lowercase )['last_hidden_state']
												lowerCAmelCase__         =    model(_lowercase  ,    token_type_ids=_lowercase  ,    past_key_values=_lowercase )[
												    'last_hidden_state'
												]

												# select random slice
												lowerCAmelCase__         =    int(ids_tensor((1,)  ,    shape_list(_lowercase )[-1] ) )
												lowerCAmelCase__         =    output_from_no_past[:, -1, random_slice_idx]
												lowerCAmelCase__         =    output_from_past[:, 0, random_slice_idx]

												# test that outputs are equal for slice
												tf.debugging.assert_near(_lowercase  ,    _lowercase  ,    rtol=1E-6 )






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    *_UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModel(config=_lowercase )

												# create attention mask
												lowerCAmelCase__         =    self.seq_length // 2
												lowerCAmelCase__         =    tf.ones((self.batch_size, half_seq_length)  ,    dtype=tf.intaa )
												lowerCAmelCase__         =    tf.zeros((self.batch_size, self.seq_length - half_seq_length)  ,    dtype=tf.intaa )
												lowerCAmelCase__         =    tf.concat([attn_mask_begin, attn_mask_end]  ,    axis=1 )

												# first forward pass
												lowerCAmelCase__    ,							lowerCAmelCase__         =    model(_lowercase  ,    attention_mask=_lowercase ).to_tuple()

												# create hypothetical next token and extent to next_input_ids
												lowerCAmelCase__         =    ids_tensor((self.batch_size, 1)  ,    config.vocab_size )

												# change a random masked slice from input_ids
												lowerCAmelCase__         =    ids_tensor((1,)  ,    _lowercase ).numpy() + 1
												lowerCAmelCase__         =    ids_tensor((self.batch_size, self.seq_length)  ,    config.vocab_size )
												lowerCAmelCase__         =    tf.range(self.seq_length ) == (self.seq_length - random_seq_idx_to_change)
												lowerCAmelCase__         =    tf.transpose(
												    tf.broadcast_to(tf.expand_dims(_lowercase  ,    -1 )  ,    (self.seq_length, self.batch_size) ) )
												lowerCAmelCase__         =    tf.where(_lowercase  ,    _lowercase  ,    _lowercase )

												# append to next input_ids and attn_mask
												lowerCAmelCase__         =    tf.concat([input_ids, next_tokens]  ,    axis=-1 )
												lowerCAmelCase__         =    tf.concat([attn_mask, tf.ones((shape_list(_lowercase )[0], 1)  ,    dtype=tf.intaa )]  ,    axis=1 )

												# get two different outputs
												lowerCAmelCase__         =    model(_lowercase  ,    attention_mask=_lowercase )['last_hidden_state']
												lowerCAmelCase__         =    model(_lowercase  ,    past_key_values=_lowercase  ,    attention_mask=_lowercase )[
												    'last_hidden_state'
												]

												# select random slice
												lowerCAmelCase__         =    int(ids_tensor((1,)  ,    shape_list(_lowercase )[-1] ) )
												lowerCAmelCase__         =    output_from_no_past[:, -1, random_slice_idx]
												lowerCAmelCase__         =    output_from_past[:, 0, random_slice_idx]

												# test that outputs are equal for slice
												tf.debugging.assert_near(_lowercase  ,    _lowercase  ,    rtol=1E-12 )






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    *_UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModel(config=_lowercase )

												lowerCAmelCase__         =    input_ids[:1, :]
												lowerCAmelCase__         =    input_mask[:1, :]
												lowerCAmelCase__         =    token_type_ids[:1, :]
												lowerCAmelCase__         =    1

												# first forward pass
												lowerCAmelCase__         =    model(_lowercase  ,    attention_mask=_lowercase  ,    token_type_ids=_lowercase  ,    use_cache=_lowercase )

												lowerCAmelCase__    ,							lowerCAmelCase__         =    outputs.to_tuple()

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

												# append to next input_ids and token_type_ids
												lowerCAmelCase__         =    tf.concat([input_ids, next_tokens]  ,    axis=-1 )
												lowerCAmelCase__         =    tf.concat([input_mask, next_attn_mask]  ,    axis=-1 )
												lowerCAmelCase__         =    tf.concat([token_type_ids, next_token_types]  ,    axis=-1 )

												lowerCAmelCase__         =    model(
												    _lowercase  ,    token_type_ids=_lowercase  ,    attention_mask=_lowercase )['last_hidden_state']
												lowerCAmelCase__         =    model(
												    _lowercase  ,    token_type_ids=_lowercase  ,    attention_mask=_lowercase  ,    past_key_values=_lowercase  ,    )['last_hidden_state']
												self.parent.assertTrue(output_from_past.shape[1] == next_tokens.shape[1] )

												# select random slice
												lowerCAmelCase__         =    int(ids_tensor((1,)  ,    shape_list(_lowercase )[-1] ) )
												lowerCAmelCase__         =    output_from_no_past[:, -3:, random_slice_idx]
												lowerCAmelCase__         =    output_from_past[:, :, random_slice_idx]

												# test that outputs are equal for slice
												tf.debugging.assert_near(_lowercase  ,    _lowercase  ,    rtol=1E-3 )






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    *_UpperCamelCase ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJForCausalLM(config=_lowercase )
												lowerCAmelCase__         =    {
												    'input_ids': input_ids,
												    'attention_mask': input_mask,
												    'token_type_ids': token_type_ids,
												}
												lowerCAmelCase__         =    model(_lowercase )
												self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.seq_length, self.vocab_size) )







						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.prepare_config_and_inputs()

												(
												    (
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,							(
												    lowerCAmelCase__	
												)    ,								
												)         =    config_and_inputs

												lowerCAmelCase__         =    {
												    'input_ids': input_ids,
												    'token_type_ids': token_type_ids,
												    'attention_mask': input_mask,
												}
												return config, inputs_dict




@require_tf
class      __SCREAMING_SNAKE_CASE       ( lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       unittest.TestCase):
						_SCREAMING_SNAKE_CASE						:							Tuple				=       (
						    (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
						    if is_tf_available()
						    else ()
						)

						_SCREAMING_SNAKE_CASE						:							Dict				=       (TFGPTJForCausalLM,) if is_tf_available() else ()
						_SCREAMING_SNAKE_CASE						:							Dict				=       (
						    {
						        '''feature-extraction''': TFGPTJModel,
						        '''question-answering''': TFGPTJForQuestionAnswering,
						        '''text-classification''': TFGPTJForSequenceClassification,
						        '''text-generation''': TFGPTJForCausalLM,
						        '''zero-shot''': TFGPTJForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						_SCREAMING_SNAKE_CASE						:							int				=       False
						_SCREAMING_SNAKE_CASE						:							Optional[Any]				=       False
						_SCREAMING_SNAKE_CASE						:							Optional[Any]				=       False
						_SCREAMING_SNAKE_CASE						:							Optional[int]				=       False






						def    UpperCamelCase__   (						self  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase  ,    _UpperCamelCase ):






												"""simple docstring"""






												if (
												    pipeline_test_casse_name == "QAPipelineTests"
												    and tokenizer_name is not None
												    and not tokenizer_name.endswith('Fast' )
												):
																		# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
																		# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
																		# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
																		return True

												return False






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModelTester(self )
												lowerCAmelCase__         =    ConfigTester(self  ,    config_class=_lowercase  ,    n_embd=37 )






						def    UpperCamelCase__   (						self ):






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






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_gptj_model(*_lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_gptj_model_past(*_lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_gptj_model_attention_mask_past(*_lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_gptj_model_past_large_inputs(*_lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_gptj_lm_head_model(*_lowercase )






						@slow
						@unittest.skipIf(
						    not is_tf_available() or len(tf.config.list_physical_devices('GPU' ) ) > 0  ,    'skip testing on GPU for now to avoid GPU OOM.'  ,    )
						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJModel.from_pretrained('EleutherAI/gpt-j-6B'  ,    from_pt=_lowercase )
												self.assertIsNotNone(_lowercase )







						@unittest.skip(reason='Currently, model embeddings are going to undergo a major refactor.' )
						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												super().test_resize_token_embeddings()




@require_tf
@tooslow
# Marked as @tooslow due to GPU OOM -- but still useful to run locally. Requires ~39GB of RAM.
class      __SCREAMING_SNAKE_CASE       ( unittest.TestCase):






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'  ,    from_pt=_lowercase )
												lowerCAmelCase__         =    tf.convert_to_tensor([[4_64, 32_90]]  ,    dtype=tf.intaa )  # The dog
												# fmt: off
												# The dog is a man's best friend. It is a loyal companion, and it is a friend
												lowerCAmelCase__         =    [4_64, 32_90, 3_18, 2_57, 5_82, 3_38, 12_66, 15_45, 13, 6_32, 3_18, 2_57, 91_12, 1_51_85, 11, 2_90, 3_40, 3_18, 2_57, 15_45]
												# fmt: on
												lowerCAmelCase__         =    model.generate(_lowercase  ,    do_sample=_lowercase )
												self.assertListEqual(output_ids[0].numpy().tolist()  ,    _lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'  ,    revision='float16' )
												lowerCAmelCase__         =    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'  ,    revision='float16'  ,    from_pt=_lowercase )

												lowerCAmelCase__         =    tokenizer('Today is a nice day and'  ,    return_tensors='tf' )
												# forces the generation to happen on CPU, to avoid GPU-related quirks
												with tf.device(':/CPU:0' ):
																		lowerCAmelCase__         =    model.generate(**_lowercase  ,    do_sample=_lowercase  ,    seed=[42, 0] )
												lowerCAmelCase__         =    tokenizer.decode(output_ids[0]  ,    skip_special_tokens=_lowercase )

												lowerCAmelCase__         =    'Today is a nice day and I’m going to go for a walk. I’'
												self.assertEqual(_lowercase  ,    _lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'  ,    revision='float16'  ,    from_pt=_lowercase )
												lowerCAmelCase__         =    AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'  ,    revision='float16' )

												lowerCAmelCase__         =    'left'

												# Define PAD Token = EOS Token = 50256
												lowerCAmelCase__         =    tokenizer.eos_token
												lowerCAmelCase__         =    model.config.eos_token_id

												# use different length sentences to test batching
												lowerCAmelCase__         =    [
												    'Hello, my dog is a little',
												    'Today, I',
												]
												lowerCAmelCase__         =    [
												    'Hello, my dog is a little over a year old and has been diagnosed with hip dysplasia',
												    'Today, I’m going to be talking about a topic that’',
												]
												return model, tokenizer, sentences, expected_output_sentences






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__         =    self._get_beam_search_test_objects()

												lowerCAmelCase__         =    tokenizer(_lowercase  ,    return_tensors='tf'  ,    padding=_lowercase )
												lowerCAmelCase__         =    model.generate(**_lowercase  ,    do_sample=_lowercase  ,    num_beams=2 )
												lowerCAmelCase__         =    tokenizer.batch_decode(_lowercase  ,    skip_special_tokens=_lowercase )
												self.assertListEqual(_lowercase  ,    _lowercase )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__         =    self._get_beam_search_test_objects()

												lowerCAmelCase__         =    tokenizer(_lowercase  ,    return_tensors='tf'  ,    padding=_lowercase )
												lowerCAmelCase__         =    tokenizer(sentences[0]  ,    return_tensors='tf' )
												lowerCAmelCase__         =    model.generate(**_lowercase  ,    do_sample=_lowercase  ,    num_beams=2 )
												lowerCAmelCase__         =    (
												    shape_list(inputs_non_padded['input_ids'] )[-1]
												    - tf.reduce_sum(tf.cast(inputs['attention_mask'][-1]  ,    tf.intaa ) ).numpy()
												)
												lowerCAmelCase__         =    tokenizer(sentences[1]  ,    return_tensors='tf' )
												lowerCAmelCase__         =    model.generate(
												    **_lowercase  ,    do_sample=_lowercase  ,    num_beams=2  ,    max_length=model.config.max_length - num_paddings )
												lowerCAmelCase__         =    tokenizer.decode(output_non_padded[0]  ,    skip_special_tokens=_lowercase )
												lowerCAmelCase__         =    tokenizer.decode(output_padded[0]  ,    skip_special_tokens=_lowercase )
												self.assertListEqual(_lowercase  ,    [non_padded_sentence, padded_sentence] )







						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__    ,							lowerCAmelCase__         =    self._get_beam_search_test_objects()

												lowerCAmelCase__         =    tokenizer(_lowercase  ,    return_tensors='tf'  ,    padding=_lowercase )
												lowerCAmelCase__         =    tf.function(model.generate  ,    jit_compile=_lowercase )
												lowerCAmelCase__         =    xla_generate(**_lowercase  ,    do_sample=_lowercase  ,    num_beams=2 )
												lowerCAmelCase__         =    tokenizer.batch_decode(_lowercase  ,    skip_special_tokens=_lowercase )
												self.assertListEqual(_lowercase  ,    _lowercase )






from __future__ import annotations



def       __SCREAMING_SNAKE_CASE    (   __UpperCamelCase       :			str      )				->   bool:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__     				= 42
  SCREAMING_SNAKE_CASE__     				= list(__UpperCamelCase      )
  SCREAMING_SNAKE_CASE__				,	SCREAMING_SNAKE_CASE__     				= _vector[:-1], int(_vector[-1]      )
  SCREAMING_SNAKE_CASE__     				= [int(__UpperCamelCase      ) for digit in __vector]

  vector.reverse()
  for i, digit in enumerate(__UpperCamelCase      ):
    if i & 1 == 0:
      SCREAMING_SNAKE_CASE__     				= digit * 2
      if doubled > 9:
        doubled -= 9
      check_digit += doubled
    else:
      check_digit += digit

  return check_digit % 10 == 0


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   assert is_luhn('''79927398713''')
   assert not is_luhn('''79927398714''')
