Model Archiver is a Python library and command-line tool used for creating archives of trained neural network models. These archives, typically with a .mar extension, are specifically structured to be consumed by the MXNet-Model-Server for efficient inference. The PyPI package (version 1.0.3) serves as a standalone tool, although its core functionality has largely evolved into 'torch-model-archiver' for the 'TorchServe' (formerly 'Multi-Model-Server') ecosystem.
pip install model-archiverVerified import paths — ran on the pinned version, not inferred.
Create a model archive (.mar file) for an MXNet model. This command packages your model artifacts, a custom handler script (`my_handler.py`), and any extra files (like `requirements.txt` or configuration files) into a single archive. The generated .mar file is then placed in the specified `export-path`. Ensure your handler script correctly implements the `initialize`, `preprocess`, `inference`, and `postprocess` methods for your specific model.
For new projects or PyTorch models, consider using `pip install torch-model-archiver` and the associated `torch-model-archiver` CLI. This provides access to the latest features, bug fixes, and active community support.
For packaging models, rely on the `model-archiver` command-line tool. If programmatic integration is essential, consult the source code on GitHub for direct API usage patterns, focusing on the `model_archiver.mar` module.
Before archiving ONNX models, manually install the required libraries: `pip install protobuf onnx mxnet` (or the specific MXNet variant like `mxnet-cu101`). Ensure a protobuf compiler is also available in your environment.
For complex dependencies, either package them as a Python egg/wheel and include it via `--extra-files`, or adjust your handler to manually manage the Python path or use relative imports carefully. Alternatively, provide a `requirements.txt` with your `model-archiver` command for dependencies available on PyPI.