'''simple docstring'''






import gc
import threading
import time

import psutil
import torch




class    a :







  def __init__(							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= psutil.Process()
    __UpperCAmelCase:					int		= False







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= -1

    while True:
      __UpperCAmelCase:					List[str]		= max(self.process.memory_info().rss   ,    self.cpu_memory_peak					)

      # can't sleep or will not catch the peak right (this comment is here on purpose)
      if not self.peak_monitoring:
        break







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= True
    __UpperCAmelCase:					List[str]		= threading.Thread(target=self.peak_monitor					)
    __UpperCAmelCase:					Union[str, Any]		= True
    self.thread.start()







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= False
    self.thread.join()
    return self.cpu_memory_peak



SCREAMING_SNAKE_CASE_	   =			PeakCPUMemory()






def  UpperCamelCase__					(					)							->	List[Any]:
  # Time
  __UpperCAmelCase:					Optional[int]		= {"""time""": time.time()}

  gc.collect()
  torch.cuda.empty_cache()

  # CPU mem
  __UpperCAmelCase:					Union[str, Any]		= psutil.Process().memory_info().rss
  cpu_peak_tracker.start()

  # GPU mem
  for i in range(torch.cuda.device_count()     ):
    __UpperCAmelCase:					str		= torch.cuda.memory_allocated(__SCREAMING_SNAKE_CASE     )
  torch.cuda.reset_peak_memory_stats()

  return measures






def  UpperCamelCase__					(					_lowercase    :				Optional[Any]     )							->	int:
  # Time
  __UpperCAmelCase:					Optional[int]		= {"""time""": time.time() - start_measures["""time"""]}

  gc.collect()
  torch.cuda.empty_cache()

  # CPU mem
  __UpperCAmelCase:					List[Any]		= (psutil.Process().memory_info().rss - start_measures["""cpu"""]) / 2**2_0
  __UpperCAmelCase:					Optional[Any]		= (cpu_peak_tracker.stop() - start_measures["""cpu"""]) / 2**2_0

  # GPU mem
  for i in range(torch.cuda.device_count()     ):
    __UpperCAmelCase:					Union[str, Any]		= (torch.cuda.memory_allocated(__SCREAMING_SNAKE_CASE     ) - start_measures[str(__SCREAMING_SNAKE_CASE     )]) / 2**2_0
    __UpperCAmelCase:					List[Any]		= (torch.cuda.max_memory_allocated(__SCREAMING_SNAKE_CASE     ) - start_measures[str(__SCREAMING_SNAKE_CASE     )]) / 2**2_0

  return measures







def  UpperCamelCase__					(					_lowercase    :				Union[str, Any]   ,    _lowercase    :				Optional[Any]     )							->	Optional[int]:
  print(F'''{description}:'''     )
  print(F'''- Time: {measures['time']:.2f}s'''     )
  for i in range(torch.cuda.device_count()     ):
    print(F'''- GPU {i} allocated: {measures[str(__SCREAMING_SNAKE_CASE     )]:.2f}MiB'''     )
    __UpperCAmelCase:					str		= measures[F'''{i}-peak''']
    print(F'''- GPU {i} peak: {peak:.2f}MiB'''     )
  print(F'''- CPU RAM allocated: {measures['cpu']:.2f}MiB'''     )
  print(F'''- CPU RAM peak: {measures['cpu-peak']:.2f}MiB'''     )
'''simple docstring'''






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


SCREAMING_SNAKE_CASE_	   =			logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_	   =			{
    'facebook/timesformer': 'https://huggingface.co/facebook/timesformer/resolve/main/config.json',
}




class    a (       __lowerCAmelCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					"""timesformer"""







  def __init__(							self   ,    snake_case_=224   ,    snake_case_=16   ,    snake_case_=3   ,    snake_case_=8   ,    snake_case_=768   ,    snake_case_=12   ,    snake_case_=12   ,    snake_case_=3072   ,    snake_case_="gelu"   ,    snake_case_=0.0   ,    snake_case_=0.0   ,    snake_case_=0.0_2   ,    snake_case_=1e-6   ,    snake_case_=True   ,    snake_case_="divided_space_time"   ,    snake_case_=0   ,    **snake_case_   ,    ):

    '''simple docstring'''







    super().__init__(**snake_case_					)

    __UpperCAmelCase:					Tuple		= image_size
    __UpperCAmelCase:					List[Any]		= patch_size
    __UpperCAmelCase:					Optional[Any]		= num_channels
    __UpperCAmelCase:					int		= num_frames

    __UpperCAmelCase:					List[str]		= hidden_size
    __UpperCAmelCase:					List[str]		= num_hidden_layers
    __UpperCAmelCase:					Dict		= num_attention_heads
    __UpperCAmelCase:					List[str]		= intermediate_size
    __UpperCAmelCase:					Union[str, Any]		= hidden_act
    __UpperCAmelCase:					Dict		= hidden_dropout_prob
    __UpperCAmelCase:					Optional[Any]		= attention_probs_dropout_prob
    __UpperCAmelCase:					Union[str, Any]		= initializer_range
    __UpperCAmelCase:					List[Any]		= layer_norm_eps
    __UpperCAmelCase:					int		= qkv_bias

    __UpperCAmelCase:					str		= attention_type
    __UpperCAmelCase:					Tuple		= drop_path_rate