


'''simple docstring'''

def __snake_case      (   UpperCAmelCase_		:		Dict	):
 lowerCamelCase_  				=						abs(SCREAMING_SNAKE_CASE_	)
 lowerCamelCase_  				=						0
 while n > 0:
  res += n % 10
  n //= 10
 return res





def __snake_case      (   UpperCAmelCase_		:		Dict	):
 lowerCamelCase_  				=						abs(SCREAMING_SNAKE_CASE_	)
 return n if n < 10 else n % 10 + sum_of_digits(n // 10	)





def __snake_case      (   UpperCAmelCase_		:		Union[str, Any]	):
 return sum(int(SCREAMING_SNAKE_CASE_	) for c in str(abs(SCREAMING_SNAKE_CASE_	)	)	)





def __snake_case      (   ):
 from collections.abc import Callable
 from timeit import timeit

 def benchmark_a_function(UpperCAmelCase_		:		Optional[int]      ,       UpperCAmelCase_		:		Optional[Any]	) -> None:
  lowerCamelCase_  				=						F'''{func.__name__}({value})'''
  lowerCamelCase_  				=						timeit(F'''__main__.{call}'''      ,       setup="import __main__"	)
  print(F'''{call:56} = {func(SCREAMING_SNAKE_CASE_	)} -- {timing:.4f} seconds'''	)

 for value in (262144, 1125899906842624, 1267650600228229401496703205376):
  for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
   benchmark_a_function(SCREAMING_SNAKE_CASE_      ,       SCREAMING_SNAKE_CASE_	)
  print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()







'''simple docstring'''

import unittest

import numpy as np

from transformers import DistilBertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
     import jax.numpy as jnp

     from transformers.models.distilbert.modeling_flax_distilbert import (
         FlaxDistilBertForMaskedLM,
         FlaxDistilBertForMultipleChoice,
         FlaxDistilBertForQuestionAnswering,
         FlaxDistilBertForSequenceClassification,
         FlaxDistilBertForTokenClassification,
         FlaxDistilBertModel,
     )





class   snake_case					(					unittest.TestCase    ):





  """simple docstring"""




  def __init__(					self    ,						UpperCamelCase    ,						UpperCamelCase=13    ,						UpperCamelCase=7    ,						UpperCamelCase=True    ,						UpperCamelCase=True    ,						UpperCamelCase=True    ,						UpperCamelCase=True    ,						UpperCamelCase=99    ,						UpperCamelCase=32    ,						UpperCamelCase=5    ,						UpperCamelCase=4    ,						UpperCamelCase=37    ,						UpperCamelCase="gelu"    ,						UpperCamelCase=0.1    ,						UpperCamelCase=0.1    ,						UpperCamelCase=512    ,						UpperCamelCase=16    ,						UpperCamelCase=2    ,						UpperCamelCase=0.02    ,						UpperCamelCase=4    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						parent
   lowerCamelCase_  				=						batch_size
   lowerCamelCase_  				=						seq_length
   lowerCamelCase_  				=						is_training
   lowerCamelCase_  				=						use_attention_mask
   lowerCamelCase_  				=						use_token_type_ids
   lowerCamelCase_  				=						use_labels
   lowerCamelCase_  				=						vocab_size
   lowerCamelCase_  				=						hidden_size
   lowerCamelCase_  				=						num_hidden_layers
   lowerCamelCase_  				=						num_attention_heads
   lowerCamelCase_  				=						intermediate_size
   lowerCamelCase_  				=						hidden_act
   lowerCamelCase_  				=						hidden_dropout_prob
   lowerCamelCase_  				=						attention_probs_dropout_prob
   lowerCamelCase_  				=						max_position_embeddings
   lowerCamelCase_  				=						type_vocab_size
   lowerCamelCase_  				=						type_sequence_label_size
   lowerCamelCase_  				=						initializer_range
   lowerCamelCase_  				=						num_choices






  def 						snake_case	(					self  ):







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

   lowerCamelCase_  				=						None
   if self.use_attention_mask:
    lowerCamelCase_  				=						random_attention_mask([self.batch_size, self.seq_length]  )

   lowerCamelCase_  				=						DistilBertConfig(
       vocab_size=self.vocab_size    ,						dim=self.hidden_size    ,						n_layers=self.num_hidden_layers    ,						n_heads=self.num_attention_heads    ,						hidden_dim=self.intermediate_size    ,						hidden_act=self.hidden_act    ,						dropout=self.hidden_dropout_prob    ,						attention_dropout=self.attention_probs_dropout_prob    ,						max_position_embeddings=self.max_position_embeddings    ,						initializer_range=self.initializer_range    ,						tie_weights_=UpperCamelCase    ,						)

   return config, input_ids, attention_mask







  def 						snake_case	(					self  ):







   """simple docstring"""
   lowerCamelCase_  				=						self.prepare_config_and_inputs()
   lowerCamelCase_				,lowerCamelCase_				,lowerCamelCase_  				=						config_and_inputs
   lowerCamelCase_  				=						{"input_ids": input_ids, "attention_mask": attention_mask}
   return config, inputs_dict





@require_flax
class   snake_case					(					lowercase    ,		unittest.TestCase    ):





  """simple docstring"""




  _lowerCamelCase						=						(
      (
          FlaxDistilBertModel,
          FlaxDistilBertForMaskedLM,
          FlaxDistilBertForMultipleChoice,
          FlaxDistilBertForQuestionAnswering,
          FlaxDistilBertForSequenceClassification,
          FlaxDistilBertForTokenClassification,
          FlaxDistilBertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )






  def 						snake_case	(					self  ):







   """simple docstring"""
   lowerCamelCase_  				=						FlaxDistilBertModelTester(self  )







  @slow
  def 						snake_case	(					self  ):







   """simple docstring"""
   for model_class_name in self.all_model_classes:
    lowerCamelCase_  				=						model_class_name.from_pretrained("distilbert-base-uncased"  )
    lowerCamelCase_  				=						model(np.ones((1, 1)  )  )
    self.assertIsNotNone(UpperCamelCase  )





@require_flax
class   snake_case					(					unittest.TestCase    ):





  """simple docstring"""




  @slow
  def 						snake_case	(					self  ):







   """simple docstring"""
   lowerCamelCase_  				=						FlaxDistilBertModel.from_pretrained("distilbert-base-uncased"  )
   lowerCamelCase_  				=						np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]  )
   lowerCamelCase_  				=						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
   lowerCamelCase_  				=						model(UpperCamelCase    ,						attention_mask=UpperCamelCase  )[0]
   lowerCamelCase_  				=						(1, 11, 768)
   self.assertEqual(output.shape    ,						UpperCamelCase  )
   lowerCamelCase_  				=						np.array([[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]  )

   self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]    ,						UpperCamelCase    ,						atol=1e-4  )  )



