






'''simple docstring'''



import os
import shutil
from pathlib import Path
from typing import Optional, Union

import numpy as np
from huggingface_hub import hf_hub_download

from ..utils import ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, is_onnx_available, logging


if is_onnx_available():
 import onnxruntime as ort


__UpperCamelCase      :       Tuple      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Optional[Any]      			=      {
    """tensor(bool)""": np.bool_,
    """tensor(int8)""": np.inta,
    """tensor(uint8)""": np.uinta,
    """tensor(int16)""": np.intaa,
    """tensor(uint16)""": np.uintaa,
    """tensor(int32)""": np.intaa,
    """tensor(uint32)""": np.uintaa,
    """tensor(int64)""": np.intaa,
    """tensor(uint64)""": np.uintaa,
    """tensor(float16)""": np.floataa,
    """tensor(float)""": np.floataa,
    """tensor(double)""": np.floataa,
}
class 							__SCREAMING_SNAKE_CASE       :




      def __init__(  self ,   lowerCamelCase=None ,   **lowerCamelCase      )							->int:



         '''simple docstring'''
         logger.info('`diffusers.OnnxRuntimeModel` is experimental and might change in the future.'      )
         __a				     =    model
         __a				     =    kwargs.get('model_save_dir' ,   __lowercase      )
         __a				     =    kwargs.get('latest_model_name' ,   __lowercase      )




      def __call__(  self ,   **lowerCamelCase      )							->List[str]:



         '''simple docstring'''
         __a				     =    {k: np.array(__lowercase      ) for k, v in kwargs.items()}
         return self.model.run(__lowercase ,   __lowercase      )




      @staticmethod
      def  __UpperCamelCase							(  lowerCamelCase ,   lowerCamelCase=None ,   lowerCamelCase=None      )							->Dict:



         '''simple docstring'''
         if provider is None:
            logger.info('No onnxruntime provider specified, using CPUExecutionProvider'      )
            __a				     =    'CPUExecutionProvider'

         return ort.InferenceSession(__lowercase ,   providers=[provider] ,   sess_options=__lowercase      )




      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   lowerCamelCase = None ,   **lowerCamelCase      )							->Optional[int]:



         '''simple docstring'''
         __a				     =    file_name if file_name is not None else ONNX_WEIGHTS_NAME

         __a				     =    self.model_save_dir.joinpath(self.latest_model_name      )
         __a				     =    Path(__lowercase      ).joinpath(__lowercase      )
         try:
            shutil.copyfile(__lowercase ,   __lowercase      )
         except shutil.SameFileError:
            pass

         # copy external weights (for models >2GB)
         __a				     =    self.model_save_dir.joinpath(__lowercase      )
         if src_path.exists():
            __a				     =    Path(__lowercase      ).joinpath(__lowercase      )
            try:
               shutil.copyfile(__lowercase ,   __lowercase      )
            except shutil.SameFileError:
               pass




      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   **lowerCamelCase ,   )							->Union[str, Any]:



         '''simple docstring'''
         if os.path.isfile(__lowercase      ):
            logger.error(F"""Provided path ({save_directory}) should be a directory, not a file"""      )
            return

         os.makedirs(__lowercase ,   exist_ok=__lowercase      )

         # saving model weights/files
         self._save_pretrained(__lowercase ,   **__lowercase      )




      @classmethod
      def  __UpperCamelCase							(  cls ,   lowerCamelCase ,   lowerCamelCase = None ,   lowerCamelCase = None ,   lowerCamelCase = False ,   lowerCamelCase = None ,   lowerCamelCase = None ,   lowerCamelCase = None ,   lowerCamelCase = None ,   **lowerCamelCase ,   )							->List[str]:



         '''simple docstring'''
         __a				     =    file_name if file_name is not None else ONNX_WEIGHTS_NAME
         # load model from local directory
         if os.path.isdir(__lowercase      ):
            __a				     =    OnnxRuntimeModel.load_model(
                os.path.join(__lowercase ,   __lowercase      ) ,   provider=__lowercase ,   sess_options=__lowercase      )
            __a				     =    Path(__lowercase      )
         # load model from hub
         else:
            # download model
            __a				     =    hf_hub_download(
                repo_id=__lowercase ,   filename=__lowercase ,   use_auth_token=__lowercase ,   revision=__lowercase ,   cache_dir=__lowercase ,   force_download=__lowercase ,   )
            __a				     =    Path(__lowercase      ).parent
            __a				     =    Path(__lowercase      ).name
            __a				     =    OnnxRuntimeModel.load_model(__lowercase ,   provider=__lowercase ,   sess_options=__lowercase      )
         return cls(model=__lowercase ,   **__lowercase      )






      @classmethod
      def  __UpperCamelCase							(  cls ,   lowerCamelCase ,   lowerCamelCase = True ,   lowerCamelCase = None ,   lowerCamelCase = None ,   **lowerCamelCase ,   )							->Tuple:



         '''simple docstring'''
         __a				     =    None
         if len(str(__lowercase      ).split('@'      )      ) == 2:
            __a     ,			__a				     =    model_id.split('@'      )

         return cls._from_pretrained(
             model_id=__lowercase ,   revision=__lowercase ,   cache_dir=__lowercase ,   force_download=__lowercase ,   use_auth_token=__lowercase ,   **__lowercase ,   )







'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


__UpperCamelCase      :       Dict      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Any      			=      {
    """google/vivit-b-16x2-kinetics400""": (
        """https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"""
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
      __a  					="vivit"




      def __init__(  self ,   lowerCamelCase=224 ,   lowerCamelCase=32 ,   lowerCamelCase=[2, 16, 16] ,   lowerCamelCase=3 ,   lowerCamelCase=768 ,   lowerCamelCase=12 ,   lowerCamelCase=12 ,   lowerCamelCase=3072 ,   lowerCamelCase="gelu_fast" ,   lowerCamelCase=0.0 ,   lowerCamelCase=0.0 ,   lowerCamelCase=0.02 ,   lowerCamelCase=1e-06 ,   lowerCamelCase=True ,   **lowerCamelCase ,   )							->Tuple:



         '''simple docstring'''
         __a				     =    hidden_size
         __a				     =    num_hidden_layers
         __a				     =    num_attention_heads
         __a				     =    intermediate_size
         __a				     =    hidden_act
         __a				     =    hidden_dropout_prob
         __a				     =    attention_probs_dropout_prob
         __a				     =    initializer_range
         __a				     =    layer_norm_eps

         __a				     =    image_size
         __a				     =    num_frames
         __a				     =    tubelet_size
         __a				     =    num_channels
         __a				     =    qkv_bias

         super().__init__(**lowerCamelCase      )