Model Serialization - krishanth7/EveryO GitHub Wiki

Model Serialization

EveryO โ€” Secure Model Persistence, Checkpointing & Interoperability

Save ยท Inspect ยท Restore ยท Verify ยท Deploy

Python EveryO Format License

A comprehensive guide to saving, loading, inspecting, validating, and exporting EveryO machine learning models.

Home ยท Model Training ยท API Reference ยท Examples and Tutorials


Maintained By & Owner: EveryO Contributors & @krishanth7

Important

API Compatibility

This guide describes the serialization interfaces inspected in EveryO's repository source.

The native format is .evo, with a JSON architecture manifest and NumPy parameter data. Examples should be tested against the installed version before production deployment.


Table of Contents

  1. Overview
  2. Serialization Architecture
  3. Native .evo Format
  4. Public Serialization API
  5. Saving a Model
  6. Loading a Model
  7. State Dictionaries
  8. Architecture Reconstruction
  9. Metadata and Manifests
  10. Archive Inspection
  11. Model Checkpointing
  12. Restoring Training
  13. Model Version Compatibility
  14. Artifact Integrity
  15. Security Considerations
  16. ONNX Export
  17. ONNX Compatibility
  18. Model Deployment
  19. Complete Serialization Example
  20. Testing and Verification
  21. Troubleshooting
  22. Best Practices
  23. Developer References
  24. Next Steps

1. Overview

Model serialization converts a trained model into a persistent artifact that can be stored, transferred, inspected, and restored.

EveryO provides a native model format designed to preserve model architecture, parameters, registered buffers, and metadata.

1.1 Core Objectives

  • Preserve trained model parameters.
  • Reconstruct supported model architectures.
  • Store model metadata.
  • Support checkpointing.
  • Verify model restoration.
  • Enable model portability.
  • Avoid Python pickle-based model loading.

1.2 Serialization Components

Component Purpose
save() Write model archive
load() Restore model
build_manifest() Build model metadata
load_manifest() Read archive manifest
inspect_archive() Summarize stored model
state_dict() Extract parameter and buffer state
load_state_dict() Restore state
export_onnx() Export supported models to ONNX

2. Serialization Architecture

2.1 Saving Pipeline

                  EveryO Model
                       |
                       v
                 Model.state_dict()
                       |
                       v
                Parameter Arrays
                       |
                       +------------------+
                       |                  |
                       v                  v
               Model Architecture     Model Metadata
                       |                  |
                       +---------+--------+
                                 |
                                 v
                          .evo Archive
                                 |
                                 v
                          Persistent File

2.2 Loading Pipeline

                    .evo Archive
                         |
                         v
                    Read Manifest
                         |
                         v
                 Validate Format Version
                         |
                         v
                 Load NumPy Parameters
                         |
                         v
                 Reconstruct Architecture
                         |
                         v
                    Restore State
                         |
                         v
                    Evaluation Mode
                         |
                         v
                     Ready Model

3. Native .evo Format

EveryO uses .evo as its native model archive suffix.

3.1 Archive Structure

The archive is ZIP-based and contains two members:

model.evo
โ”‚
โ”œโ”€โ”€ manifest.json
โ”‚
โ””โ”€โ”€ parameters.npz

3.2 Components

File Description
manifest.json Architecture, format version, metadata, parameter descriptions
parameters.npz NumPy arrays containing parameters and persistent buffers

3.3 Format Constants

The inspected implementation defines:

FORMAT_VERSION = 1

MANIFEST_NAME = "manifest.json"

PARAMETERS_NAME = "parameters.npz"

DEFAULT_SUFFIX = ".evo"

3.4 Design Characteristics

  • Structured metadata.
  • NumPy numerical storage.
  • Architecture reconstruction through registered classes.
  • No Python pickle required.
  • Versioned archive format.

4. Public Serialization API

4.1 Main Functions

import everyo as eo

eo.save
eo.load
eo.build_manifest
eo.load_manifest
eo.inspect_archive

4.2 Save Signature

save(
    model,
    path,
    *,
    metadata=None,
    overwrite=True
)

4.3 Load Signature

load(
    path,
    *,
    model=None,
    strict=True
)

4.4 Return Types

Function Return
save() Written Path
load() Restored Module
build_manifest() Dictionary
load_manifest() Dictionary
inspect_archive() Summary dictionary

5. Saving a Model

