
import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
   import torch

   from transformers import AutoModelForImageClassification

if is_vision_available():
   from transformers import AutoImageProcessor






@require_torch
@require_vision
class     UpperCAmelCase						(		unittest.TestCase					):



   @slow
   def 							_SCREAMING_SNAKE_CASE  (self						:   List[str]					)						->      int:


          '''simple docstring'''


          snake_case			:  Any     							= AutoImageProcessor.from_pretrained("microsoft/dit-base-finetuned-rvlcdip"					)
          snake_case			:  Optional[Any]     							= AutoModelForImageClassification.from_pretrained("microsoft/dit-base-finetuned-rvlcdip"					)
          model.to(snake_case__					)

          from datasets import load_dataset

          snake_case			:  Optional[int]     							= load_dataset("nielsr/rvlcdip-demo"					)

          snake_case			:  List[Any]     							= dataset["train"][0]["image"].convert("RGB"					)

          snake_case			:  int     							= image_processor(snake_case__       ,		return_tensors="pt"					).to(snake_case__					)

          # forward pass
          with torch.no_grad():
                 snake_case			:  Any     							= model(**snake_case__					)
                 snake_case			:  Union[str, Any]     							= outputs.logits

          snake_case			:  Optional[Any]     							= torch.Size((1, 16)					)
          self.assertEqual(logits.shape       ,		snake_case__					)

          snake_case			:  int     							= torch.tensor(
              [-0.4158, -0.4092, -0.4347]       ,		device=snake_case__       ,		dtype=torch.float       ,		)
          self.assertTrue(torch.allclose(logits[0, :3]       ,		snake_case__       ,		atol=1e-4					)					)







from math import factorial


def      UpperCamelCase   (       __lowerCamelCase	:					int							,   __lowerCamelCase	:					int							,   __lowerCamelCase	:					float       ):
       if successes > trials:
              raise ValueError("successes must be lower or equal to trials"       )
       if trials < 0 or successes < 0:
              raise ValueError("the function is defined for non-negative integers"       )
       if not isinstance(__lowerCamelCase							,   __lowerCamelCase       ) or not isinstance(__lowerCamelCase							,   __lowerCamelCase       ):
              raise ValueError("the function is defined for non-negative integers"       )
       if not 0 < prob < 1:
              raise ValueError("prob has to be in range of 1 - 0"       )
       snake_case			:  Tuple     							= (prob**successes) * ((1 - prob) ** (trials - successes))
       # Calculate the binomial coefficient: n! / k!(n-k)!
       snake_case			:  str     							= float(factorial(__lowerCamelCase       )       )
       coefficient /= factorial(__lowerCamelCase       ) * factorial(trials - successes       )
       return probability * coefficient


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

   testmod()
   print("""Probability of 2 successes out of 4 trails""")
   print("""with probability of 0.75 is:""", end=""" """)
   print(binomial_distribution(2, 4, 0.75))





