첫 소리 다음에 남은 것은 메모리였고, 메모리를 재는 자도 틀렸다
말로 대화하는 작은 기기를 만들고 있습니다. 머리는 맥북(M5, 24GB)에서 도는 로컬 모델이고, 보드가 오기 전이라 맥에서 받아쓰기와 답, 음성 합성을 이어 붙여 재고 있습니다. 앞 글에는 질문을 넘긴 뒤 첫 소리까지 가운데 값 1.48초가 나왔다고 적었습니다. 그 숫자만 보면 다 된 것 같았지만, 같은 날 남은 문제는 속도보다 메모리였습니다. 메모리를 재는 쪽도 두 번 틀렸습니다.
네 번 중 두 번이 3초를 넘었다
10월 19일 새벽 첫 측정에서는 받아쓰기(whisper large-v3-turbo), 답, 합성(Qwen3-TTS)을 모두 올려 둔 채 조합 넷에 질문 넷을 한 번씩 돌렸습니다. 답 모델은 gemma4 12b 와 e4b 파생 모델, 합성 모델은 1.7B 와 0.6B 입니다. 세 조합은 첫 소리가 1.36~2.22초였고 끊김이 없었습니다. 12b 와 0.6B 를 묶은 조합만 1.47초, 1.63초, 3.89초, 10.91초로 갈렸고, 이 조합에서 스왑아웃이 89,284쪽(16KB 쪽, 약 1.4GB) 났습니다.
원인은 메모리 부족으로 보고 있지만 확정하지는 못했습니다. 올려 둔 모델이 잡은 양은 12b 가 7.8~8.3GB, 받아쓰기가 2.3~2.4GB 였고, 합성 모델은 소리를 만드는 동안 1.7B 가 7.4GB, 0.6B 가 6.2GB 까지 올라갔습니다.
3초 안이어도 여유는 없었다
한 번씩만 돌려서는 흔들림 폭을 알 수 없어서, 같은 날 0시 32분에 12b 와 1.7B 조합으로 질문 넷을 세 바퀴 돌렸습니다. 12번 모두 3초 안이었고 가운데 값은 1.74초였습니다. 이 12번에서도 스왑아웃이 42,664쪽, 약 0.7GB 났고 메모리 여유는 28%에서 20%로 줄었습니다. 같은 조건에서 e4b 파생 모델 조합은 스왑이 0이었고 여유는 50%에서 48%가 됐습니다.
이 결과를 "느려진다"가 아니라 "여유가 없다"로 읽었습니다. 12b 로 대화하는 동안 그림이나 음악 같은 무거운 작업을 막는 규칙을 다음 할 일에 넣은 것도 이 때문입니다. 두 모델의 차이는 e4b 파생 모델의 가중치가 파일 캐시라 눌리면 버리고 다시 읽으면 되고, 12b 는 스왑으로 밀려나는 메모리를 쓰기 때문이라고 추정합니다. 측정하는 동안 스왑이 이미 5.4~6.0GB 쓰이고 있었고 여유와 스왑은 다른 작업에 따라 출렁여서, 같은 날 같은 조건에서 견준 값끼리만 비교합니다.
재는 자가 두 번 틀렸다
첫째는 메모리를 세는 방법이었습니다. 첫 측정 표에서 e4b 파생 모델의 메모리 칸이 비어 있었습니다. 측정 스크립트가 12b 를 돌리는 프로세스 이름만 찾았는데, 이 모델은 다른 이름의 프로세스로 돌았습니다. 이름을 고쳐 다시 재도 프로세스가 잡은 양은 1.3GB 로만 나왔습니다. 가중치를 mmap 으로 읽어서 프로세스 몫으로 잡히지 않은 것이고, 시스템 여유는 80%에서 40%로 떨어졌습니다. 실제로 쓰는 양은 9GB 안팎으로 보고, 지금은 파일 캐시 양을 같이 적습니다.
둘째는 다른 작업이 도는지 보는 방법이었습니다. 측정 스크립트는 다른 작업이 돌면 최대 15분까지 기다리는데, 처음에는 프로세스 이름만 봤습니다. 0시 56분에는 사진 색인이 이름 목록에 없어서 겹쳤습니다. 그 시간에 돌린 목소리 작업은 다른 작업을 확인하지도 않았고, 데운 합성 모델이 소리 길이의 약 두 배 시간을 썼습니다. 0시 6분에 같은 모델로 잰 값은 0.52~0.63배였습니다. 겹친 작업 탓으로 보지만 같은 조건으로 견주지는 않아서, 그 구간의 속도는 믿지 않기로 했습니다. 11시 8분에는 반대 일이 났습니다. 같은 색인이 다른 경로로 다시 떠서 CPU 0%, GPU 10% 로 쉬고 있었는데 측정은 15분을 기다리다 멈췄습니다.
지금은 이름이 맞아도 CPU 를 5% 넘게 쓸 때만 기다리고, 이름과 상관없이 GPU 사용률이 20% 이상이면 기다립니다. GPU 는 1초 간격으로 세 번 읽어 가운데 값을 씁니다. 판단 함수를 직접 불러, 동영상 색인이 GPU 를 97~99% 잡을 때는 기다리고 쉬는 색인 프로세스는 통과시키는 것을 확인했습니다.
기준 조합을 같은 자리에서 다시 쟀다
11시 9분에 12b 와 비서 목소리를 묶은 실제 조합을 쟀습니다. 세 바퀴 12번에서 첫 소리 가운데 값 1.48초(1.24~1.98초), 스왑 0, 여유는 26%에서 23%였습니다. 조건이 깨끗했는지 보려고 바로 이어서 새벽에 쟀던 기준 조합(12b 와 다른 참고 음성)을 같은 자리에서 다시 쟀습니다. 가운데 값은 1.40초(1.09~1.79초)로 새벽의 1.74초보다 빨랐습니다. 새벽에는 스왑이 쌓여 있었고 이 시각은 깨끗했다고 보아 1.48초를 믿기로 했습니다.
다시 잴 때는 bench.py e2e --llm 12b --tts 1.7B --rounds 3 을 돌립니다. 요약 스크립트는 모든 결과 파일을 시각순 이력 표로 모으고, 지금 8건이 들어 있습니다. 전에는 가장 최근 파일만 보여 줘서 같은 날 두 번 잰 값을 한 표에서 견줄 수 없었습니다.
무거운 작업 앞에서 모델을 내린다
막아야 할 작업이 얼마나 무거운지는 10월 22일에 쟀습니다. 12b 를 올린 채 사진 찾기용 그림 모델을 올리면 11초가 19초가 되고 스왑이 4GB 늘었습니다. 1024 크기 그림 한 장은 대화 모델을 내리고 그리면 49초에 스왑 0이었고, 12b 를 올린 채 그리면 58초에 스왑이 7.2GB 늘고 여유가 0%가 됐습니다. 12b 의 8GB 와 그림의 18GB 를 더하면 24GB 를 넘습니다.
지금은 그림과 사진 색인이 시작하기 전에 올라가 있는 대화 모델을 모두 내립니다. 대가로 그 뒤 첫 답은 모델을 다시 올리느라 늦고, 12b 를 올리는 데는 3.8초가 걸립니다. 그리는 도중에 대화를 하면 12b 가 다시 올라가 메모리가 모자랄 수 있는데, 이것은 아직 재지 않았습니다.
정리하면
- 3초 안에 들어온 측정도 스왑을 같이 봅니다. 시간 안에 들어와도 여유가 없으면 작업 하나만 겹쳐도 밀립니다.
- 프로세스가 잡은 양만으로는 mmap 으로 읽는 모델의 메모리가 보이지 않습니다. 시스템 여유와 파일 캐시를 함께 적습니다.
- 다른 작업은 이름보다 실제로 쓰는 CPU 와 GPU 로 판단합니다. 이름만 보면 놓치기도 하고 헛기다리기도 했습니다.
- 시각이 다른 두 측정은 같은 자리에서 기준 조합을 다시 재고 나서 견줍니다.
- 무거운 작업 앞에서는 대화 모델을 내리고, 첫 답이 늦어지는 대가는 적어 둡니다.
I am building a small device you talk with by voice. The brain is a local model running on a MacBook (M5, 24GB), and since the board has not arrived yet, I am measuring on the Mac with transcription, answering and speech synthesis chained together. In the previous post I wrote that the median from handing over a question to the first sound came out at 1.48 seconds. Looking at that number alone, it seemed done, but what remained that same day was memory rather than speed. The way memory was measured went wrong twice as well.
Two of four runs went over 3 seconds
In the first measurement, before dawn on October 19, transcription (whisper large-v3-turbo), answering and synthesis (Qwen3-TTS) were all kept loaded, and four combinations were each run once on four questions. The answer models were gemma4 12b and a model derived from e4b, and the synthesis models were 1.7B and 0.6B. Three combinations reached the first sound in 1.36–2.22 seconds, with no breaks. Only the combination pairing 12b with 0.6B split into 1.47, 1.63, 3.89 and 10.91 seconds, and this combination swapped out 89,284 pages (16KB pages, about 1.4GB).
I take the cause to be a memory shortage, but I have not confirmed it. Of the models kept loaded, 12b held 7.8–8.3GB and transcription 2.3–2.4GB, while the synthesis models rose to 7.4GB for 1.7B and 6.2GB for 0.6B while producing audio.
Under 3 seconds, but no headroom
One run each could not show how wide the spread was, so at 0:32 the same day I ran the four questions for three rounds with 12b and 1.7B. All 12 runs were under 3 seconds, with a median of 1.74 seconds. These 12 runs also swapped out 42,664 pages, about 0.7GB, and free memory fell from 28% to 20%. Under the same conditions, the combination with the e4b-derived model had zero swap, and free memory went from 50% to 48%.
I read this result not as "it gets slower" but as "there is no headroom". That is also why a rule blocking heavy jobs such as image or music generation while talking with 12b went onto the to-do list. My guess is that the difference between the two models is that the e4b-derived model's weights are file cache, which can be dropped under pressure and read again, while 12b uses memory that gets pushed out to swap. During the measurements 5.4–6.0GB of swap was already in use, and free memory and swap rose and fell with other work, so I only compare values measured on the same day under the same conditions.
The ruler was wrong twice
The first was how memory was counted. In the first measurement's table, the memory column for the e4b-derived model was empty. The measurement script looked only for the name of the process running 12b, but this model ran in a process with a different name. Even after fixing the name and measuring again, the process came out holding only 1.3GB. The weights are read with mmap, so they were not counted against the process, while system free memory fell from 80% to 40%. I put the real usage at around 9GB, and now the file cache amount is recorded alongside.
The second was how it checked whether other work was running. The measurement script waits up to 15 minutes if other work is running, but at first it looked only at process names. At 0:56, a photo indexer was not on the name list, so the two overlapped. The voice job run at that time did not check for other work at all, and the warmed-up synthesis model took about twice the length of the audio. Measured with the same model at 0:06, the figure was 0.52–0.63 times. I put it down to the overlapping work, but did not compare under the same conditions, so I decided not to trust the speed in that window. At 11:08 the opposite happened. The same indexer had started again from a different path and was sitting idle at 0% CPU and 10% GPU, yet the measurement waited 15 minutes and stopped.
Now it waits only when a name matches and that process uses more than 5% CPU, and regardless of name, it waits when GPU utilisation is 20% or more. The GPU is read three times at 1-second intervals and the median is used. Calling the decision function directly, I confirmed that it waits while a video indexer holds the GPU at 97–99% and lets an idle indexer process through.
The baseline, measured again in the same sitting
At 11:09 I measured the real combination, 12b with the assistant's voice. Over 12 runs in three rounds, the median to the first sound was 1.48 seconds (1.24–1.98 seconds), with zero swap and free memory going from 26% to 23%. To see whether the conditions were clean, I went straight on to measure again, in the same sitting, the baseline combination from before dawn (12b with a different reference voice). Its median was 1.40 seconds (1.09–1.79 seconds), faster than the 1.74 seconds before dawn. Taking it that swap had built up before dawn and that this time was clean, I decided to trust 1.48 seconds.
To measure again, run bench.py e2e --llm 12b --tts 1.7B --rounds 3. The summary script gathers every result file into a history table in time order, and it now holds 8 entries. Before, it showed only the most recent file, so two measurements taken on the same day could not be compared in one table.
Unloading the models before heavy jobs
On October 22 I measured how heavy the jobs to be blocked actually are. Loading the image model used for photo search with 12b loaded turned 11 seconds into 19 and added 4GB of swap. One 1024-pixel image took 49 seconds with zero swap when drawn after unloading the conversation model, and 58 seconds with 7.2GB more swap and free memory at 0% when drawn with 12b loaded. 12b's 8GB plus the image model's 18GB is more than 24GB.
Now, before image generation and photo indexing start, every loaded conversation model is unloaded. The cost is that the first answer after that is slow while the model loads again; loading 12b takes 3.8 seconds. Talking while an image is being drawn would load 12b again and memory could run short, and this has not been measured yet.
In short
- Measurements that came in under 3 seconds are checked for swap too. Even within the time limit, with no headroom a single overlapping job pushes things back.
- The amount a process holds does not show the memory of a model read with mmap. System free memory and file cache are recorded together.
- Other work is judged by the CPU and GPU it actually uses rather than by its name. Going by names alone, the script both missed work and waited for nothing.
- Two measurements taken at different times are compared only after the baseline combination has been measured again in the same sitting.
- Before heavy jobs, the conversation model is unloaded, and the cost of a slower first answer is written down.