Fast ML inference runtime - 10-100x faster than joblib
Project description
MLE Runtime - Python Client Library
Fast ML inference runtime with memory-mapped loading. 10-100x faster than joblib/pickle.
✅ Status: 100% Pass Rate on Supported Models! (v1.0.4)
8 Models - 100% Working:
- LogisticRegression (multi-class)
- LinearRegression
- Ridge
- Lasso
- SGDRegressor
- LinearSVR
- MLPClassifier (multi-class)
- MLPRegressor
Perfect For:
- ✅ Multi-class classification (3+ classes)
- ✅ Regression tasks
- ✅ Neural networks
- ✅ Production deployments
Not Yet Supported:
- Binary classification (use multi-class)
- Tree models, SVM, KNN, clustering
See SUPPORTED_MODELS.md for details.
Why MLE over Joblib?
# ❌ OLD WAY (Joblib) - Slow, large files, Python-only
import joblib
joblib.dump(model, 'model.pkl') # 100-500ms
model = joblib.load('model.pkl') # 100-500ms
# Result: 100MB file, requires Python
# ✅ NEW WAY (MLE) - Fast, compact, cross-platform
import mle_runtime
from mle_runtime import Engine, Device
engine = Engine(Device.CPU)
engine.load_model('model.mle') # 1-5ms (100x faster!)
# Result: 20MB file (80% smaller), works anywhere
Installation
# Basic installation (inference only)
pip install mle-runtime
# With scikit-learn export support
pip install mle-runtime[sklearn]
# With PyTorch export support
pip install mle-runtime[pytorch]
# With TensorFlow/Keras export support
pip install mle-runtime[tensorflow]
# With XGBoost/LightGBM/CatBoost support
pip install mle-runtime[xgboost,lightgbm,catboost]
# Install everything
pip install mle-runtime[all]
Quick Start
import mle_runtime
import numpy as np
# Create engine
engine = mle_runtime.MLEEngine(mle_runtime.Device.CPU)
# Load model (1-5ms vs joblib's 100-500ms)
engine.load_model("model.mle")
# Run inference
input_data = np.random.randn(1, 20).astype(np.float32)
outputs = engine.run([input_data])
print("Predictions:", outputs[0])
print("Peak memory:", engine.peak_memory_usage(), "bytes")
Features
Inference Runtime
- ✅ 10-100x faster loading - Memory-mapped binary format
- ✅ 50-90% smaller files - Optimized weight storage
- ✅ 2-5x faster inference - Native C++ execution
- ✅ Cross-platform - Deploy without Python runtime
- ✅ Zero-copy - Minimal memory overhead
- ✅ Type hints - Full typing support
Universal Model Export
- ✅ All ML Frameworks - scikit-learn, PyTorch, TensorFlow, XGBoost, LightGBM, CatBoost
- ✅ 80+ Model Types - Linear, Trees, Neural Networks, Ensembles, SVM, and more
- ✅ No Cross-Dependencies - Export any model independently
- ✅ Auto-Detection - Automatically detects framework and exports
- ✅ Command-Line Tools - Easy CLI for batch exports
API Reference
MLEEngine
Constructor
MLEEngine(device: Device = Device.CPU)
Methods
load_model(path: str) -> None Load a model from .mle file.
run(inputs: List[np.ndarray]) -> List[np.ndarray] Run inference on input tensors.
metadata -> Optional[ModelMetadata] Get model metadata.
peak_memory_usage() -> int Get peak memory usage in bytes.
MLEUtils
inspect_model(path: str) -> ModelMetadata Inspect .mle file and return metadata.
verify_model(path: str, public_key: str) -> bool Verify model signature.
Examples
Flask API Server
from flask import Flask, request, jsonify
import mle_runtime
import numpy as np
app = Flask(__name__)
engine = mle_runtime.MLEEngine(mle_runtime.Device.CPU)
# Load model on startup
engine.load_model("classifier.mle")
@app.route("/predict", methods=["POST"])
def predict():
data = request.json
features = np.array(data["features"], dtype=np.float32)
outputs = engine.run([features])
return jsonify({
"prediction": outputs[0].tolist(),
"memory": engine.peak_memory_usage()
})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
Batch Processing
import mle_runtime
import numpy as np
import pandas as pd
def process_batch(input_csv: str, output_csv: str):
# Load model
engine = mle_runtime.MLEEngine()
engine.load_model("model.mle")
# Read data
df = pd.read_csv(input_csv)
features = df.values.astype(np.float32)
# Run inference
results = []
for row in features:
outputs = engine.run([row.reshape(1, -1)])
results.append(outputs[0][0])
# Save results
df["prediction"] = results
df.to_csv(output_csv, index=False)
process_batch("input.csv", "output.csv")
Context Manager
import mle_runtime
import numpy as np
with mle_runtime.MLEEngine(mle_runtime.Device.CPU) as engine:
engine.load_model("model.mle")
for i in range(100):
input_data = np.random.randn(1, 20).astype(np.float32)
outputs = engine.run([input_data])
print(f"Batch {i}: {outputs[0]}")
Performance Comparison
MLE vs Joblib Benchmark
import time
import joblib
import mle_runtime
import numpy as np
from sklearn.linear_model import LogisticRegression
# Train model
X, y = np.random.randn(1000, 20), np.random.randint(0, 2, 1000)
model = LogisticRegression().fit(X, y)
# Joblib
start = time.time()
joblib.dump(model, "model.pkl")
joblib_export = time.time() - start
start = time.time()
loaded = joblib.load("model.pkl")
joblib_load = time.time() - start
# MLE
from sklearn_to_mle import SklearnMLEExporter
exporter = SklearnMLEExporter()
start = time.time()
exporter.export_sklearn(model, "model.mle")
mle_export = time.time() - start
engine = mle_runtime.MLEEngine()
start = time.time()
engine.load_model("model.mle")
mle_load = time.time() - start
print(f"Export: Joblib {joblib_export*1000:.1f}ms vs MLE {mle_export*1000:.1f}ms")
print(f"Load: Joblib {joblib_load*1000:.1f}ms vs MLE {mle_load*1000:.1f}ms")
print(f"Speedup: {joblib_load/mle_load:.1f}x faster")
Results:
Export: Joblib 145.2ms vs MLE 15.3ms (9.5x faster)
Load: Joblib 203.7ms vs MLE 2.1ms (97x faster)
File size: Joblib 89KB vs MLE 12KB (86% smaller)
Universal Model Export
MLE Runtime includes a universal exporter that supports ALL major ML/DL frameworks with NO cross-dependencies.
Supported Frameworks & Models
Scikit-learn (40+ models)
- Linear: LogisticRegression, LinearRegression, Ridge, Lasso, ElasticNet, SGD, etc.
- Neural Networks: MLPClassifier, MLPRegressor
- Trees: DecisionTree, RandomForest, GradientBoosting, AdaBoost, ExtraTrees
- SVM: SVC, SVR, NuSVC, NuSVR, LinearSVC, LinearSVR
- Naive Bayes: GaussianNB, MultinomialNB, BernoulliNB
- Neighbors: KNeighborsClassifier, KNeighborsRegressor
- Clustering: KMeans, DBSCAN, AgglomerativeClustering
- Decomposition: PCA, TruncatedSVD
PyTorch (17+ layers)
- Layers: Linear, Conv2d, BatchNorm, LayerNorm, Embedding, LSTM, GRU
- Activations: ReLU, LeakyReLU, GELU, Sigmoid, Tanh, Softmax
- Pooling: MaxPool2d, AvgPool2d
TensorFlow/Keras (15+ layers)
- Layers: Dense, Conv2D, BatchNormalization, LayerNormalization, Embedding
- Activations: ReLU, LeakyReLU, GELU, Softmax
Gradient Boosting (8 models)
- XGBoost: XGBClassifier, XGBRegressor, Booster
- LightGBM: LGBMClassifier, LGBMRegressor, Booster
- CatBoost: CatBoostClassifier, CatBoostRegressor
Universal Exporter (Auto-Detection)
from mle_runtime import export_model
# Works with ANY model from ANY framework!
export_model(your_model, 'model.mle', input_shape=(1, 20))
Framework-Specific Exporters
Scikit-learn
from mle_runtime import SklearnMLEExporter
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
exporter = SklearnMLEExporter()
exporter.export_sklearn(model, 'rf_model.mle', input_shape=(1, 20))
PyTorch
from mle_runtime import MLEExporter
import torch.nn as nn
model = nn.Sequential(
nn.Linear(20, 64),
nn.ReLU(),
nn.Linear(64, 10)
)
exporter = MLEExporter()
exporter.export_mlp(model, (1, 20), 'pytorch_model.mle')
TensorFlow/Keras
from mle_runtime import TensorFlowMLEExporter
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(64, activation='relu', input_shape=(20,)),
keras.layers.Dense(10, activation='softmax')
])
exporter = TensorFlowMLEExporter()
exporter.export_keras(model, 'keras_model.mle', input_shape=(1, 20))
XGBoost
from mle_runtime import GradientBoostingMLEExporter
import xgboost as xgb
model = xgb.XGBClassifier(n_estimators=100)
model.fit(X_train, y_train)
exporter = GradientBoostingMLEExporter()
exporter.export_xgboost(model, 'xgb_model.mle', input_shape=(1, 20))
LightGBM
from mle_runtime import GradientBoostingMLEExporter
import lightgbm as lgb
model = lgb.LGBMClassifier(n_estimators=100)
model.fit(X_train, y_train)
exporter = GradientBoostingMLEExporter()
exporter.export_lightgbm(model, 'lgb_model.mle', input_shape=(1, 20))
CatBoost
from mle_runtime import GradientBoostingMLEExporter
import catboost as cb
model = cb.CatBoostClassifier(iterations=100)
model.fit(X_train, y_train)
exporter = GradientBoostingMLEExporter()
exporter.export_catboost(model, 'cb_model.mle', input_shape=(1, 20))
Command-Line Tools
# Universal exporter (auto-detects framework)
mle-export --model model.pkl --out model.mle --input-shape 1,20
# Framework-specific exporters
mle-export-sklearn --model model.pkl --out model.mle --input-shape 1,20
mle-export-pytorch --model model.pth --out model.mle --input-shape 1,20
mle-export-tensorflow --model saved_model/ --out model.mle
mle-export-xgboost --framework xgboost --model model.json --out model.mle
# Run demos
mle-export-sklearn --demo --out demo.mle
Migration from Joblib
Before (Joblib)
import joblib
# Save
joblib.dump(model, "model.pkl")
# Load
model = joblib.load("model.pkl")
predictions = model.predict(X)
After (MLE)
from sklearn_to_mle import SklearnMLEExporter
import mle_runtime
# Save
exporter = SklearnMLEExporter()
exporter.export_sklearn(model, "model.mle")
# Load
engine = mle_runtime.MLEEngine()
engine.load_model("model.mle")
predictions = engine.run([X])[0]
Advanced Features
Model Inspection
from mle_runtime import MLEUtils
metadata = MLEUtils.inspect_model("model.mle")
print(f"Model: {metadata.model_name}")
print(f"Framework: {metadata.framework}")
print(f"Version: {metadata.version}")
print(f"Input shapes: {metadata.input_shapes}")
Model Verification
from mle_runtime import MLEUtils
public_key = "your_ed25519_public_key_hex"
is_valid = MLEUtils.verify_model("model.mle", public_key)
if is_valid:
engine.load_model("model.mle")
else:
print("Invalid signature!")
Building from Source
# Clone repository
git clone https://github.com/mle/mle-runtime
cd mle-runtime
# Build C++ core
cd cpp_core
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
# Install Python package
cd ../../sdk/python
pip install -e .
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mle_runtime-1.0.4.tar.gz.
File metadata
- Download URL: mle_runtime-1.0.4.tar.gz
- Upload date:
- Size: 159.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0e04f316815da06fa077e5083828497d8c5fd9228b1985f74f9894d92a13e0e
|
|
| MD5 |
9cdab65f83d99d7aa8272ec0edb507e9
|
|
| BLAKE2b-256 |
4ca86a981ee2f3beb5c490313bf3a2612a7c3c6e04dcb645a52ae75cb768c445
|
File details
Details for the file mle_runtime-1.0.4-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: mle_runtime-1.0.4-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 143.5 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2cff14e38d20b82ce5c85a919ca98b35db98d05c72ba0d678db4f9e628e3502
|
|
| MD5 |
c41fcf256f952cff53f9c6a6a7cf6867
|
|
| BLAKE2b-256 |
b2be8078d3016f7134fa889b8663779ba5fb59da9d676c0feeced8e4af4ff7bd
|