Engineering · AI · Infrastructure

Moving the AI Humanizer to Serverless GPUs: 91 Seconds to Under 2

13 min read

How we served our detector and humanizer from GPUs we pay for by the second, and took a cold start from four minutes to a few seconds


A 228-word essay went into the humanizer at 9:58 one morning. The answer came back 91 seconds later. Seven minutes earlier, a 111-word one had taken 44. Both did what they were asked: two of three paragraphs rewritten, the detector's score down to 41 from 75 and 96. They were just slow, and the slowness had a pattern. In two days of logs, the two rewrites that changed something took 44 and 91 seconds, and the ten that changed nothing came back in one or two.

Nobody had complained, for a simple reason: almost nobody had waited. The humanizer is not announced yet, and over the last 60 days it ran between zero and four paid rewrites a week. That is also why fixing it could not mean renting a big machine.

This post is about the inference stack, the part of Cereby that runs our own models: the AI detector, the humanizer's rewriter, and the verifier that checks a rewrite still says what the original did. We moved all three off one small CPU server and onto GPUs billed by the second, and measured the result on synthetic essays before any student saw it.

Where the 91 seconds went

The humanizer does not ask a model for one rewrite and hope. For each paragraph the detector still reads as AI, it asks the rewriter for several candidates, throws out the ones that fail our guards (numbers changed, quotes altered, the wrong length), scores the rest with the detector, and asks the verifier whether the best one kept the meaning. A paragraph only changes when a candidate clearly reads as more human.

On the old server all of that ran on the same few CPU cores, one paragraph at a time, two candidates at a time. The rewriter wrote at about ten tokens a second. Here is the 228-word essay, traced:

None of the steps was wrong. They were serial on hardware built for something else. The work is a textbook batch job: a dozen candidates, each a short paragraph, all wanting the same model at once. Our own training lab had already shown what a GPU does with that. When it trained the rewriter, it generated 64,000 rewrites in 49 minutes on a single mid-range GPU.

Why not just rent a GPU

The obvious fix is a GPU server that is always on. The cheapest one we found that could hold all three models was about $119 a month, before storage, and it would sit idle almost all the time. At a few rewrites a week, nearly every dollar would pay for waiting.

So we went the other way: a serverless GPU platform that starts a container when a request arrives, bills it by the second, and stops it after a minute with nothing to do. At our traffic that costs cents a month. The trade is the cold start, the time it takes to bring a container up from nothing, and that turned out to be most of the engineering.

The shape we landed on

One inference app, two services, both running the exact code the old server ran, so the rewrite engine, the guards and the detector's calibration did not change. Every model Cereby runs is served from this app; the old server is gone:

Rewrites go to a GPU. The rewriter runs in a model server built for batched generation, beside our service in the same container. The engine asks it for all of a paragraph's candidates in one request, and rewrites every paragraph side by side, so a three-paragraph essay becomes one batch of twelve. The detector and the verifier score those candidates on the same GPU, with no network hop between them.

Detection runs on a CPU, in the same app. A detector check takes about a quarter of a second on an ordinary CPU. Putting it on a GPU would only add a slower start, so it gets its own small CPU container in the inference app, billed by the second like the GPU, which starts faster and costs a small fraction as much.

Every answer says what it cost. Each response carries how long it ran, whether it started cold and what that came to in dollars. The app logs it and adds it to a monthly total, so we see what serving costs from our side and not only on the provider's invoice.

The old server is gone. It stayed as a backup while the new services ran for real: if the new service failed twice, the app sent the same request to the old one. Once cold starts fit inside the app's minute (below), nothing needed it, and we shut it down. The detector, the rewriter and the verifier are now served only from the inference app.

What we measured

We ran the new services on four synthetic essays, written for the test in the polished style the detector flags, at the same lengths as the slow production rewrites. The essays are synthetic; the timings are what the service returned.

Getting the benchmark to start at all took two fixes. The service reads its API key from a secret, and the benchmark runs without one, so we attached the secret only when a flag was set. The flag was set on the machine that launched the run, not inside the containers. The platform matches a function's attachments by position, saw a different list on each side, and refused to start every container. Baking the choice into the container's environment, so both sides read the same value, fixed it. Then the containers refused again, and this time we were glad: our service will not run without an API key at all, because an empty key would let anyone use the models. The benchmark now gets a random key that nobody holds, and a real deploy without its secret still fails closed.

Old CPU server (now shut down)GPU service, warm
Rewrite, about 110 words44 s (a real 111-word essay)0.6 to 1.2 s
Rewrite, about 215 to 280 words91 s (a real 228-word essay)1.1 to 1.9 s
Rewrite at the engine's maximum effortnot measured1.2 to 3.1 s
Four essays at onceone at a time2.8 s for all four
Detector checkabout 0.4 s (lab median)0.26 s median, on CPU
Cost of one warm rewritea share of a fixed monthly server$0.0002 to $0.0009
Starting from nothingalways running244 s at first; 5 to 9 s now