5.1 Basic Example

from pathlib import Path
import everyo as eo

model = eo.Sequential(
    eo.Linear(4, 8, seed=0),
    eo.ReLU(),
    eo.Linear(8, 2, seed=1)
)

path = eo.save(
    model,
    "artifacts/model.evo"
)

print("Saved:", path)

5.2 Automatic Extension

When the destination has no suffix, EveryO appends .evo.

eo.save(model, "artifacts/model")

The resulting file is:

artifacts/model.evo

5.3 Saving Metadata

eo.save(
    model,
    "artifacts/model.evo",
    metadata={
        "experiment": "classification-v1",
        "epoch": 20,
        "validation_accuracy": 0.92,
        "dataset_version": "2026-10"
    }
)

The metric value above is illustrative, not a measured EveryO result.

5.4 Prevent Overwriting

eo.save(
    model,
    "artifacts/model.evo",
    overwrite=False
)

If the destination already exists, the implementation raises a serialization error.


6. Loading a Model

6.1 Basic Example

import everyo as eo

model = eo.load(
    "artifacts/model.evo"
)

print(type(model).__name__)

6.2 Restore into an Existing Model

model = eo.Sequential(
    eo.Linear(4, 8, seed=10),
    eo.ReLU(),
    eo.Linear(8, 2, seed=11)
)

restored = eo.load(
    "artifacts/model.evo",
    model=model
)

When model is supplied, the loader uses the existing architecture and restores its state.

6.3 Strict Loading

restored = eo.load(
    "artifacts/model.evo",
    strict=True
)

Strict loading requires matching state names.

Shape compatibility must also be satisfied.

6.4 Evaluation Mode

The inspected load() implementation calls:

model.eval()

before returning the model.

To continue training, switch back to training mode:

model.train()

7. State Dictionaries

A state dictionary maps parameter and buffer names to NumPy arrays.

7.1 Extract State

state = model.state_dict()

for name, array in state.items():
    print(name, array.shape)

7.2 Restore State

model.load_state_dict(
    state,
    strict=True
)

7.3 What Is Stored?

The inspected Module.state_dict() implementation includes:

  • Named parameters.
  • Registered persistent buffers.

Buffers may include running statistics used by certain layers.

7.4 Why Buffers Matter

A model with normalization layers may require running statistics to reproduce inference behavior.

Restoring weights without those buffers can change predictions.

7.5 State Dictionary Versus Full Archive

State Dictionary .evo Archive
Parameter and buffer arrays Parameters and buffers
Requires an existing model for restoration Can reconstruct registered architectures
In-memory Python mapping Persistent ZIP-based file
No archive metadata by itself Includes JSON manifest

8. Architecture Reconstruction

EveryO reconstructs model classes using a registry.

8.1 Registry Mechanism

Manifest Class Name
        |
        v
   Module Registry
        |
        v
 Registered Module Class
        |
        v
     from_config()
        |
        v
 Reconstructed Model

8.2 Module Configuration

The base module supports:

model.get_config()

and:

ModelClass.from_config(config)

8.3 Custom Modules

Custom module types must be registered and provide sufficient configuration information for reconstruction.

The source provides a registration decorator:

from everyo.nn.module import register_module

8.4 Important Limitation

A custom module cannot necessarily be reconstructed automatically unless:

  • Its class is registered.
  • Its configuration can recreate the architecture.
  • The required class implementation is available.
  • Its saved state matches the reconstructed module.

9. Metadata and Manifests

The manifest describes the saved model.

9.1 Manifest Structure

A representative structure is:

{
  "format_version": 1,
  "everyo_version": "0.2.0",
  "created_at": "2026-10-15T00:00:00+00:00",
  "architecture": {
    "class_name": "Sequential",
    "config": {}
  },
  "parameters": {
    "parameter_name": {
      "shape": [4, 8],
      "dtype": "float32"
    }
  },
  "num_parameters": 58,
  "metadata": {
    "experiment": "classification-v1"
  }
}

This is a structural illustration, not an exact manifest generated from a particular model.

9.2 Generate Manifest

manifest = eo.build_manifest(
    model,
    metadata={
        "project": "EveryO",
        "stage": "evaluation"
    }
)

print(manifest)

9.3 Read Manifest

manifest = eo.load_manifest(
    "artifacts/model.evo"
)

print(manifest["format_version"])
print(manifest["architecture"])

