How to serialize an AllenNLP model without training it?

I have a model that is entirely pre-trained (basically, PretrainedTransformerEmbedder -> BagOfEmbeddingsEncoder). I was wondering if there is an easy way to serialize this model to disk without training it, as I want to use the model before it has been subjected to my fine-tuning procedure (as a baseline).

The only solution I can think of seems a little hacky, i.e. using the train command with a checkpointer but freezing all the gradients. Or playing around with the Archive class.

Thanks in advance!

1 Like

Here are three potential options:

  1. Use the NoOpTrainer.
  2. Use the newly-added EpochCallback, which gets called at the start of training, to save a checkpoint of your model (with is_best_so_far=True), and then call archive_model.
  3. Write a simple script to instantiate the model, save its weights, config file and vocabulary yourself, then call archive_model.

If you need more detail on these options, feel free to ask more questions.

2 Likes

NoOpTrainer is exactly what I was looking for. Not sure how I didn’t see that – thanks a lot!