"""simple docstring"""







from typing import Union

import fire
import torch
from tqdm import tqdm
def   __UpperCAmelCase    (   UpperCAmelCase_   :    str      ,							UpperCAmelCase_   :    str = "cpu"      ,							UpperCAmelCase_   :    Union[str, None] = None  )							->      None:

	'''simple docstring'''





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


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






"""simple docstring"""







def   __UpperCAmelCase    (   UpperCAmelCase_   :    int      ,							UpperCAmelCase_   :    int  )							->      int:

	'''simple docstring'''





	while a != 0:
		__snake_case		,    __snake_case      :							Union[str, Any]						=			b % a, a
	return b

def   __UpperCAmelCase    (   UpperCAmelCase_   :    int      ,							UpperCAmelCase_   :    int  )							->      int:

	'''simple docstring'''





	if gcd(UpperCAmelCase_      ,							UpperCAmelCase_  ) != 1:
		__snake_case      :							Union[str, Any]						=			F"mod inverse of {a!r} and {m!r} does not exist"
		raise ValueError(UpperCAmelCase_  )
	__snake_case		,    __snake_case		,    __snake_case      :							List[str]						=			1, 0, a
	__snake_case		,    __snake_case		,    __snake_case      :							Dict						=			0, 1, m
	while va != 0:
		__snake_case      :							List[str]						=			ua // va
		__snake_case		,    __snake_case		,    __snake_case		,    __snake_case		,    __snake_case		,    __snake_case      :							List[str]						=			(ua - q * va), (ua - q * va), (ua - q * va), va, va, va
	return ua % m





