
"""simple docstring"""






import unittest

from transformers import DonutProcessor


SCREAMING_SNAKE_CASE						:						Any					   =       '''naver-clova-ix/donut-base'''





class       snake_case_       (    unittest.TestCase       ):



	"""simple docstring"""

	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       DonutProcessor.from_pretrained(__a						)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       {
					    'name': 'John Doe',
					    'age': '99',
					    'city': 'Atlanta',
					    'state': 'GA',
					    'zip': '30301',
					    'phone': '123-4567',
					    'nicknames': [{'nickname': 'Johnny'}, {'nickname': 'JD'}],
					}

					A__							 =       (
					    '<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>'
					    '<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>'
					    '<s_nicknames><s_nickname>Johnny</s_nickname>'
					    '<sep/><s_nickname>JD</s_nickname></s_nicknames>'
					)
					A__							 =       self.processor.tokenajson(__a						)

					self.assertDictEqual(__a  ,					__a						)










"""simple docstring"""






from typing import Union

import fire
import torch
from tqdm import tqdm



def  __lowerCamelCase					(					lowerCAmelCase__       ,lowerCAmelCase__ = "cpu"       ,lowerCAmelCase__ = None				):
				A__							 =       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'				)
								A__							 =       v.half()
				if save_path is None:  # overwrite src_path
								A__							 =       src_path
				torch.save(lowerCAmelCase__       ,lowerCAmelCase__				)


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


