Blog · · 10 min to read

We looked inside the open tools we use

model-maker is built on open-source tools. We checked whether problems we had measured come from them, and made public copies of four with fixes. The library we suspected of making folds was innocent. A memory fix saves 2.3 GB with identical answers, but a program we build ourselves answers a little differently.

model-maker stands on other people's work. The program that runs its AI judge, the library that runs its painting models, the code that turns a shape into triangles: all of them are open source. Anyone can read that code, and anyone can change their own copy of it. This week we asked a plain question. Some problems we had measured might not be ours at all. Could they be in those tools, and could we fix them there?

Three words first

Upstream. The original project a tool comes from, kept by its own maintainers. We are downstream: we use what they publish.

Fork. A copy of a project, kept by someone else, where changes can be made without touching the original. On GitHub a fork is public and says where it came from.

Pull request. A proposed change, sent to a project for its maintainers to review. They decide whether it goes in.

What we looked for

We listed the problems we had measured and could not explain in our own code. For each one, we read the tool's code, its open issues and the changes already under review. The short answer: most of our problems are in our own code. For the few that are in a tool, upstream already has a fix, or one under review.

We still made fixes, in four public forks, each with our change on its own branch and the original licence untouched:

Then we measured whether each fix helps model-maker. Here is what worked and what did not.

The folds were not where we looked

Folds are two triangles on the same three corners, facing opposite ways, like a sheet folded flat onto itself. model-maker has a repair step that removes them. We knew they were there; we did not know where they came from.

Our research suspected scikit-image. Its marching cubes, the step that draws a surface out of the shape model's numbers, has a known open bug: on an exact tie it can draw the same triangles twice. We fixed that tie in our fork. The fix is real: of 60,000 small random test shapes, 8 had duplicates before it and none after.

Then we counted where model-maker's folds actually appear. On 11 of our 24 test objects, the raw output of marching cubes had 0 folds in 12.5 million triangles. Our next step, which simplifies the shape down to about 60,000 triangles so it loads fast, made all 113. So the library we suspected was innocent. model-maker stays on the released scikit-image, and the fix stays in our fork.

A cleaner skin that moved

The same simplifying step also leaves very thin triangles. We wrote about the thin dark strokes they paint in Triangles too thin to paint; a fix there removed most of them, but not all. The simplifying library, meshoptimizer, has an option to keep triangles more even, called regularising. We did not need a fork for it: the option already exists.

On the same 11 objects, at the same number of triangles, the lighter of its two settings removed 98.5 % of the dark strokes and pale slivers, 1,019 down to 15. The tiny texture pieces of 1 to 3 triangles, where strokes come from, fell by 62 %. No check changed its verdict, and it was faster.

Two objects model-maker made, a projector and a wooden barrel, each shown from the front twice: simplified as shipped on the left and simplified with regularising on the right. Small magenta marks sit along the projector's grille and the barrel's hoops on the left; on the right there are fewer. Labels under them: projector, 655 strokes and slivers against 5; barrel, 36 against 0
The same stored objects, simplified two ways to the same number of triangles and painted again from the same paint. Magenta marks triangles in texture pieces of 1 to 3 triangles, where dark strokes come from.

But it moves the surface. We measure how far the simplified surface lies from the shape model's own surface, at the far end: the distance that 95 % of the surface stays within. Before anything ran, we wrote down a bar: on every object, that distance may be at most 1.5 times what today's simplifier gives. Regularising went past that on 5 of the 10 objects it simplified (one, a long spear, was already small enough to need no simplifying). The worst, a laptop, was 3.6 times as far.

In plain size, the move is small: at most about a thousandth of the object's size, and on the laptop we cannot see it. But a bar written first is not moved after the numbers come in. So regularising is not in model-maker now. We will come back to it in a later version, with a new plan and a bar argued for before a fresh run. These numbers are from the first 11 objects; the other 13 are not measured yet.

The judge's memory: half of what we hoped

