Skip to content
/ airelien.dev
Go back
Aurélien AMSELLEM

Lucebox on Olares One — Episode 5: The runtime slams the door with a negative device id

Image pushed, pod deployed, models downloaded. Everything is ready. Then HAMi vGPU dumps `Illegal device id: -644371744` on every boot, with a random number that changes each run. Smells like uninitialized stack from a mile away.

Episode 4: after 6h of cumulative compile time, the image aamsellem/lucebox-qwen36-blackwell:1.0.0 is on Docker Hub. It compiles, it links, it pushes.

Except the pod doesn’t boot.

The crash

Here are the pod logs, once the Q4_K_M main model (~17 GB) and the z-lab drafter (~3.5 GB) have finished downloading. The HAMI-core lines come from HAMi during its initialization, the ggml_cuda_init lines from llama.cpp, which does find the GPU. The last line is the error.

==> Starting Lucebox llama-server: /opt/lucebox/.../llama-server
[HAMI-core Msg(...)]: Initializing.....
[HAMI-core Warn(...)]: invalid device memory limit CUDA_DEVICE_MEMORY_LIMIT_0=0m
[HAMI-core Msg(...)]: get_nvml_device_memory_total 0
[HAMI-core Msg(...)]: get_nvml_device_memory_total 1
... (up to 15)
[HAMI-core Msg(...)]: Initialized
[HAMI-core Msg(...)]: SCHEDULER_WEBSOCKET_URL ws://gpu-scheduler.os-gpu:6000

ggml_cuda_init: found 1 CUDA devices (Total VRAM: 24463 MiB):
  Device 0: NVIDIA GeForce RTX 5090 Laptop GPU, compute capability 12.0,
            VMM: yes, VRAM: 24463 MiB

[HAMI-core ERROR (...)]: Illegal device id: -644371744

Then the process exits and the pod goes into CrashLoopBackOff. I restart, and:

[HAMI-core ERROR (...)]: Illegal device id: -39296272

Then:

[HAMI-core ERROR (...)]: Illegal device id: 1816936528

The device id changes on every run, at random. For CUDA, the device id is the GPU’s number: the machine’s first GPU is 0, the second is 1, and so on. There’s only one GPU here, so the only valid value is 0. A negative or ten-digit id makes no sense.

First instinct

When a C or C++ program throws out a “random” integer that changes every run, nine times out of ten it’s an uninitialized stack variable. The stack is the memory area where a function keeps its local variables, and it gets reused from one call to the next without being cleaned. If you declare int dev; without giving it a value, dev takes whatever was lying at that spot on the stack, meaning whatever the previous functions left there. Hence a different value each time.

But where does the error come from? Not ggml, not Lucebox, not llama-server. The [HAMI-core ERROR ...] prefix points to HAMi vGPU, the GPU isolation layer running on Olares’s Kubernetes (I introduced it briefly in episode 1).

What HAMi actually is

HAMi (Heterogeneous AI computing Virtualization Middleware) is a Kubernetes device plugin that virtualizes GPUs. A device plugin is the component that tells Kubernetes about a machine’s special hardware (here, the GPU) and hands it out to the pods that ask for it. On Olares, HAMi lives in the kube-system namespace; the command below lists its DaemonSets, services that run on every machine in the cluster:

$ kubectl get ds -n kube-system | grep hami
hami-device-plugin          1/1  ...   gpu.bytetrade.io/cuda-supported=true
hami-nvidia-dcgm-exporter   1/1  ...

At startup, the HAMi init script copies a custom library (libvgpu.so) onto the host, at /usr/local/vgpu/. When a pod requests nvidia.com/gpu in its resources, HAMi mounts it into the container via hostPath (a host folder made visible inside the container), and libvgpu.so is LD_PRELOAD’d into every binary in the pod. LD_PRELOAD tells the system loader to load that library before all the others, so its functions take precedence over those of the real libcuda. That’s how libvgpu.so can intercept CUDA calls to track memory, schedule work and enforce quotas.

So when llama-server calls a CUDA function, the call goes through HAMi first. And it’s HAMi that crashes with Illegal device id: <random>.

First diagnosis: is VMM to blame?

The log says VMM: yes. CUDA has two API levels: the Runtime API (cudaMalloc and friends), the common one, and the lower-level Driver API (the cu... functions). The Driver API gives access to VMM, virtual memory management: you reserve a range of addresses, then map physical memory into it as you go. Lucebox uses it (cuMemCreate, cuMemAddressReserve, cuMemMap) for its allocations, because it’s more efficient than cudaMalloc for managing dynamic memory pools. Those are the functions we ran into in episodes 2 to 4: almost every undefined reference was a VMM function.

Hypothesis: maybe HAMi doesn’t intercept the VMM path correctly. If I disable VMM on the ggml-cuda side, the bug might go away.

ggml has a CMake flag for this, -DGGML_CUDA_NO_VMM=ON, which forces cudaMalloc (Runtime API) instead of cuMemCreate (Driver API). HAMi normally knows how to intercept the Runtime API.

So I rebuild. Build #5, another 2h of compile, because the flag invalidates the entire CUDA cache.

docker.io/aamsellem/lucebox-qwen36-blackwell:1.1.0

Push, swap the image in the Olares chart (from v1.0.0 to v1.1.0), restart the pod. It boots, downloads the models, starts llama-server.

ggml_cuda_init: found 1 CUDA devices (Total VRAM: 24463 MiB):
  Device 0: NVIDIA GeForce RTX 5090 Laptop GPU, compute capability 12.0,
            VMM: yes, VRAM: 24463 MiB
[HAMI-core ERROR (...)]: Illegal device id: -1967326112

Same thing.

Wait, the log still says VMM: yes. Why? I built with NO_VMM…

Oh. It’s the GPU’s capability being printed, not what ggml does with it. The GPU can do VMM; ggml just chose not to use it. And Illegal device id is still there.

In other words, the bug isn’t in the VMM path. It’s somewhere else, and NO_VMM does nothing.

At this point I’m 7h into the saga, I’ve burned 8h of CPU on compiles, and I still don’t know why my pod crashes. Time to read the HAMi source code.

Episode 6: reading the HAMi-core source. See you next time!


Disclosure — All the benchmarks in this post run on my own Olares One. If the content was useful and you’re considering one, ordering through this referral link gets you $300 off ($4,699 instead of $4,999), stackable with the $300 Black Friday discount starting November 17: $600 off in total ($4,399). I’m mentioning this out of transparency — and yes, incidentally, it helps keep the blog alive (hosting, domain, and the time I spend writing here).

Share this post on:

Comments