| ```python | |
| import json | |
| import onnx | |
| import torch | |
| from safetensors.torch import save_file | |
| from huggingface_hub import hf_hub_download | |
| state_dict = {} | |
| state_dict_info = {} | |
| for i in onnx.load(hf_hub_download("KittenML/kitten-tts-nano-0.8-int8","kitten_tts_nano_v0_8.onnx")).graph.initializer: | |
| p = onnx.numpy_helper.to_array(i) | |
| state_dict_info[i.name] = list(p.shape) | |
| state_dict[i.name] = torch.tensor(p) | |
| json.dump(state_dict_info,open("KittenTTS.json","w")) | |
| save_file(state_dict, "model.safetensors") | |
| ``` |