Export inference checkpoint
To run your model on Myrtle.ai’s hardware-accelerated inference server you will need a hardware checkpoint. This is a training checkpoint with additional data such as mel-bin mean and variances as described here.
By default, train.sh will automatically create hardware checkpoints for your
best and last checkpoints.
If your best checkpoint is /results/RNN-T_best_checkpoint.pt,
you can find the hardware checkpoint at /results/RNN-T_best_checkpoint.hw.pt.
Creating a hardware checkpoint manually
If you want more customization,
you can also create a hardware checkpoint from
a training checkpoint using the hardware_ckpt.py script.
To create a hardware checkpoint run:
python -m caiman_train.export.hardware_ckpt \
--ckpt /results/RNN-T_best_checkpoint.pt \
--config <path/to/config.yaml> \
--output_ckpt /results/hardware_checkpoint.example.pt
where /results/RNN-T_best_checkpoint.pt is your best checkpoint.
The script should take a few seconds to run.
The generated hardware checkpoint will contain the sentencepiece model specified in the config file and the dataset mel stats.
The hardware checkpoint also records which prefixes the model was trained with,
and the one it was validated with during training (--pnc_prefix and --val_lang_prefix),
so the inference server can validate a requested prefix and use that one by default
(see Model Info).
The export will also find the binary n-gram generated during preprocessing, as specified by the ngram_path field in the config file, check it and print its path, as it is a separate file to keep next to the hardware checkpoint.
However, this is optional, and can be skipped by passing the --skip_ngram flag:
python -m caiman_train.export.hardware_ckpt \
--ckpt /results/RNN-T_best_checkpoint.pt \
--config <path/to/config.yaml> \
--output_ckpt /results/hardware_checkpoint.example.pt \
--skip_ngram
To use an n-gram that was generated on a different dataset, use the --override_ngram_path argument:
python -m caiman_train.export.hardware_ckpt \
--ckpt /results/RNN-T_best_checkpoint.pt \
--config <path/to/config.yaml> \
--output_ckpt /results/hardware_checkpoint.example.pt \
--override_ngram_path /path/to/ngram.binary
The n-gram file
The n-gram is not stored in the hardware checkpoint (which has only its scale factor). It can be large (many GB), so it is a separate file that the inference server memory-maps: any number of servers share one copy of it in memory.
The export does not copy it: it prints the path of the n-gram file it used (the one found from ngram_path in the config, or --override_ngram_path), and that file is what you upload to wherever you put the hardware checkpoint.
The inference server has to be given the file with --ngram-binary-path.
The n-gram file is the KenLM binary, unchanged, followed by the hash of the SentencePiece model it was made for; caiman_model.ngram_file describes the format.
scripts/generate_ngram.sh writes it, and python -m caiman_model.ngram_file append <ngram> <sentencepiece model> adds it to an existing n-gram (info <ngram> prints what a file records).
Validation, the export and the inference server refuse an n-gram file that says it was made for another SentencePiece model than the checkpoint’s. One that doesn’t say can still be used, with a warning, as nothing can check it.
Stock KenLM loads these files; asking it for their vocabulary strings needs our KenLM fork, which the training image installs.