# From research checkpoint to production-ready endpoint in an hour

> Source: <https://www.photoroom.com/inside-photoroom/automated-model-deployment-in-an-hour>
> Published: 2026-12-02 09:45:11.235706+00:00

**Recommendation:** Replace hand-written Dockerfiles and manual testing with deterministic, quality-gated deployment scripts, and reserve LLM assistance for judgement steps like porting research code to the inference endpoint.
More in the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

**TL;DR:** We automated the internal model deployment process. In **under an hour** the trained checkpoints are packaged, quantised, compiled and thoroughly tested, ready to serve our users.

At Photoroom, speed of iteration has always been one of the main tenets, a necessity in a market that’s getting faster every day. On the training side of things, these expectations were already met as new features and POCs were being produced in a matter of days. Getting the model into the hands of our users instead, was a manual, fault-prone procedure that could take anywhere from an afternoon to a week. On paper, deployment is the cheap step and that's exactly why it was ignored for so long, until it became the actual bottleneck.

So we automated it. Deterministic scripts for the mechanical steps: image building, cache capture and packaging, all identical every time. A Claude skill for the steps that need judgement such as reading the research code and rewriting it for the inference endpoint. Most importantly, every stage is quality-gated to make sure that a broken model is caught within minutes, often seconds, rather than after a rollout.

Deployment time of one of our models: from 2 days to 16 minutes for the plain PyTorch version, and from 1 week to 37 minutes for the compiled one (with a 2.06× speedup).

## Table of contents

## Anatomy and pain points of a manual deployment

