Skip to content

hive: dwarfstar, one bee per model, one GPU between them - #85

Merged
adiled merged 3 commits into
mainfrom
hive/dwarfstar
Oct 24, 2026
Merged

adiled merged 3 commits into
mainfrom
hive/dwarfstar

Conversation

@adiled

@adiled adiled commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #88 (the C client). This PR is only hives/dwarfstar/.

What this adds

A worker hive whose bees have the DwarfStar
engine linked into their own process and speak thrum through the C
client: one unit per model, each its own bee, sharing one GPU.

One unit, one model, one bee

The Orchfile keeps a unit per model, the way ds4-runner keeps a server
per model:

unit answers to
ds4flash deepseek-v4-flash (ds4's default link)
ds4flash-q2 deepseek-v4-flash-q2
ds41flash-q2 deepseek-v4.1-flash, deepseek-v4.1-flash-q2
glm53flash-q2 glm-5.3-flash, glm-5.3-flash-q2

Each unit runs the same dwarfstar-bee, pinned to one GGUF and entered
as the unit's name, so each model has its own key, ids and headroom, and
hum bee <id> exit takes one model off the mesh. Model files are ARGs,
since their names drift between machines. Each unit states its resources
in the Orch spec: MEMORY, nice, SSD streaming and threads as
ds4-runner ran them, RESTART on-failure with a start limit, and a stop
timeout. A unit whose model is not on the machine exits 0 and stays down.

On macOS, launchd records MEMORY as a soft resident-set limit the
kernel does not enforce (the Orch spec calls it advisory there); systemd
enforces it as MemoryMax. On a Mac, one model on the GPU at a time is
what keeps memory in hand.

One GPU, handed between bees

ds4 exits when a second process opens the GPU, so the bees share a
hive-wide flock and hold it while their engine is loaded:

  • A bee that needs the GPU files a want beside the lock and waits. A
    cancel ends the wait.
  • The holder gives the GPU back when it is idle and wanted, after its
    turn when a want has waited a minute, and after DWARFSTAR_IDLE_MS.
  • Loading checks ds4's own lock first, so a ds4 started elsewhere is an
    error on the turn, not a dead bee.
  • A bee claims one slot of headroom while the GPU is its own or free, so
    a peer routes to the model that can start now. It pulses only when the
    claim changes. A local prompt still runs and waits for the handoff.

No arbiter: humd is the front door, and the handoff lives in the bees.

How a turn runs

One long-lived session per loaded engine, synced to each turn's whole
prompt so ds4 evaluates only what the KV cache lacks. Turns queue and run
one at a time; a cancel stops its sid's turn, waiting or in flight, and
drops its queued ones. Sampling is seeded with ds4's defaults, the stop
check is ds4-server's, chunks carry whole UTF-8 characters, and a turn
ends stop, length, cancelled or error.

Proof

Installed for real, on a humd built from main (./install --edge)
with hum hive ./hives/dwarfstar install: the four model units nestled as
four bees, each under its own key, and an OpenAI chat completion sent to
openai-server streamed back from the DeepSeek V4 Flash Q2 bee (A beehive
is a structure where a colony of honeybees...
). That run is what caught
openai-server sending content as a string; the bee now reads it.

Through a humd built from this branch, in isolated XDG dirs:

  • Two real models on one GPU, M5 Max: a DeepSeek V4 Flash Q2 bee
    answered Bees make honey. in 1.6 s, then handed the GPU to a GLM 5.3
    Flash Q2 bee, which loaded (89 GiB planned) and answered A hive is a
    structure, such as a beehive, in which honeybees live and store honey.
  • Stub bees (make check, no model): the GPU traded on demand and on
    idle, a cancel ended a turn still waiting for the GPU, two idle bees
    sent no pulses in 12 s, a missing model left its unit down, and "é"
    split across token pieces arrived whole.
  • The Orchfile passes orch validate. No undeclared keys in humd's spec
    log.

What changed from the first version of this PR

The first version carried its own C client, codegen and CI changes and
docs; #88 replaces those, so this is the hive alone. It also fixes what
the first version got wrong: the signature and signedAt came from two
clock reads; concurrent prompts shared one engine with no lock and
interleaved writes; it claimed stateful_session while making a new
session every prompt; up to eight models could be held open at once; the
sampler was seeded with 0; a prompt with no model took whichever file was
listed first; and it advertised chis it did not handle.

Not here

The lattice (ds4 across machines), two models resident at once, vision,
tools and thinking, and CUDA: the Makefile wires ds4's Metal backend.

@adiled adiled changed the title the C client, and a hive with the engine inside it hive: dwarfstar, the DwarfStar engine in a C bee Oct 24, 2026
@adiled
adiled changed the base branch from main to thrum/c-client October 24, 2026 14:43
@adiled adiled changed the title hive: dwarfstar, the DwarfStar engine in a C bee hive: dwarfstar, one bee per model, one GPU between them Oct 24, 2026
A worker hive whose bee links antirez/ds4 into its own process and
speaks thrum through the C client. A prompt tone becomes a chat prompt,
the chat prompt becomes tokens, and the tokens come back as text_delta
chunks and a finish, with no HTTP in between.

The Makefile fetches ds4 at a pinned commit, compiles exactly the
objects ds4's own Makefile links on macOS with its flags, includes
thrum.mk for the client, libsodium and cJSON, and puts the Metal kernels
beside the bee. install builds it and runs it under orchd like every
bundled hive; the bee enters itself as main and signs its hello.

One engine is resident at a time and keeps one session, synced to each
turn's whole prompt so ds4 evaluates only what the KV cache lacks. Turns
queue and run one at a time on their own thread; a cancel stops its
sid's turn in flight and drops its queued ones. Sampling is seeded and
uses ds4's defaults, the stop check is ds4-server's, a chunk carries
whole UTF-8 characters, and a turn ends stop, length, cancelled or
error. The bee claims one slot of headroom and is stateless.

make check builds the bee against a stub bridge, so the thrum side runs
with no model. Both were run through a humd built from this branch: the
stub for queueing, cancel in flight and queued, and a character split
across tokens; the engine with DeepSeek V4 Flash Q2 on an M5 Max for a
real answer, a second turn on the resident engine, and a real cancel.
…n them

The Orchfile now carries a unit per model, the way ds4-runner keeps a
server per model: ds4flash, ds4flash-q2, ds41flash-q2 and glm53flash-q2.
Each runs the same bee pinned to one GGUF (DWARFSTAR_MODEL, with the ids
it answers to in DWARFSTAR_MODELS) and entered as the unit's name, so
every model nestles with its own key, ids and headroom, and one can be
exited without the rest. Model files are ARGs, since their names drift
between machines. Each unit states its resources in the Orch spec:
MEMORY, nice, SSD streaming and threads as ds4-runner ran them,
RESTART on-failure with a start limit, and a stop timeout. install
grows every unit; a unit whose model is not on the machine exits 0 and
stays down.

ds4 exits when a second process opens the GPU, so the bees share a
hive-wide flock and hold it while their engine is loaded. A bee that
needs the GPU files a want beside the lock and waits; the holder gives
it back when idle and wanted, after its turn when a want has waited a
minute, and after DWARFSTAR_IDLE_MS idle. A cancel ends a wait. Loading
first checks ds4's own lock, so a ds4 started elsewhere is an error on
the turn and not a dead bee. A bee claims one slot of headroom while the
GPU is its own or free and pulses only when that changes; a probe that
meets another bee's probe retries before calling the GPU taken.

Run through a humd built from this branch: two stub bees traded the GPU
on demand and on idle, a cancel ended a turn still waiting for the GPU,
two idle bees sent no pulses in twelve seconds, and a missing model
left its unit down. With the engine, a DeepSeek V4 Flash Q2 bee answered,
then handed the GPU to a GLM 5.3 Flash Q2 bee, which loaded and answered.
openai-server sends a prompt's content as one flattened string, and
hum-nest reads content as a string before it falls back to text. The bee
only took text or content petals, so a chat completion through
openai-server reached it and was answered "the prompt carried no text".
It now takes a content string, then text, then content petals.

Installed on a humd built from main, the four model units nestled as
four bees, and an OpenAI chat completion to openai-server streamed back
from the DeepSeek V4 Flash Q2 bee.
@adiled
adiled changed the base branch from thrum/c-client to main October 24, 2026 16:30
@adiled
adiled merged commit 0d6b2c3 into main Oct 24, 2026
5 checks passed
@adiled
adiled deleted the hive/dwarfstar branch October 31, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant