code: 
  import os
  from pathlib import Path
  from typing import Dict, List
  
  import fire
  import torch
  
  from transformers import AutoModelForSeqaSeqLM, AutoTokenizer
  from transformers.utils.logging import get_logger
  
  
  snake_case				:	List[str]							   =						get_logger(__name__)
  
  
  
  
  
  
  def 						lowerCAmelCase_		(      _snake_case   :						Dict   ,     _snake_case   :						Union[str, Any]     )       ->	Optional[Any]:
  
  
  
  
  
  
  
  	'''simple docstring'''
  
  
  	if text.startswith(_snake_case     ):
  		return text[len(_snake_case     ) :]
  	return text  # or whatever
  
  
  
  
  
  
  def 						lowerCAmelCase_		(      _snake_case   :						Union[str, Any]     )       ->	Optional[Any]:
  
  
  
  
  
  
  
  	'''simple docstring'''
  
  
  	return {remove_prefix(_snake_case   ,     "model."     ): v for k, v in sd.items()}
  
  
  
  
  
  
  def 						lowerCAmelCase_		(      _snake_case   :						int     )       ->	Optional[Any]:
  
  
  
  
  
  
  
  	'''simple docstring'''
  
  
  	__magic_name__	:	List[str]			     =  {}
  	for k in state_dicts[0].keys():
  		__magic_name__	:	str			     =  [sd[k] for sd in state_dicts]
  		__magic_name__	:	str			     =  sum(_snake_case     ) / len(_snake_case     )
  		assert isinstance(_snake_case   ,     torch.Tensor     )
  		__magic_name__	:	str			     =  new_t
  	return new_sd
  
  
  
  
  
  
  def 						lowerCAmelCase_		(      _snake_case   :						Any   ,     _snake_case   :						Dict   ,     _snake_case   :						List[str]     )       ->	None:
  
  
  
  
  
  
  
  	'''simple docstring'''
  
  
  	__magic_name__	:	Any			     =  AutoModelForSeqaSeqLM.from_pretrained(_snake_case     )
  	if os.path.isfile(_snake_case     ):
  		__magic_name__	:	Optional[int]			     =  [pl_ckpt_path]
  	else:
  		assert os.path.isdir(_snake_case     )
  		__magic_name__	:	Optional[Any]			     =  list(Path(_snake_case     ).glob("*.ckpt"     )     )
  		assert ckpt_files, F'''could not find any ckpt files inside the {pl_ckpt_path} directory'''
  
  	if len(_snake_case     ) > 1:
  		logger.info(F'''averaging the weights of {ckpt_files}'''     )
  
  	__magic_name__	:	List[Any]			     =  [sanitize(torch.load(_snake_case   ,     map_location="cpu"     )["state_dict"]     ) for x in ckpt_files]
  	__magic_name__	:	List[Any]			     =  average_state_dicts(_snake_case     )
  
  	__magic_name__     ,					__magic_name__	:	Tuple			     =  hf_model.load_state_dict(_snake_case   ,     strict=_snake_case     )
  	assert not missing, F'''missing keys: {missing}'''
  	hf_model.save_pretrained(_snake_case     )
  	try:
  		__magic_name__	:	int			     =  AutoTokenizer.from_pretrained(_snake_case     )
  		tok.save_pretrained(_snake_case     )
  	except Exception:
  		pass
  		# dont copy tokenizer if cant
  
  
  if __name__ == "__main__":
  				fire.Fire(convert_pl_to_hf)
  
style_context: 
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_torch_available,
      is_vision_available,
  )
  
  
  snake_case				:	Optional[int]							   =						{
      "configuration_mobilevitv2": [
          "MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP",
          "MobileViTV2Config",
          "MobileViTV2OnnxConfig",
      ],
  }
  
  
  try:
  				if not is_torch_available():
  								raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  				pass
  else:
  				snake_case				:	Optional[int]							   =						[
  				    "MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST",
  				    "MobileViTV2ForImageClassification",
  				    "MobileViTV2ForSemanticSegmentation",
  				    "MobileViTV2Model",
  				    "MobileViTV2PreTrainedModel",
  				]
  
  if TYPE_CHECKING:
  				from .configuration_mobilevitva import (
  				    MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
  				    MobileViTVaConfig,
  				    MobileViTVaOnnxConfig,
  				)
  
  				try:
  								if not is_torch_available():
  												raise OptionalDependencyNotAvailable()
  				except OptionalDependencyNotAvailable:
  								pass
  				else:
  								from .modeling_mobilevitva import (
  								    MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
  								    MobileViTVaForImageClassification,
  								    MobileViTVaForSemanticSegmentation,
  								    MobileViTVaModel,
  								    MobileViTVaPreTrainedModel,
  								)
  
  else:
  				import sys
  
  				snake_case				:	Tuple							   =						_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
  