9.4 Metadata Restrictions

Metadata must be JSON-serializable.

Use:

  • Strings.
  • Numbers.
  • Booleans.
  • Lists.
  • Dictionaries.
  • Null values.

Convert unsupported objects before saving.


10. Archive Inspection

EveryO provides an inspection function that reads model metadata without reconstructing the model.

10.1 Example

import everyo as eo

information = eo.inspect_archive(
    "artifacts/model.evo"
)

print(information)

10.2 Inspection Fields

The inspected implementation returns:

Field Description
path Archive path
everyo_version Saving framework version
format_version Archive format version
created_at Creation timestamp
class_name Model class
num_parameters Model parameter count
parameters Parameter and buffer descriptions
metadata User-defined metadata

10.3 Example

info = eo.inspect_archive(
    "artifacts/model.evo"
)

print("Class:", info["class_name"])
print("Parameters:", info["num_parameters"])
print("Version:", info["everyo_version"])

11. Model Checkpointing

Checkpointing saves a model during training.

11.1 ModelCheckpoint API

The inspected constructor is:

ModelCheckpoint(
    path,
    *,
    monitor="val_loss",
    mode="min",
    save_best_only=True
)

11.2 Example

checkpoint = eo.ModelCheckpoint(
    "checkpoints/best-model.evo",
    monitor="val_loss",
    mode="min",
    save_best_only=True
)

11.3 Trainer Integration

history = trainer.fit(
    train_loader,
    epochs=50,
    validation_loader=val_loader,
    callbacks=[checkpoint]
)

This example assumes the model, trainer, and loaders have already been configured.

11.4 Checkpoint Behavior

With save_best_only=True, the callback saves when the monitored metric improves.

With save_best_only=False, it saves at every epoch to the configured destination, replacing the previous file.

11.5 Checkpoint Metadata

The callback includes the epoch and available training metrics in the saved metadata.


12. Restoring Training

Restoring a model for inference is different from resuming training exactly.

12.1 Model Restoration

model = eo.load(
    "checkpoints/best-model.evo"
)

model.train()

12.2 Important Limitation

The native model archive preserves model state and metadata, but the inspected save() implementation does not serialize the optimizer's internal state.

Therefore, loading a model and creating a new optimizer is not necessarily equivalent to resuming the original optimization process.

12.3 Exact Training Continuation

A fully resumable training checkpoint may require:

  • Model state.
  • Optimizer state.
  • Scheduler state.
  • Epoch and step counters.
  • Random generator state.
  • DataLoader progression.
  • Training configuration.

Do not assume that a native .evo model archive contains all of these components.


13. Model Version Compatibility

The archive stores a format version and the saving EveryO version.

13.1 Format Version

The inspected format version is:

FORMAT_VERSION = 1

13.2 Loading Newer Archives

The loader rejects archives whose format version is newer than the implementation supports.

13.3 Compatibility Considerations

  • Framework version.
  • Archive format version.
  • Registered module availability.
  • Architecture configuration.
  • Parameter names.
  • Parameter shapes.
  • Numerical dtype compatibility.

13.4 Recommended Policy

For production artifacts:

  1. Record the framework version.
  2. Record the source commit.
  3. Retain a compatible runtime environment.
  4. Test restoration before deployment.
  5. Validate predictions after upgrades.

14. Artifact Integrity

Artifact integrity checks detect unintended changes or corruption.

14.1 SHA-256 Verification

A SHA-256 digest can identify whether a file's bytes have changed.

import hashlib
from pathlib import Path

def sha256_file(path):
    digest = hashlib.sha256()

    with Path(path).open("rb") as handle:
        for chunk in iter(
            lambda: handle.read(1024 * 1024),
            b""
        ):
            digest.update(chunk)

    return digest.hexdigest()

print(
    sha256_file("artifacts/model.evo")
)

14.2 Important Distinction

A hash detects changes when compared with a trusted expected hash.

It does not establish who created the artifact.

14.3 Recommended Controls

  • Trusted artifact storage.
  • Access controls.
  • Versioned releases.
  • Integrity verification.
  • Backups.
  • Audit records.

15. Security Considerations

EveryO's native serialization avoids Python pickle-based model reconstruction.

15.1 Source-Level Safeguards

