Skip to content

Latest commit

 

History

History
213 lines (186 loc) · 12.4 KB

groups.md

File metadata and controls

213 lines (186 loc) · 12.4 KB

Worker groups and GPUs on pools: a plan

November 27, 2026 · a plan for step 4 of layers.md; all its PRs, 1 to 5, are built (November 28)

dista now routes a task or an actor to the workers of a named group, reports demand per group and runs flows (dista #152 to #167). Before this plan morca used none of it: a run asked for a count of workers, a host reported CPUs and memory only, and no worker was started with a group. This plan closes that for pools, which layers.md makes the one model, and then for the other ways a run gets workers. Its PRs are built, so it now describes what exists.

What existed, and what was missing

Part Before Added
Request workers, cpus, memory_gb per pipeline (Registered, Request) Workers per group, each group with its own size and GPUs
Host facts CPUs and memory, less a reserve (host_room), sent with each claim GPUs
Grant Grant(cpus, memory_mb), as MORCA_GRANT_* GPUs, and which devices
Members of a run join_claim hands an idle worker a MemberSpec (head, token, grant) The group the member serves; DISTA_GROUP on its dista worker
Pool demand SQL: queued runs, plus workers less the live members What each running run's head wants, per group
Taking a member back Only when its run ends Draining one while the run goes on
Scaling by dista's demand Only the ec2 placement (decide and dista-drain) The same on pools

Two things found while reading that this plan fixes on the way:

  • On a pool, workers = "MIN..MAX" ignores MIN and asks for MAX members (fixed in PR 4a). Pipeline[workers=] in code is ignored there too (the SQL reads only the registered column), and stays so: describe always carries workers (2 by default), so reading it would have every pool pipeline with tasks ask for two members. On a pool only the registered workers counts.
  • The DISTA_* names morca sets aren't reserved in a pipeline's env.

Requests: groups beside workers

[pipelines.embed]
placement = "worker:batch"
workers = "1..4"            # the workers with no group, as today
cpus = 4

[pipelines.embed.groups.gpu]
workers = "0..2"
gpus = 1                    # per worker
cpus = 4
memory_gb = 16
  • A group has workers (a count or a range), and cpus, memory_gb and gpus per worker. What it doesn't set falls back to the pipeline's.
  • The keys outside groups keep their meaning: they describe the workers with no group, which is where dista sends a task that names none.
  • Groups are stored as one jsonb column on orca.pipelines, which is additive. They aren't copied into the run's spec: the scheduler reads them from the pipeline's registration.
  • In code, a task names its group (Task[..., group="gpu"] in dista). register and config check refuse a pipeline whose tasks name a group the pipeline doesn't declare, if the binary's describe can list them; otherwise the run fails at its first such task with dista's message.

Hosts and grants: GPUs

  • morca worker counts its GPUs once at start: MORCA_HOST_GPUS if set, else the devices nvidia-smi lists, else none. It sends the count with each claim, and the scheduler stores it beside room_cpus.
  • Grant gains the GPUs it holds, as device indexes. The worker hands them out itself, since only it knows which are free, and sets MORCA_GRANT_GPUS and CUDA_VISIBLE_DEVICES on the member's process.
  • A GPU is granted whole, to one member at a time. A member of a group that asks for none gets none, and its CUDA_VISIBLE_DEVICES is empty.
  • A host with GPUs serves groups without them only when no host without GPUs has room, so a decode worker doesn't take the place a model needs.

Members by group

  • orca.run_members gains the member's group. join_claim picks, for an idle host, a running run and a group of it that is short of members and that the host can serve (room for its size, a free GPU if it asks one).
  • start_dista_worker sets DISTA_GROUP. The claiming host's own dista worker has no group, as today.
  • The driver and head stay on the claiming host.
  • Until demand per group lands, every group wants its MAX, as the workers with no group want workers today. Honouring MIN before there is demand to grow a group back would shrink today's pool runs.
  • A host is one member of a run at most, so a host with GPUs doesn't join as a member without GPUs of a run that still wants one with them.
  • A claim says whether its worker understands groups; one that doesn't is offered only members with no group. A run with groups goes only to a worker with --advertise, which starts it as a cluster.

Demand per group

  • The host that runs a run's head asks it for its status (<binary> dista-status, which exists) every few polls and sends the answer with its claim. The scheduler can't always reach the head, and the host can.
  • The scheduler keeps the last answer on the run and calls dista's decide once per group, with the group's range as the policy's bounds. The result is how many members of each group the run wants now.
  • join_claim and the pool's demand query use those wanted counts where they used workers. Before the first answer a run wants each group's MIN, which is also the fix for the ignored MIN (PR 4a; until then each group wanted its MAX).
  • Units: dista counts its workers, and a member is one. The workers with no group also count the head's host's own dista worker, which isn't a member, so they want one less than decide says. decide's memory (since when a group is short) is kept per run, start and group in orca.run_wants, so a restarted UI goes on where it was.
  • A host with GPUs doesn't start a run whose groups ask for GPUs as its head while a host without GPUs could: the head's host serves no group.
  • A worker says in each claim whether it reports demand (reports_demand). A run whose head is on one that doesn't (an older worker, or reporting off) wants each kind's MAX until something is decided, as before, since nothing would grow it from MIN.
  • When decide says a group has too many, it names the idle members to drain by their dista workers' addresses, which each member's host reads from the process and sends with its claims. The scheduler marks those members as draining, counts them no more among the live ones, and tells their hosts in their claims' answers. A host drains the dista worker with dista's drain (dista-drain), so its tasks finish or move and a group's last worker stays while the group has tasks, and kills it if it hasn't left 15 s after dista's own bound. A drain dista refuses goes back with the next claim, and the member runs on. A member ends, and its grant is returned, when its process exits; its row says why it was drained. decide never goes below the group's MIN, and the head's host's own dista worker is no member and is never drained.
  • A pool grows when wanted members have no host. A group that asks for GPUs needs a machine type that has them: a pool lists those under gpu_machines, with the same shape as machines, and is otherwise unchanged. The members of groups that ask for GPUs are the demand of gpu_machines, and the rest the demand of machines: each kind grows and shrinks by its own, with a trying state and a status of its own, and max_machines caps both together.
  • A host with GPUs leaves a run's head, or a member that asks for no GPU, to a host without GPUs that has room for MORCA_GPU_DEFER_SECONDS (60) at most. A host that seems to have room may never take it (it runs another image, say), and the run would wait for ever.

One contract for every provider

"Give run R a worker of group G, of this size, from this image, joined to this head with this token", and "take it back". The pool path was that contract after the PRs above, in MemberSpec and the stop list. PR 5 named it (morca._internal.provider) and moved the other providers behind it:

Provider Give Take back
Pool host (morca worker) join_claim to MemberSpec Drain, then kill
Local and control The run's process forks each group's workers (Runtime(groups=...), from MORCA_GROUPS), all sharing the run's grant The run's end
Kubernetes A worker Pod per worker, sized from the group, with DISTA_GROUP and nvidia.com/gpu The run's end
  • One function builds a dista process's environment for all of them, selected by the provider's name (cluster_env, driver_env, local_env, gpu_env): the DISTA_* names, the slots, and the GPUs.
  • Kubernetes, local and control get groups but no scaling: each starts every group at its MAX, for the run's life. (This plan first said local would start each group's MIN, which with no demand to grow it would leave a group of 0..N with no worker.) Scaling there follows if the gate needs it.
  • On local and control the run is admitted as one: its groups' GPUs, a group's gpus for each of its MAX workers, are part of its request and come from the scheduler's host, counted as a worker counts its own (MORCA_HOST_GPUS, else nvidia-smi). Every forked worker sees all of the run's GPUs, since dista forks them with one environment; dista's groups keep the model's tasks on the group's workers. A group's cpus and memory_gb aren't used there.
  • The ec2 placement gets none of this. It is to be retired (layers.md), and register and config check warn when a pipeline placed on it declares groups.
  • register and config check also warn about a group's cpus and memory_gb on control, which ignores them. A pipeline on the default placement isn't warned: which runner that is is the scheduler's MORCA_RUNNER, which neither command knows. The full table of keys per placement is #369, not this plan.

