liveBook · Manning

Model archive

As explained in Designing Deep Learning Systems: A guide for software engineers

A TorchServe model archive, typically a .mar file, containing the packaged files required to load and serve a model.

A model archive is a TorchServe .mar package that bundles model files, metadata, and execution code so a generic prediction API can serve models without knowing their algorithm or data schema. section 7.2.6

A typical archive assigns these responsibilities:

  • Model weights provide the serialized PyTorch model, commonly as a .pt or .pth file. section 7.2.6
  • The handler implements model initialization, input preprocessing, inference, and prediction postprocessing. section 7.2.6
  • Metadata identifies the model name, version, serialized file, runtime, and handler so TorchServe can load the package. section 7.2.6

Package an intent model

Create an archive with torch-model-archiver by supplying the model name, version, model implementation, serialized weights, handler, and extra files. The same package can be created in training code with model_archiver.archive(...).

TorchServe loads the archive into a worker process and invokes its handler when a prediction request arrives. Pure PyTorch model files cannot be loaded directly. section 7.2.6 section 7.4.2

How Designing Deep Learning Systems: A guide for software engineers covers it

How deep it goes
Defines archive components and handler responsibilities, then demonstrates command-line and programmatic packaging.
Examples
Uses an intent-classification archive containing model weights, a handler, vocabulary data, and manifest metadata.
What it assumes
Assumes a PyTorch model, serialized weights, and handler logic while defining the serving interface needed by TorchServe.
What you can do after
Builds a .mar package with torch-model-archiver or model_archiver for TorchServe deployment.
How it connects
Connects model weights, model handlers, model metadata, worker processes, and generic prediction APIs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing Deep Learning Systems: A guide for software engineers. The section links point to the parts of the book it draws on.