Before model-maker builds an object, an AI judge checks the picture it painted. The judge runs in llama.cpp. When llama.cpp loads a model, it maps the model's file: the computer shows the file to the program as if it were in memory and reads pieces in as they are needed. Then llama.cpp copies many of the model's weights into a faster arrangement. Our research found that it keeps the file's original pages of those weights in memory as well. The same weights, held twice.

First try: a setting. llama.cpp can read the file instead of mapping it. The judge gave identical answers on 160 of 160 pictures and was a little faster. But its highest memory fell only from 9.5 to 7.4 GB, and the bar we had set was 6.5 GB. Inside a 12 GB limit it also had to push memory out to the disk. We dropped it.

Second try: a fix in our fork. We changed llama.cpp itself to let go of the file's pages once their weights have been copied. Against the same build without the fix, the answers were identical on 160 of 160 pictures, to the last digit, and the time was the same within 0.3 %.

A bar chart of the judge's highest memory in use while judging 160 pictures. Our build of llama.cpp as it came: 9.8 GB. The same build with our fix: 7.4 GB. A dashed line at 6.5 GB marks the goal we set first. The answers were identical on all 160
Two runs of the same build, with and without our fix, on the same 160 pictures. The fix gives back 2.3 GB but stops short of the goal.

It gave back 2.3 GB, and still missed 6.5 GB. The reason: about 3.2 GB of the judge's weights are never copied into the faster arrangement. Their only copy is the file itself, so there is nothing to let go of. The research's estimate had assumed otherwise. A measurement beat an estimate again.

A program we build answers differently

The second run held a surprise. model-maker uses llama.cpp as its makers publish it, already built. To test our fix, we built llama.cpp ourselves, from the same version of the code with the same settings, and only a newer compiler: the tool that turns code into a program.

Without any fix at all, our build did not answer like the published one. On all 160 pictures the judge's score moved a little, by 0.08 at most on a scale from 0 to 1, and on one picture its yes or no flipped. It was also 18.7 % faster. We have not traced why: the compiler is the only difference we know of. We saw the same thing with a different AI in Same AI, same question, different answers.

So the fix itself changes nothing, but using it means shipping a llama.cpp we built, and that is a new judge. A new judge has to pass its own test on our stored pictures, not just "same answers as before". The fix is not in model-maker now. It stays in our fork for the next time the judge changes.

The other two

diffusers. To fit a 12 GB card, model-maker keeps parts of the painting model in main memory, locked in place so the card can copy them fast. The library underneath, PyTorch, rounds each locked piece up to the next power of two. By our count from the model files, 6.3 GiB of weights take 8.2 GiB locked, 30 % more. Our fork can lock each group of parts in one piece of exactly the right size, and its 7 new tests pass. The same idea then went into model-maker's own code: since version 0.3.4, building the painter takes 2.7 GiB less of the computer's memory, and the pictures are identical, 58 of 58. model-maker still runs diffusers as released.

We also tried the change that diffusers itself has under review for the same cause. Its own tests pass on our card. In model-maker's painter it failed: it locks whole pages of memory around each weight, those pages also hold neighbouring parts, and the card then refuses to copy the neighbours. We did not adopt it, and we left a comment on that change with what we found.

MV-Adapter. When its camera looked exactly straight down or straight up, the direction it called "right" could flip. Our fix makes it the same from both sides, and its 5 tests pass. model-maker's cameras stop just short of straight up, so this was never on our path. We fixed it because we found it.

What we do next

None of the four forks is in a model-maker release today. That is the honest result of looking inside other people's code: one suspect was innocent, one setting cleaned the skin but moved it, one fix works but brings a new judge with it, and one idea went into model-maker's own code instead.

We are not sending pull requests now. llama.cpp and diffusers already have changes under review for the same causes, and meshoptimizer already has the option. On the diffusers change we have left one comment with what we measured. When model-maker uses a change that is under review upstream, we will add our measured numbers to it.

Words used