Model Archiver

1.0.3 · maintenance · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

model-archiver --model-name my_mxnet_model \
               --version 1.0 \
               --model-path ./path_to_model_artifacts/ \
               --handler my_handler.py \
               --extra-files requirements.txt,config.json \
               --export-path ./model_store/

# Example `my_handler.py` (simplified structure):
# class MXNetHandler:
#     def __init__(self):
#         self.model = None
#     def initialize(self, context):
#         properties = context.system_properties
#         model_dir = properties.get("model_dir")
#         # Load model, e.g., using MXNet's gluon.nn
#         # self.model = gluon.nn.load_param(os.path.join(model_dir, 'model_params.params'))
#     def preprocess(self, data):
#         # Preprocess input data
#         return data
#     def inference(self, data):
#         # Perform inference using self.model
#         return self.model(data)
#     def postprocess(self, data):
#         # Postprocess inference results
#         return data

view raw JSON →