Examples
The examples are in https://github.com/belfortlabs/eml-examples. Each vX.Y.Z tag of the
repository pins them to that Belfort release. The paths below are relative to
its root:
git clone https://github.com/belfortlabs/eml-examples
cd eml-examplesquickstart/ holds the Quickstart's files as a standalone uv
project; its README has the steps.
The directories below hold trained models with their definitions and 2000 samples of test data each.
| Example | What it is | Input shape | Activations |
|---|---|---|---|
mlp |
A three-layer MLP classifying MNIST digits | (1, 1, 28, 28) |
squares |
lola |
The LoLA CNN on MNIST: one convolution block, then two linear layers | (1, 1, 28, 28) |
squares |
Each has <name>.py (the nn.Module), the trained model (<name>.pth), and
test_data.npz with the inputs under X and the labels under y.
Compiling one#
The .pth files hold whole pickled modules, so the example's own module has to
be importable when you load one. From the examples' root:
import sys
import numpy as np
import torch
import belfort_ml
sys.path.insert(0, "mlp")
net = torch.load("mlp/mlp.pth", weights_only=False).eval()
samples = np.load("mlp/test_data.npz")["X"][:512]
calibration = [torch.from_numpy(x).float().unsqueeze(0) for x in samples]
artifacts = belfort_ml.compile(
net, calibration[0], "mlp", "./build", calibration_inputs=calibration
)From there, upload it with
provider.models.get(name="mlp", create_from=artifacts) as provider.py does
in step 4 of the Quickstart. The end client passes each input as
a flat list: client.infer([samples[0].flatten().tolist()]) for the first test
image.