code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  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
  
  
  _a      :				List[str]											=					get_logger(__name__)
  
  
  
  
  
  def      _lowerCAmelCase		(		lowercase      ,			lowercase			)      ->      Optional[Any]:
  			if text.startswith(lowercase			):
  						return text[len(lowercase			) :]
  			return text  # or whatever
  
  
  
  
  
  def      _lowerCAmelCase		(		lowercase			)      ->      Optional[Any]:
  			return {remove_prefix(lowercase      ,			"""model."""			): v for k, v in sd.items()}
  
  
  
  
  
  def      _lowerCAmelCase		(		lowercase			)      ->      Optional[Any]:
  			__lowerCAmelCase      		=       {}
  			for k in state_dicts[0].keys():
  						__lowerCAmelCase      		=       [sd[k] for sd in state_dicts]
  						__lowerCAmelCase      		=       sum(lowercase			) / len(lowercase			)
  						assert isinstance(lowercase      ,			torch.Tensor			)
  						__lowerCAmelCase      		=       new_t
  			return new_sd
  
  
  
  
  
  def      _lowerCAmelCase		(		lowercase      ,			lowercase      ,			lowercase			)      ->      None:
  			__lowerCAmelCase      		=       AutoModelForSeqaSeqLM.from_pretrained(lowercase			)
  			if os.path.isfile(lowercase			):
  						__lowerCAmelCase      		=       [pl_ckpt_path]
  			else:
  						assert os.path.isdir(lowercase			)
  						__lowerCAmelCase      		=       list(Path(lowercase			).glob("""*.ckpt"""			)			)
  						assert ckpt_files, f'could not find any ckpt files inside the {pl_ckpt_path} directory'
  
  			if len(lowercase			) > 1:
  						logger.info(f'averaging the weights of {ckpt_files}'			)
  
  			__lowerCAmelCase      		=       [sanitize(torch.load(lowercase      ,			map_location="""cpu"""			)["""state_dict"""]			) for x in ckpt_files]
  			__lowerCAmelCase      		=       average_state_dicts(lowercase			)
  
  			__lowerCAmelCase		, __lowerCAmelCase      		=       hf_model.load_state_dict(lowercase      ,			strict=lowercase			)
  			assert not missing, f'missing keys: {missing}'
  			hf_model.save_pretrained(lowercase			)
  			try:
  						__lowerCAmelCase      		=       AutoTokenizer.from_pretrained(lowercase			)
  						tok.save_pretrained(lowercase			)
  			except Exception:
  						pass
  						# dont copy tokenizer if cant
  
  
  if __name__ == "__main__":
  	fire.Fire(convert_pl_to_hf)
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  from cva import destroyAllWindows, imread, imshow, waitKey
  
  
  
  
  
  def      _lowerCAmelCase		(		lowercase      ,			lowercase			)      ->      int:
  			__lowerCAmelCase		, __lowerCAmelCase      		=       img.shape[0], img.shape[1]
  
  			def to_grayscale(lowercase      ,			lowercase      ,			lowercase			):
  						return 0.21_26 * red + 0.5_87 * green + 0.1_14 * blue
  
  			def normalize(lowercase			):
  						return min(lowercase      ,			255			)
  
  			for i in range(lowercase			):
  						for j in range(lowercase			):
  									__lowerCAmelCase      		=       int(to_grayscale(*img[i][j]			)			)
  									__lowerCAmelCase      		=       [
  									    normalize(lowercase			),
  									    normalize(greyscale + factor			),
  									    normalize(greyscale + 2 * factor			),
  									]
  
  			return img
  
  
  if __name__ == "__main__":
  	# read original image
  	_a      :				Any											=					{
  	    percentage: imread("""image_data/lena.jpg""", 1) for percentage in (1_0, 2_0, 3_0, 4_0)
  	}
  
  	for percentage, img in images.items():
  		make_sepia(img, percentage)
  
  	for percentage, img in images.items():
  		imshow(f'Original image with sepia (factor: {percentage})', img)
  
  	waitKey(0)
  	destroyAllWindows()
  
  