The inspected implementation:

  • Stores architecture descriptions as JSON.
  • Uses NumPy arrays for state.
  • Loads NumPy data with allow_pickle=False.
  • Resolves model classes through a registration mechanism.
  • Rejects unsupported future format versions.

15.2 Security Boundaries

Avoiding pickle reduces arbitrary code-execution risks associated with deserialization.

It does not eliminate all risks associated with malicious files, including oversized archives, excessive resource consumption, or vulnerabilities in dependencies.

15.3 Recommended Practices

  • Accept models only from trusted sources.
  • Verify artifact integrity.
  • Enforce file size limits.
  • Keep dependencies updated.
  • Use isolated environments for untrusted artifacts.
  • Restrict artifact write permissions.
  • Avoid storing credentials in metadata.

16. ONNX Export

EveryO includes ONNX interoperability utilities.

16.1 Available APIs

eo.export_onnx
eo.export_onnx_traced
eo.onnx_available
eo.run_onnx

16.2 ONNX Availability

import everyo as eo

print(
    "ONNX available:",
    eo.onnx_available()
)

16.3 Install Optional Dependency

python -m pip install "everyo[onnx]"

16.4 Export Signature

Inspect the installed exporter before using it:

import inspect
import everyo as eo

print(
    inspect.signature(eo.export_onnx)
)

16.5 Export Strategies

EveryO provides two export approaches:

Exporter Approach
export_onnx Layer-based graph construction
export_onnx_traced Operation tracing

The appropriate exporter depends on the model architecture and supported operations.


17. ONNX Compatibility

The inspected layer-based ONNX exporter supports these layer types:

  • AvgPool2D
  • BatchNorm1D
  • BatchNorm2D
  • Conv2D
  • Dropout
  • Flatten
  • LayerNorm
  • Linear
  • LogSoftmax
  • MaxPool2D
  • ReLU
  • Sequential
  • Sigmoid
  • Softmax
  • Tanh

17.1 ONNX Opset

The inspected default opset is:

DEFAULT_OPSET = 17

17.2 Image Layout

EveryO uses NHWC image layout for relevant operations.

ONNX convolution and pooling operators use NCHW conventions.

The exporter handles required layout conversions for supported layers.

17.3 Limitations

Not every EveryO model can be exported using the layer-based exporter.

Recurrent, attention, and transformer architectures may require operation tracing.

Successful export does not guarantee identical behavior on every downstream runtime.

17.4 Validation

Compare predictions between:

  • The original EveryO model.
  • The exported ONNX model.
  • The target inference runtime.

Use numerical tolerances appropriate to the model and precision.


18. Model Deployment

A deployment-ready artifact should include more than model weights.

18.1 Recommended Package

model-release/
โ”‚
โ”œโ”€โ”€ model.evo
โ”œโ”€โ”€ manifest.json
โ”œโ”€โ”€ preprocessing.json
โ”œโ”€โ”€ metrics.json
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ checksums.sha256
โ””โ”€โ”€ README.md

This is a recommended external release structure, not the internal layout of an .evo archive.

18.2 Deployment Requirements

  • Compatible runtime.
  • Validated model artifact.
  • Input schema.
  • Preprocessing configuration.
  • Output schema.
  • Performance requirements.
  • Error handling.
  • Monitoring.

18.3 Production Considerations

Document:

  • Model purpose.
  • Supported inputs.
  • Expected outputs.
  • Known limitations.
  • Validation results.
  • Resource requirements.
  • Rollback procedure.

19. Complete Serialization Example

This example saves a model, inspects its archive, reloads it, and verifies output consistency.

19.1 Full Example

from pathlib import Path

import numpy as np
import everyo as eo

# ---------------------------------
# 1. Create a model
# ---------------------------------

model = eo.Sequential(
    eo.Linear(4, 8, seed=0),
    eo.ReLU(),
    eo.Linear(8, 2, seed=1)
)

# ---------------------------------
# 2. Create input data
# ---------------------------------

x = eo.tensor([
    [0.2, 0.4, 0.6, 0.8]
])

# ---------------------------------
# 3. Generate reference output
# ---------------------------------

model.eval()

with eo.no_grad():
    original_output = model(x).numpy()

# ---------------------------------
# 4. Save model
# ---------------------------------

artifact_path = Path(
    "artifacts/classifier.evo"
)

eo.save(
    model,
    artifact_path,
    metadata={
        "project": "EveryO",
        "purpose": "serialization-demo",
        "version": 1
    }
)