The detector needed one more check before we trusted it on new hardware. Its score is calibrated, so a 50 means the same thing to every student, and that calibration was fit on the old server's CPU in full precision. When we once tried a faster, lower-precision version, it moved 47 scores and flipped two labels. So the GPU detector runs at full precision too, and we compared it with the CPU one on 200 held-out test texts: the largest difference in probability was 0.000002, and not one score moved.

A cold start from 244 seconds to 6

The warm numbers were the easy part. The last row of that table took three rounds, and each one moved the problem somewhere new:

Compiling the same kernels on every start

The first full run took 230 seconds to become ready, and 140 of those went to the model server's own warm-up: compiling GPU kernels and capturing the steps it will repeat, so that each later step runs a little faster. On a container that lives for a minute after each burst of traffic, that looked like the wrong trade, so we turned the warm-up off.

The start barely moved: 227 seconds, then 224 on a second cold start. And warm rewrites got three to four times slower, 2.1 to 6.1 seconds where they had been under two. The log showed why. Our rewriter's design compiles some of its own GPU kernels the first time it runs, whatever the server is told, and every new container threw those kernels away and compiled them again. The cost was never the decision to compile. It was compiling the same thing on every start.

So the compiled kernels now live on a shared disk that outlives any one container, and the server compiles as it did before. The first container ever pays the four minutes and leaves its work behind. The next one loads instead of building: the step that had taken 114 seconds took 27, and the whole start fell from 244 seconds to 152, with warm rewrites back under two seconds. That was a 38% cut and still too long: the app gives a call a minute before it gives up, so a cold request fell back to the old server.

Restoring a container that has already started

Most of the 152 seconds was now the server loading itself and replaying the same warm-up. A container that has already started can be snapshotted, GPU memory included, and later containers restored from the snapshot, which skips both. That only works on a deployed service, so we measured it on a deployed test copy. Our own start, from the container running to the service being ready, went from 152 seconds to between 0.2 and 0.7.

Waiting for a free GPU

But most cold requests were still slow, and the time had gone somewhere new. With one kind of GPU allowed, six of seven cold starts waited between 1 and 12 minutes before our code ran at all: 64, 121, 198, 360, 361 and 717 seconds. The provider was looking for a free card of that kind, and we had seen the same wait before snapshots, from 8 seconds to 8 minutes. The snapshot removed our part of the cold start, and finding a GPU became the whole problem. No amount of tuning on our side changes that.

So the humanizer now accepts two kinds of GPU and asks for the larger one first. It costs about 30% more a minute, and the provider found one within seconds on almost every start. Each kind keeps its own snapshot, since a GPU's memory only restores onto the same kind of card.

BeforeAfter snapshots and a second GPU kind
Our own start inside the container152 s0.2 to 0.7 s
Cold rewrite of a 110-word essay152 s or more4.8 to 8.6 s on 8 of 9 cold starts; 31.7 s on the ninth
Warm rewrite, 215 words1.15 to 1.27 s0.77 to 0.88 s

It is still not always on. The ninth start waited 28 seconds for a card. And a deploy makes the old snapshots stale, so the first cold start on each kind of GPU after a deploy boots the whole way, about one and a half to three minutes. A short script now pays for those right after each deploy, starting the service cold until three starts in a row come back from a snapshot. After the production deploy it took five starts: one full boot of 93 seconds, then restores of 8.6, 6.1 and 6.0 seconds, with our own start at 0.2 to 1.1 seconds of that.

The app helps from the other side. It warms the GPU when a student opens the detector, before they press the button. It keeps the GPU warm while a check on screen reads as AI and the tab is in view, under a small monthly cap. And while a GPU is still starting, the rewrite sheet says so. A daily canary request checks that the whole path still works, for about two cents a day.

At 5 to 9 seconds, a cold rewrite now finishes well inside the minute the app allows, so nothing falls back to the old server any more, and we shut it down.

What this taught us

Batch work hides on serial hardware. Nothing in the old pipeline was slow on its own; it was a dozen small generations standing in line. The same model, asked for all of them at once, finished before the old one finished its first pair.

Cold starts are a budget too. Per-second billing made a GPU affordable at our traffic, and it moved the cost into the first request after a quiet spell. The obvious switch, skipping the compile, fixed neither the start nor the speed. What had to change was where the compiled work lives, and then a snapshot took our part of the start to under a second. After that, the slowest part was waiting for a free GPU, and the fix there was to accept a second kind of card, not to tune our own code.

Measure parity before you measure speed. The detector's whole value is that a score means the same thing tomorrow as today. Proving 200 identical scores took less than a minute of GPU time and settled the question for good.

What's next

With the old server shut down and model size no longer limited by a small CPU, a larger detector and a stronger rewriter are now possible, but first we are making the current ones better; bigger models are a later project.

All engineering posts