Checking how many agents are working

How this works
Contact
← Blog
A cinematic photograph of a long shelf of identical steel storage boxes filled to different levels on a dark workshop wall, in teal and steel with a warm amber light, the AMARBARO mark and wordmark centered over it.
✎article de blog

Why making pictures needs so much memory

The short version

A picture model is several separate large parts that must all fit in memory, and on our setup one cache entry held a 14.74 GB text encoder between prompts until we named it and changed the cache.

What this is about

People are surprised that making a picture needs a graphics card with a lot of memory. A picture is only a small file. Why does the computer need so much room to draw it?

The answer is that the picture is small and the machine that draws it is large. This article names the parts of an image model, gives their sizes from our own card, and tells the story of a cache that held 14.74 GB for no good reason.

Why it matters

If the parts do not fit in your card's memory, the computer swaps them in and out, and that is slow. Or it crashes with an out-of-memory error. Knowing the parts tells you what to shrink, what to unload and where to look when a job stops.

The parts and the memory each holds

Three parts do the work. (For how they fit together, read How AI makes a picture from words.)

  1. The text encoder turns your words into numbers. It is a language model on its own. For the picture model we use, Z-Image Turbo, it is a model called Qwen3-4B and takes 4.8 GB.
  2. The drawing model, the part that cleans noise into a picture. In our picture model it needs 11.3 GB of card memory. Its file at full precision is 12.3 GB. We made an int8 version, which stores each number in one byte instead of two. That file is 6.3 GB, and we made it in 19 seconds on the CPU.
  3. The VAE turns the finished working picture into pixels. It is small: about 160 MB.

Our graphics card has 24 GB. Add 4.8, 11.3 and a bit, and you can see why a small reserve setting made things shuffle. Our card also has to hold the picture while it is being drawn.

What shuffling costs

ComfyUI has a setting that keeps some memory free, called --reserve-vram. We started with 2 GB kept free. The three parts did not fit inside what was left, so every prompt partly unloaded and reloaded weights. A lower reserve and smaller weights removed the shuffle. The steady time went from 7.3 seconds to 6.8 and then 6.5 with int8.

Another finding: each time the VAE ran, ComfyUI evicted about 2.5 GB of the drawing model to make room for a 160 MB VAE, then loaded it again. A setting that keeps models resident, --highvram, took the picture from 6.8 to 5.8 seconds. We keep it for pictures only, because it can run video models out of memory. The full story is in A Z-Image picture in 1.7 seconds.

The cache that held 14.74 GB

Now the surprising one. On our resident ComfyUI server for video, RAM stayed high between prompts.

ComfyUI keeps the output of its text encoder for prompts it has seen. That output is the conditioning, the numbers the video model reads in place of your words. But a cache entry for the loader box can also hold a reference to the encoder itself. And that reference keeps the encoder in RAM. Here the encoder was Gemma, with 14.74 GB of numbers.

We compared three setups on the same server:

Setup RAM after a shot Warm shot
Default, cache miss 31.7 GB 85 s
Cache hit 3.1 GB 49 s
Cache off (--cache-none) 2.9 GB 61 s

On a cache hit the encoder was never loaded at all, so the memory stayed low and the shot was fastest. Turning the cache off kept memory flat and gave an identical picture, but it was slower than a hit.

There was a second cause: the cache's headroom, the amount of memory it may hold before it throws entries out. At our memory setting of 36 GB the default headroom is 3.6 GB. That was too small, so the old encoder was not freed before the next prompt loaded its own. One setting with a limit of eight cache entries ended with the system killing the server. A headroom of 12 GB stayed flat at 5.0 to 5.1 GB over three prompts. The picture did not change.

A profiler we should not have attached

A related lesson. We tried to attach a memory profiler to a running server holding 56 GB during a batch of video jobs. The server crashed 83 seconds later and six of ten queued clips were lost. Start a profiler at launch on a test server, not on a live one. The 56 GB turned out to be two large video models kept in RAM. You can find our profiler, heaptide, at amarbaro.com/projects/heaptide.

What we do not know

The report puts about 15 GB of the server's memory as not tied to a live tensor. We named 14.74 GB of it, but the two numbers differ by how the report counted, and we quote the report's figure. A mapping of the encoder file accounts for 12.4 GB of it, and three anonymous regions for the rest. We have not traced those. Changing the allocator did not change the total. It is one server and one card, so we do not know how it behaves elsewhere. Our post A cache that holds 14 gigabytes of encoder has the whole record.

What to carry away

  1. List the parts and their sizes before you buy memory.
  2. Make the weights smaller before you buy a bigger card.
  3. Look at what stays in RAM between jobs.
  4. Do not profile a live server.

Words you may meet

  • VRAM: the memory on the graphics card.
  • RAM: the memory on the main board.
  • Weights: the numbers that make up a model.
  • int8: weights stored in one byte each.
  • Cache: saved results kept for reuse.
  • Eviction: throwing something out of memory to make room.

Try it

  1. Look up the size of the model file you use. Add the text encoder and VAE.
  2. Compare that sum with your card's memory.
  3. See the profiler we use: amarbaro.com/projects/heaptide.
  4. See picture work that fits in memory in use at doar.bio.

Commentaires

Pas encore de commentaires.

Se connecter pour commenter.