Convert vocoder weights.
(vocoder_path: Path, output_path: Path)
| 116 | |
| 117 | |
| 118 | def convert_vocoder(vocoder_path: Path, output_path: Path): |
| 119 | """Convert vocoder weights.""" |
| 120 | print(f"\nLoading vocoder from {vocoder_path}") |
| 121 | state_dict = torch.load(vocoder_path, map_location='cpu', weights_only=False) |
| 122 | |
| 123 | remapped = {} |
| 124 | for key, tensor in sorted(state_dict.items()): |
| 125 | if tensor.dim() == 0: |
| 126 | tensor = tensor.unsqueeze(0) |
| 127 | if tensor.dtype == torch.float32: |
| 128 | tensor = tensor.half() |
| 129 | remapped[key] = tensor |
| 130 | |
| 131 | print(f"Saving {len(remapped)} vocoder tensors to {output_path}") |
| 132 | save_file(remapped, str(output_path)) |
| 133 | print(f" Size: {output_path.stat().st_size / 1e6:.1f} MB") |
| 134 | |
| 135 | |
| 136 | def main(): |