# ---------------------------------
# 5. Inspect archive
# ---------------------------------

info = eo.inspect_archive(
    artifact_path
)

print("Model class:", info["class_name"])
print("Parameter count:", info["num_parameters"])

# ---------------------------------
# 6. Restore model
# ---------------------------------

restored_model = eo.load(
    artifact_path
)

# ---------------------------------
# 7. Generate restored output
# ---------------------------------

with eo.no_grad():
    restored_output = restored_model(x).numpy()

# ---------------------------------
# 8. Verify results
# ---------------------------------

np.testing.assert_allclose(
    original_output,
    restored_output,
    rtol=1e-6,
    atol=1e-7
)

print("Serialization round-trip verified.")

19.2 Expected Behavior

The example should:

  1. Create a model.
  2. Produce a reference prediction.
  3. Save an .evo archive.
  4. Read archive metadata.
  5. Restore the architecture and parameters.
  6. Compare predictions.

The final verification message should appear if the round-trip outputs satisfy the specified numerical tolerances.


20. Testing and Verification

20.1 Run Tests

python -m pytest

20.2 Recommended Test Cases

  • Save and load a linear model.
  • Save and load a sequential model.
  • Preserve parameter values.
  • Preserve registered buffers.
  • Preserve supported metadata.
  • Reject malformed archives.
  • Reject unsupported format versions.
  • Reject unregistered architecture classes.
  • Verify strict state loading.
  • Compare inference results before and after restoration.

20.3 Round-Trip Test

import numpy as np

original_state = model.state_dict()
restored_state = restored_model.state_dict()

assert original_state.keys() == restored_state.keys()

for name in original_state:
    np.testing.assert_allclose(
        original_state[name],
        restored_state[name]
    )

21. Troubleshooting

Model file not found

Verify the path and filename.

If the original save path omitted a suffix, check for the automatically appended .evo extension.

Unknown module type

The architecture may reference a class that is not registered in the loading environment.

Ensure the required module implementation is available and registered.

Parameter names or shapes do not match

Verify that the target model architecture matches the saved state.

Use strict loading when exact state compatibility is required.

Archive format version is unsupported

The archive may have been produced by a newer EveryO release.

Use a compatible framework version.

Model outputs differ after loading

Check evaluation mode, preprocessing, input dtype, restored buffers, numerical precision, and backend differences.

ONNX export fails

Confirm optional dependencies are installed and that the model uses supported layers or traceable operations.


22. Best Practices

22.1 Serialization Checklist

  • Save the correct model state.
  • Include useful metadata.
  • Record the framework version.
  • Record model configuration.
  • Validate the archive.
  • Verify restored predictions.
  • Store preprocessing configuration.
  • Maintain artifact checksums.
  • Restrict access to production artifacts.
  • Test compatibility after upgrades.

22.2 Recommended Artifact Naming

project-model-version.evo

Example:

everyo-classifier-v1.evo

22.3 Production Release Policy

For each model release:

  1. Complete training.
  2. Evaluate the model.
  3. Save the artifact.
  4. Inspect metadata.
  5. Verify restoration.
  6. Run inference regression tests.
  7. Record a trusted checksum.
  8. Publish to controlled artifact storage.
  9. Monitor deployment behavior.

23. Developer References

Resource Link
EveryO Repository GitHub
Serialization Package serialization/
Save Implementation save.py
Load Implementation load.py
Archive Format format.py
ONNX Export onnx_export.py
ONNX Tracing onnx_trace.py
Module Implementation module.py
Training Callbacks callbacks.py
Issues GitHub Issues

24. Next Steps

Continue exploring EveryO's advanced engineering documentation.

Page Focus
Performance Optimization Profiling, benchmarking, and efficiency
Model Training Training workflows and callbacks
Data Pipeline Dataset management
API Reference Public Python APIs
Contributing Open-source development

Wiki links become active after the corresponding pages are created.


Model Serialization โ€” Documentation Prepared

Next Recommended Page: Performance Optimization โ†’

Home ยท Model Training ยท Data Pipeline ยท API Reference


EveryO โ€” Open Machine Learning. Built for Developers.

Maintained By & Owner:
EveryO Contributors & @krishanth7

Open Source ยท MIT Licensed ยท Community Driven

ยฉ 2026 EveryO Contributors

โš ๏ธ **GitHub.com Fallback** โš ๏ธ