Not in this plan

  • Labels other than GPUs (a GPU model, a zone). A second pool does that job until something needs more.
  • A fraction of a GPU, or several members sharing one.
  • A group whose members come from another pool than the run's.
  • Moving the ec2 placement's users to pools, and removing it.
  • Jobs that aren't runs, a shared head and named actors.

PRs

# What Tests
0 Move the dista pin to the release with groups and flows The existing suite
1 Groups in morca.toml, Registered, the database and describe; config check; reserve the DISTA_* names. No change in what runs. (done) Unit tests of the parser and the stored form
2 GPUs: the host's count, the claim, Grant, admission, the UI's host and run pages (done) test-grants with MORCA_HOST_GPUS
3 Members by group on pools: run_members, join_claim, DISTA_GROUP (done) test-run-cluster with a GPU group on a mixed pair of hosts: the group's task runs only there
4a Demand per group: the head's status with the claim, decide per group, the wanted counts in join_claim and the pool's demand; MIN honoured; a host with GPUs leaves a run whose groups ask for GPUs to start on one without (done) test-run-cluster with a group of 0..1 that grows from 0 once the head reports its tasks; unit tests of the decision
4b Draining a member when decide says a group has too many, and gpu_machines in a growing pool; a bound on a host with GPUs deferring (done) test-pool-scale with a mixed pool whose GPU machine grows for a group from 0, is drained when idle and removed while the run goes on; test-run-cluster with a member drained mid-run, and a deferral that ends
5 The contract by name: one environment builder, groups on local, control and Kubernetes, warnings for the ec2 placement (done) test-kube, and test-grants with a local and a control-placed run with two groups

Each PR leaves a pipeline without groups behaving as it does today, except for the MIN fix in PR 4a.

Defaults (confirmed 2026-11-27)

  1. Groups are declared per pipeline in morca.toml, with the keys above, and the un-grouped keys keep meaning the workers with no group.
  2. GPUs are counted whole and matched by count. No other labels yet.
  3. A mixed pool is one pool with machines and gpu_machines, not a pool per group.
  4. The head's host reports dista's demand, and the scheduler decides with dista's decide. Pools take over the scaling the ec2 placement has.
  5. Pools first, then local and Kubernetes with groups but without scaling. The ec2 placement gets nothing.