In an ideal scenario, any model reaching production should go through our main optimisation pipeline: FP8 quantisation, TensorRT compilation and a [Triton](https://github.com/triton-inference-server/server) ensemble. This very efficient inference stack however, requires a slow and error-prone procedure involving the efforts of multiple people. As the number of deployments increased we decided the following: a researcher could deploy an unoptimised model following the manual procedure below; further optimisations would be applied only following a positive A/B test.

### Manual procedure

1. Write the LitServe API: wrap the research inference code in a [LitAPI](https://github.com/Lightning-AI/LitServe) class which decodes the request, runs the model and encodes the response.
2. Capture the environment: pick a base image, copy-paste the training-time dependencies into a Dockerfile and get the two to agree.
3. Build the image copying the checkpoint, HuggingFace cache and everything else the model needs inside it.
4. Test it: run a few real examples through the server to confirm it boots, answers and returns something sensible.
5. Push it: tag the image and push it to the registry.

The procedure is seemingly straightforward but hides some pitfalls that made both the researchers and the infrastructure team unhappy.

### What slowed researchers down

The researchers’ main complaint was iteration time. Moving around checkpoints of 40 GB and baking them inside the Docker image led to long edit-build-test cycles and any error or oversight easily compounded: one Qwen deployment became roughly six hours of iterate, build, fail, rebuild, almost entirely because each cycle was so long, not because any fix was hard.

Underneath the slowness sat the absence of any standard. Every Dockerfile was written by hand, usually adapted from a colleague's without a clear guide and some researchers outright defined it as “tribal knowledge”.

### What worried the infrastructure team

From an infrastructure point of view, the manual procedure was as inefficient as it was risky.

On one side, Docker was never designed to ship 40 GB layers: each layer is compressed at build time and decompressed at pull time, which caused unacceptably slow cold start times of up to 10 minutes.

On the other, the images were built and tested manually, so each of them had its own library versions and nothing guaranteed that two deployments were built the same way. Worse, nothing reliably checked that what was shipped still matched what had been researched, as there was no enforced contract between the research pipeline and the deployed one. One model we deployed was ignoring some of its input parameters; it took three days before anyone noticed the issue.

Both views are symptoms of the same underlying problem: a long loop with all the checks done at the end. The same missing dependency could cost seconds if caught while writing the Dockerfile, ten minutes if caught after a build, or an incident if caught in production. The part that follows focuses on shortening the loop and catching any mistake as early as possible.

## Designing an automated deployment: scripts first, a Claude skill only when necessary

The design rule behind the whole system is simple: every step of the pipeline defaults to a deterministic script and we give it the LLM treatment only if there is no other way around it. Automation you can trust is boring automation, while the “interesting” parts should be as few as possible.

Building the image, capturing a minimal HuggingFace cache, packaging weights, pushing to the registry have a single correct output, so every one of them is a make target: identical every run, no creative input, loud on failure.

Other things however can't be scripted and this is where a Claude skill helps. We built two: `/create-endpoint` reads the researcher's inference code and turns it into a server endpoint plus a test; `/quick-deploy` takes that endpoint to a tested image in the registry, working out where each set of model weights comes from (a checkpoint file or the Hugging Face cache), discovering which dependencies the base image is missing and deciding what does and doesn't belong in the image.

Ambiguity however, affects an agent the same way it affects a person: hand Claude a vague task and you can't expect the same behaviour twice. So the scripts-first instinct applies inside the judgement steps too: everything that can be fixed in advance, is. Endpoints are generated from templates whose blanks are an explicit, enumerated list (the skill fills slots and picks between pre-written variants, it doesn't compose code freely) and the genuinely delicate machinery lives one level further down, in shared base classes that fail loudly at import time if the generated file breaks their contract.

Two more decisions shaped the pipeline.

1. At deploy time the pipeline packages the checkpoint and a minimal, freshly-captured HuggingFace cache into compressed artifacts and uploads them to our own object storage; at runtime the pod downloads and mounts them alongside the container. The image shrinks to code and dependencies. The weights now arrive in about twenty seconds of parallel download instead of minutes of image pull, and a new pod serves in a couple of minutes.
2. We made the standard physically hard to avoid: one Dockerfile template, one shared base image family with the heavy dependencies pre-installed, and per-model additions reduced to a requirements file the pipeline itself generates. Nobody writes a Dockerfile from scratch anymore, which means nobody can get one subtly wrong.

### Quality gates: paying for mistakes at the cheapest price

The deployment pipeline and its gates. Top row: what runs, in order. Highlighted boxes: the gate after each step. Notes below: where each failure used to surface before the gate existed. Dashed box: optional step.

The chart above shows the pipeline gate by gate, in the order they fire during a real deployment. Every gate has the same job: take a failure that used to surface later (at push time, at pod boot, in production) and move it to an earlier stage. As for how the gates were selected: a few were common sense while most were simply hit head-on during real deployments. Below are two examples.

**A test with a known answer:** every endpoint is shipped with one input and the answer the research code gives for it. Before anything is built, the pipeline sends that input to the new server and checks that the same answer comes back. We added this gate after a model we had moved from research code answered every request in the correct format, with sensible numbers, but with two of its outputs swapped. A person checking the result would think that everything is fine, while the comparison with the known answer catches it without issues.

**A replay of real requests:** when recorded production requests exist for a feature, the pipeline selects a sample and sends it through the new model before the push. This gate matters most for compiled models, described further down, which tend to have a fixed range of image sizes. One of our models passed every check we ran by hand but the replay of 181 real requests then showed 13 failures: reference photos that were unusually tall or wide were outside the compilation range.

Everything else on the chart follows the same logic at lower stakes. Once every gate is green, the pipeline stops with a summary log for the researcher; after a final confirmation the produced artefacts (weights, cache and Docker image) are pushed ready to be used on production pods.

### Packaging: by hand versus the pipeline

The first ironing model is the cleanest comparison we have, because it was deployed both ways from the same checkpoint: by hand in February, and through the pipeline in June.

|  | By hand (February) | Pipeline (June) | 
|---|---|---|
| From first push to final image | Two days, four pushes | 43 minutes, one push | 
| Image in the registry | 50.8 GB | 6.7 GB | 
| Weights and cache | Baked into the image | 46 GB in two artifacts, downloaded next to the image | 
| A rebuild after an edit | ~10 minutes | 3 seconds | 
| New pod, from scheduled to serving | 6 minutes or more | 1.5 minutes | 

The bytes a new pod downloads barely changed, about 51 GB before and 53 after. What changed is that the weights no longer travel through Docker layers, so they download in parallel without decompression and an edit to the code no longer moves them at all. When we first rebuilt this model with the pipeline, we replayed it against the hand-built image and the outputs matched exactly.

The image that remains also travels faster. Its layers are compressed with zstd instead of gzip, the Docker default. In our tests the layers decompressed 3 to 7 times faster and were about 10% smaller.

Since the first deployment in April, more than 20 models have gone through the pipeline, in more than 60 image versions and with an average of 53 minutes for the end to end process. The manual procedure has not been used since.

## Compiling without a specialist

Everything so far gets a model to production as the researcher wrote it, in plain PyTorch. The second half of the work was to make that model fast.

Compiling a model used to be the job of one or two people who knew our inference stack. To hand it to the pipeline, we had to answer one question: what does a specialist know that a script does not?

Most of it is knowledge about the model family such as which inputs the network takes and how large they can get, which layers do not export as they are and what to replace them with. All of our features on FLUX.2 Klein share that knowledge, so we wrote it once in a base class that every endpoint of the family inherits. A new endpoint simply declares its adapter and a few sample prompts.

The rest is found by directly running the model. The LoRA is merged into the base weights, and the model is run on sample prompts at every image size we serve in production. From these recordings, and the size range declared in the base class, the pipeline builds one TensorRT engine per network with NVIDIA's [AITune](https://github.com/ai-dynamo/aitune).

Quantisation follows the same idea. Converting a network to FP8 needs the range of values at every layer, and measuring that is slow so we measured it once for the base model. For a new adapter the pipeline reuses those ranges, which is why the step takes under two minutes.

Then the pipeline checks its own work by rerunning every size, comparing the output with the uncompiled model, and measuring the speed.

**Note:** It’s important to take into account that inference optimisation is highly model-specific, which means that each model family will need a different treatment. The TensorRT + FP8 treatment we applied to FLUX.2 Klein does not work for Qwen architectures which instead simply see a call to torch.compile.

### One deployment, end to end

Here is one run from our deployment log. The model is our brush fixer, which repairs a defect in a generated product image, given a reference photo and a brushed mask. It is a LoRA adapter on FLUX.2 Klein, with a small auxiliary encoder and a DINOv3 backbone. This run also compiles the model: five networks become TensorRT engines, and the transformer is quantised to FP8.

Highlighted in blue: compilation-specific steps, 21 of the 37 minutes.

| Stage | Wall time | What the gate established | 
|---|---|---|
| Analyse the endpoint, check what the compile step needs | ~1 min | Every weight classified; FP8 available for this model | 
| Endpoint tests | 26 s | The endpoint loads, answers and returns a well-shaped image | 
| Build the image | 3.5 min | Code and dependencies only, no weights | 
| Quantise and compile the transformer | 5.5 min | An FP8 engine that covers every production aspect ratio | 
| Compile the other four networks | 10.5 min | VAE encoder and decoder, text encoder, DINOv3 | 
| Shape check and replay of 24 production requests | 4 min | 4/4 shapes; 24/24 requests answered; median similarity of 0.9921 with uncompiled PyTorch in the repaired region (SSIM, where 1 is identical) | 
| Cache capture | 2.5 min | A minimal Hugging Face cache: the base model without its transformer, and DINOv3 | 
| Benchmark, stage by stage | 1 min | 2.06× faster end to end than uncompiled PyTorch (one 1024×1024 image, 4 steps, H100) | 
| Packaging test | 1.5 min | Five engines loaded in the final image; three repair requests on real images answered | 
| Push image and upload artifacts | 3.5 min | Pushed content identical to the tested image | 
| Agent time between the steps | about 3 min |  | 
| Total | about 37 min |  | 

The times are for one GPU, with the steps one after the other. A second GPU can shorten the deployment further by running the compilations in parallel.

One of the things to highlight is the replay of production requests: before the push, the pipeline sent 24 recorded production requests through the compiled model and through the original PyTorch one and compared the two images. The compiled model gave almost the same result as the original: a median similarity of 0.9921, where 1 is identical. The shape check that runs with it tried each of the four image sizes we serve in production, and all four worked.

So where did the time go? The largest part went into compilation: 5.5 minutes to quantise and compile the transformer and 10.5 for the four smaller networks. The checks, from the replay to the packaging test, took another nine, and the push and upload 3.5. The human contribution was one approval, a quick check of the summary before anything becomes visible to others.

### Compilation: by hand versus the pipeline

The brush fixer is the cleanest comparison we have for compilation, because it was optimised both ways: by hand for our TensorRT stack and through the pipeline.

|  | By hand (May) | Pipeline | 
|---|---|---|
| Time to a compiled model that works | One week | About 37 minutes | 
| People | Two engineers | One, for one approval | 
| Speed against uncompiled PyTorch | 2.1× | 2.06× | 

The hand-tuned version is still slightly faster. The pipeline gets within a few percent of it in about half an hour, and it does so again for every new model of the family.

## What it does not do yet

- The parity gate is only as good as its reference. Comparing against the research code catches a bad port. It cannot catch a regression against what users get today. That needs a replay of production traffic, which exists for some features and has to be built for each new one.
- The compile step covers the model families we have described to it. Today that is FLUX.2 Klein. Other families take a different optimisation, or stay in plain PyTorch.

## Putting it together

| What we changed | What it improved | Measured | 
|---|---|---|
| Weights out of the image, into object storage | Image size, rebuild time, pod start | 50.8 to 6.7 GB; 10 minutes to 3 seconds; 6 minutes to 1.5 | 
| One template and one family of base images | No Dockerfile written by hand | More than 20 models | 
| A gate after each step | Errors found in minutes, not in production | The swapped outputs; 13 of 181 real requests | 
| The compile step inside the pipeline | Speed without a specialist | One week to 37 minutes; 2× faster than plain PyTorch | 

None of the individual pieces here is novel: weights in object storage, a shared base image, templates, a parity test. What made the difference is where they sit. Every check moved to the earliest point where it can fail, and judgement was confined to the few places that need it, then checked by a gate. A mistake that used to cost a rebuild or an incident now costs seconds or minutes, and that is what turned a two-day process into one that fits in an hour.
