Download scripts/export_checkpoint.py from TuringLogic/little-tts: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/TuringLogic/little-tts/resolve/main/scripts/export_checkpoint.py
- Command line
-
hf download hf://TuringLogic/little-tts/scripts/export_checkpoint.py
-
curl -L -o export_checkpoint.py https://huggingface.co/TuringLogic/little-tts/resolve/main/scripts/export_checkpoint.py
1.36 kB
| """Export the inference model from a full training checkpoint (last.pt or step-*.pt). | |
| The export holds the speech model only: no optimizer state, no auxiliary mel | |
| head and no discriminators. | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| import torch | |
| from little_tts.config import CHECKPOINT_FORMAT, Config | |
| from little_tts.model import LittleTTS | |
| from little_tts.text import frontend_fingerprint | |
| from little_tts.train import export_model | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--checkpoint", type=Path, required=True) | |
| parser.add_argument("--output", type=Path, required=True) | |
| args = parser.parse_args() | |
| state = torch.load(args.checkpoint, map_location="cpu", weights_only=True) | |
| if state.get("format_version") != CHECKPOINT_FORMAT or state["frontend"] != frontend_fingerprint(): | |
| raise ValueError("checkpoint format or front end does not match this code") | |
| model = LittleTTS(Config.from_dict(state["config"])) | |
| model.load_state_dict({k.removeprefix("model."): v for k, v in state["system"].items() if k.startswith("model.")}, strict=True) | |
| export_model(model, args.output, state["step"], state["annotation"]) | |
| print(f"exported step {state['step']} with {sum(p.numel() for p in model.parameters()):,} parameters to {args.output}") | |
| if __name__ == "__main__": | |
| main() | |