





from typing import Union

import fire
import torch
from tqdm import tqdm





def 					lowerCAmelCase_			(	__a     ,   __a = "cpu"     ,   __a = None		)					->		int:







  """simple docstring"""





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


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







def 					lowerCAmelCase_			(	__a		)					->		str:







  """simple docstring"""





  if isinstance(__a     ,   __a		):
    raise TypeError("'float' object cannot be interpreted as an integer"		)
  if isinstance(__a     ,   __a		):
    raise TypeError("'str' object cannot be interpreted as an integer"		)

  if num == 0:
    return "0b0"

  lowerCamelCase__:				Optional[int]        =False

  if num < 0:
    lowerCamelCase__:				Optional[Any]        =True
    lowerCamelCase__:				List[Any]        =-num

  lowerCamelCase__:				list[int]        =[]
  while num > 0:
    binary.insert(0     ,   num % 2		)
    num >>= 1

  if negative:
    return "-0b" + "".join(str(__a		) for e in binary		)

  return "0b" + "".join(str(__a		) for e in binary		)


if __name__ == "__main__":
     import doctest

     doctest.testmod()

