

from typing import Union

import fire
import torch
from tqdm import tqdm


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		str ,   _SCREAMING_SNAKE_CASE					:		str = "cpu" ,   _SCREAMING_SNAKE_CASE					:		Union[str, None] = None       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						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'       )
        SCREAMING_SNAKE_CASE_									=						v.half()
    if save_path is None:  # overwrite src_path
        SCREAMING_SNAKE_CASE_									=						src_path
    torch.save(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )


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





from typing import TYPE_CHECKING

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


UpperCamelCase__  :      Tuple			=    {
    "configuration_trocr": ["TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP", "TrOCRConfig"],
    "processing_trocr": ["TrOCRProcessor"],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__  :      Tuple			=    [
           "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

       UpperCamelCase__  :      str			=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


