



"""simple docstring"""






from typing import Union

import fire
import torch
from tqdm import tqdm






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


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









"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


_lowercase			:			Any										=						{
    "configuration_trocr": ["TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP", "TrOCRConfig"],
    "processing_trocr": ["TrOCRProcessor"],
}


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase			:			List[Any]										=						[
		    "TROCR_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "TrOCRForCausalLM",
		    "TrOCRPreTrainedModel",
		]


if TYPE_CHECKING:
		from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
		from .processing_trocr import TrOCRProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
		import sys

		_lowercase			:			Tuple										=						_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




