Overview
Manifest provides the MANIFEST.json representation for TorchServe model archives. It contains two key classes: RuntimeType (an Enum with PYTHON, PYTHON3, and LSP values) and Manifest (which assembles the manifest metadata). The Manifest class serializes creation time, runtime type, model metadata, and archiver version into a dictionary suitable for JSON output in .mar archives.
Description
The Manifest class represents the MANIFEST.json file that is embedded in every TorchServe model archive (.mar file). This JSON manifest contains metadata about the archive including when it was created, which runtime it targets, the model's metadata, and the version of the model archiver used to create it. The RuntimeType enum defines the supported runtime environments.
Key Responsibilities
- Runtime Definition: Defines supported runtime types via the
RuntimeType enum (PYTHON, PYTHON3, LSP)
- Manifest Construction: Assembles manifest metadata from runtime type and model information
- Serialization: Converts manifest data to a dictionary format suitable for JSON serialization
- Version Tracking: Includes the model archiver version from
model_archiver.__version__
Code Reference
Source Location
| File |
Lines |
Description
|
model-archiver/model_archiver/manifest_components/manifest.py |
L1-46 |
Full manifest module
|
model-archiver/model_archiver/manifest_components/manifest.py |
L10-13 |
RuntimeType enum
|
model-archiver/model_archiver/manifest_components/manifest.py |
L16-46 |
Manifest class
|
Signature
class RuntimeType(Enum):
"""
Enum defining supported runtime environments for model archives.
Values:
PYTHON: Generic Python runtime.
PYTHON3: Python 3 specific runtime.
LSP: Language Server Protocol runtime.
"""
PYTHON = "python"
PYTHON3 = "python3"
LSP = "LSP"
class Manifest:
"""
Represents the MANIFEST.json file in a .mar model archive.
Stores creation time, runtime type, model metadata, and
archiver version for serialization into the archive.
"""
def __init__(self, runtime, model):
"""
Initialize the manifest with runtime and model metadata.
Args:
runtime (RuntimeType): The target runtime environment.
model (Model): The Model object containing model metadata.
"""
...
def __to_dict__(self):
"""
Serialize manifest to a dictionary.
Returns:
dict: Manifest data with keys:
- 'createdOn': ISO format creation timestamp
- 'runtime': runtime type value string
- 'model': model metadata dict (from Model.__to_dict__)
- 'archiverVersion': version from model_archiver.__version__
"""
...
def __str__(self):
"""Return JSON string representation of the manifest."""
...
def __repr__(self):
"""Return JSON string representation of the manifest."""
...
Import
from model_archiver.manifest_components.manifest import Manifest, RuntimeType
# Internal dependency:
from model_archiver import __version__
I/O Contract
| Class/Method |
Input |
Output |
Notes
|
RuntimeType |
N/A |
Enum values: "python", "python3", "LSP" |
Lines 10-13; used by Manifest
|
Manifest.__init__(runtime, model) |
runtime: RuntimeType; model: Model instance |
None (sets instance attributes) |
Lines 18-21; stores creation time, runtime, model
|
Manifest.__to_dict__() |
None |
dict: serialized manifest data |
Lines 23-35; includes creation time, runtime, model, archiver version
|
Manifest.__str__() |
None |
str: JSON representation |
Calls __to_dict__ internally
|
MANIFEST.json Output Format
{
"createdOn": "2026-02-13T18:52:00.000000Z",
"runtime": "python3",
"model": {
"modelName": "my_model",
"serializedFile": "model.pt",
"handler": "handler.py",
"modelVersion": "1.0"
},
"archiverVersion": "0.9.0"
}
Usage Examples
Example 1: Creating a Manifest
from model_archiver.manifest_components.manifest import Manifest, RuntimeType
from model_archiver.manifest_components.model import Model
# Create model metadata
model = Model(
model_name="text_classifier",
serialized_file="model.pt",
handler="handler.py",
model_version="1.0"
)
# Create manifest with Python3 runtime
manifest = Manifest(runtime=RuntimeType.PYTHON3, model=model)
# Serialize to dict for JSON output
manifest_dict = manifest.__to_dict__()
Example 2: Manifest Serialization
import json
from model_archiver.manifest_components.manifest import Manifest, RuntimeType
from model_archiver.manifest_components.model import Model
model = Model(model_name="dlrm", serialized_file="dlrm.pt", handler="dlrm_handler.py")
manifest = Manifest(runtime=RuntimeType.PYTHON3, model=model)
# Convert to JSON string
json_str = str(manifest)
# Or serialize to dict and write
with open("MANIFEST.json", "w") as f:
json.dump(manifest.__to_dict__(), f, indent=4)
Related Pages