Neural network compiler, checked

Turn a neural network into C++ you can trust

ModelForge compiles a trained model into a standalone C++ program and tests every optimisation it makes before keeping it. It also checks whether a shrunk (8-bit, 4-bit or pruned) model still gives the same answers. Everything below runs in your browser.

1 · Compiler

Give it a model, get C++ back

Paste or upload a model in ModelForge's .mforge format, or pick a sample. The compiler checks it, optimises it with Guardian testing every rewrite, and writes the standalone C++ program. The code below is the same code the real C++17 compiler produces.

Compilation pipeline

    
          

    2 · Shrink lab

    Pick a real model, shrink it, and check it

    Eight classifiers trained on real data. Choose a compression and watch accuracy, then run the Guardian check to hunt for inputs close to real data where the two models disagree.

    Compression
    Weight size50%of float32
    Test accuracy-original
    Test-set flips-what most people check

    Guardian check

    not run yet

    Guardian walks between pairs of real samples that the original model classifies differently, finds where its decision changes, and checks whether the smaller model moved that boundary.

    Lines scanned0
    Boundary moved on0
    Model runs used0of 200 extra
    Worst realistic flip: how sure the original model was (0 = coin flip, 1 = certain)
    none yet

    3 · Try an input

    Draw a digit

    Draw on the 8 by 8 grid (the size of the Digits dataset). Both models predict as you draw. Then ask Guardian to find the closest drawing where the smaller model changes its answer.

    Original model
    -
    Smaller model (int4)
    -

    4 · How it works

    Boundary-shift probing in four steps

    The original model's decisions change at boundaries between classes. Compression moves those boundaries a little. Guardian measures how far, using very few runs of the smaller model.

    Pick two real samples

    Two test samples the original model puts in different classes, nearest pairs first.

    Find the original boundary

    Halve the line between them about 30 times to find exactly where the original's answer changes.

    Did it move?

    Two runs of the smaller model either side of that point show whether its boundary moved, and which way.

    Measure the gap

    Halve again to find the smaller model's boundary. The far edge of the gap is the worst disagreement on that line.

    Watch it search one line

    Dots are model runs: blue for the original's bisection, orange for the smaller model. The red band is where they disagree.

    Inside the compiler too

    The same idea guards ModelForge's own optimiser. Before keeping any rewrite (fusing layers, removing dead code), Guardian aims test inputs at the switching point of every ReLU neuron in the layers that changed, and rolls back the rewrite if any output differs. In a 96-model study it caught 99.2% of injected bugs, versus 75.0% for random inputs.

    Run it yourself

    Everything on this page runs in your browser. The C++ tool does the same on any model file:

    modelforge wine_mlp16.mforge --shrink all --data wine_test.csv

    5 · Results

    Measured on 40 compressed models

    8 networks trained on Iris, Wine, Breast Cancer and Digits, each compressed 5 ways. A compression is risky if there is a realistic input where the original is sure but the smaller model disagrees.

    Open the full research dashboard