


'''simple docstring'''




from typing import Union

import fire
import torch
from tqdm import tqdm

def 			__UpperCamelCase    (    _A    :				str					,   _A    :				str = "cpu"					,   _A    :				Union[str, None] = None				)    ->      None:




	"""simple docstring"""





	lowerCAmelCase					:    List[Any]      							= torch.load(_A					,   map_location=_A				)
	for k, v in tqdm(state_dict.items()				):
		if not isinstance(_A					,   torch.Tensor				):
			raise TypeError('FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin'				)
		lowerCAmelCase					:    Optional[int]      							= v.half()
	if save_path is None:  # overwrite src_path
		lowerCAmelCase					:    Dict      							= src_path
	torch.save(_A					,   _A				)


if __name__ == "__main__":
	fire.Fire(convert)




'''simple docstring'''




def 			__UpperCamelCase    (    _A    :				int				)    ->      bool:




	"""simple docstring"""





	return number & 1 == 0


if __name__ == "__main__":
				import doctest

				doctest.testmod()
