Docs · Compile a model
Compile a model
From an ONNX file to a .wired.json, checked against the float model. In your browser or over HTTP.
Wired compiles multilayer perceptrons: dense layers with ReLU between them. That covers most small classifiers and game policies. Export your network to ONNX (torch.onnx.export, skl2onnx or tf2onnx), then compile it in one of two ways.
In your browser
Open Deploy and drop the .onnx. Give the range of your real inputs, optionally your labels, a calibration set and a test set as .npy, and compile. Nothing is uploaded: the compiler runs in the page. You can save the .wired.json or deploy it right away.
Over HTTP
curl -X POST https://www.usewired.net/api/v1/compile \
-F model=@model.onnx \
-F inputMin=0 -F inputMax=1 \
-F calib=@x_train.npy \
-F testX=@x_test.npy -F testY=@y_test.npy \
-F labels=cat,dog \
-F shape=28x28 \
-o compiled.json| Field | What it does |
|---|---|
model | The .onnx file. Required. |
inputMin, inputMax | Range of your real inputs. Wired maps it to int8: x_int8 = round(x / scale). Required, or inputScale. |
inputScale | The scale itself, instead of a range. |
calib | .npy of real inputs used to pick the scale of each hidden layer. Use a few thousand rows. Without it, Wired calibrates on random inputs and int8 accuracy usually drops. |
testX, testY | .npy inputs and classes. Measures float accuracy, int8 accuracy and how often both agree. |
labels | One label per output, comma-separated. Published onchain with the model. |
shape | The logical shape of the input, like 28x28, for UIs. |
name, description | Published onchain with the model. |
The answer:
{
"id": "0x018d404e…e3d1",
"registered": false,
"layers": [[64, 48], [48, 32], [32, 10]],
"params": 5018,
"blobs": 1,
"metrics": { "floatAccuracy": 0.96, "int8Accuracy": 0.965, "agreement": 0.995, "testSamples": 200 },
"model": { "format": "wired-mlp-v1", "…": "…" }
}id is the id the model will have onchain: it only depends on the weights. model is the .wired.json. Send the whole answer to POST /deploy.
Try it with the digits example: digits.onnx, calib.npy, x_test.npy, y_test.npy. Its inputs range from 0 to 16.
What the ONNX graph may contain
Gemm, or MatMul + Add, with Relu between layers. Flatten, Cast, Reshape and Identity are ignored. Parsing stops at Softmax or ArgMax: they do not change the winning class. Arrays in .npy can be float32, float64, int64, int32, int8 or uint8.
What changes in int8
Weights are scaled per layer to [-127, 127]. Activations are requantized after each layer with a multiplier and a shift picked from the calibration set (99.9th percentile). On the 8×8 digits model the int8 network gives the same answer as the float one on 99.5 % to 100 % of the test set.
Limits
| Limit | |
|---|---|
| Neurons per layer | 65,535 |
| Inputs | one int8 per value |
| Model size per call | about 3 million weights (a 32M gas transaction) |
| Layers | dense + ReLU (convolutions: on the roadmap) |
Upload to /compile | 4.5 MB in total. Compile bigger models in the browser on Deploy. |