Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion K8S.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ How morca will create the pods a run needs, what that takes on AWS, how its cost
|---|---|
| A Pod and a Service for the dista head | The Service gives the head a DNS name, which becomes `DISTA_HEAD` |
| N worker Pods, sized for the pipeline | dista's workers: the pipeline's image with `DISTA_ROLE=worker` |
| The worker Pods of each [worker group](docs/morca-toml.md#groups-off-a-pool) | Its MAX of workers, sized for the group, with `DISTA_GROUP` and the group's GPUs as `nvidia.com/gpu` |
| A Job for the driver | The pipeline binary: `taxi run ...`, or `taxi resume <run>` |
| A Secret, for a run with secrets | The values of its `secrets`, which its pods refer to by name |

Every pod also gets the bucket: the scheduler's `AWS_REGION`, `AWS_ENDPOINT_URL_S3` and the like, and `MORCA_WAREHOUSE` and `MORCA_LOGS` when they're in object storage, so steps reach the warehouse and attempts' logs and timelines go to the bucket. The S3 keys come from the stack's Secret `morca-s3` in `morca-runs` (`MORCA_RUN_S3_SECRET`) by `secretKeyRef`, so no Job or Pod object holds them. Before a run's objects go, the scheduler keeps its driver's, head's and workers' logs beside its attempts' (`driver.log`, `head.log`, `worker-<i>.log`).
Every pod also gets the bucket: the scheduler's `AWS_REGION`, `AWS_ENDPOINT_URL_S3` and the like, and `MORCA_WAREHOUSE` and `MORCA_LOGS` when they're in object storage, so steps reach the warehouse and attempts' logs and timelines go to the bucket. The S3 keys come from the stack's Secret `morca-s3` in `morca-runs` (`MORCA_RUN_S3_SECRET`) by `secretKeyRef`, so no Job or Pod object holds them. Before a run's objects go, the scheduler keeps its driver's, head's and workers' logs beside its attempts' (`driver.log`, `head.log`, `worker-<i>.log`, `worker-<group>-<i>.log`).

The scheduler watches the Job, and deletes everything labelled with the run when it ends.

Expand Down
1 change: 1 addition & 0 deletions changes/613-groups-providers.minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Worker groups off pools**: the local runner, `control` and Kubernetes start each group's MAX of workers (GPUs from the scheduler's host, or `nvidia.com/gpu` on Kubernetes), every provider builds its dista environment through one contract, and `ec2` warns that it ignores groups. (#613)
62 changes: 39 additions & 23 deletions docs/groups.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Worker groups and GPUs on pools: a plan

November 27, 2026 · a plan for step 4 of [layers.md](layers.md); PRs 1
to 4b are built
November 27, 2026 · a plan for step 4 of [layers.md](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). morca can't use any of
it yet: a run asks for a count of workers, a host reports CPUs and memory
only, and no worker is started with a group. This plan closes that for
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](layers.md) makes the one model, and then for the
other ways a run gets workers.
other ways a run gets workers. Its PRs are built, so it now describes what
exists.

## What exists, and what is missing
## What existed, and what was missing

| Part | Today | 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 |
Expand Down Expand Up @@ -139,26 +140,41 @@ memory_gb = 16
## 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". After the PRs above the
pool path is that contract, in `MemberSpec` and the stop list. The last PR
names it and moves the other providers behind it:
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` | Fork with `Runtime(groups=...)`, sized from the run's grant | The run's end |
| Kubernetes | A worker Pod per member, sized from the group, with `DISTA_GROUP` and `nvidia.com/gpu` | Delete the Pod after a drain |

- One function builds a dista worker's environment for all three.
- Kubernetes and local get groups but no scaling in this plan: they start
each group at its MAX and MIN respectively. Scaling there follows if the
| 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](layers.md)), and `register` warns when a pipeline placed on
it declares groups.
- `register` and `config check` warn about group keys a placement ignores.
The full table of keys per placement is
[#369](https://github.com/morca-dev/morca/issues/369), not this plan.
([layers.md](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](https://github.com/morca-dev/morca/issues/369), not
this plan.

## Not in this plan

Expand All @@ -179,7 +195,7 @@ names it and moves the other providers behind it:
| 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 | `test-kube`, and a local run with two groups |
| 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.
Expand Down
2 changes: 1 addition & 1 deletion docs/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ than the cluster's memory:
| 4 | Worker groups and GPUs in requests, grants and `[pools]`; one provider contract | morca |
| 5 | The embedding flow and its Ray Data counterpart; measure the gate | census, dista `bench/` |

1 to 3 are done in dista. The plan for 4 is [groups.md](groups.md).
1 to 3 are done in dista, and 4 in morca ([groups.md](groups.md)).

1 to 3 need nothing from morca and run in dista's local mode, so the flow
can be measured against Ray Data on one machine before 4 exists.
Expand Down
59 changes: 47 additions & 12 deletions docs/morca-toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ hostname = "orca.mlake.dev"
|---|---|
| `[defaults]` | Values for every pipeline the file names. It doesn't apply to pipelines the file leaves out. |
| `[pipelines.<name>]` | One pipeline's own values, by the name its `describe` gives. An empty table is allowed: the pipeline is then "in the file" and gets `[defaults]`. |
| `[pipelines.<name>.groups.<group>]` | One group of the pipeline's workers, with its own size and GPUs, used on pools: [Worker groups](#worker-groups). |
| `[pipelines.<name>.groups.<group>]` | One group of the pipeline's workers, with its own size and GPUs, used on pools, the local runner, `control` and Kubernetes: [Worker groups](#worker-groups). |
| `[pools.<name>]` | A pool of workers: one morca grows and shrinks itself, or, without a `provider`, machines that join by hand. [Worker pools](#worker-pools). |
| `[apps.<name>]` | An app beside the UI and what it gets: [Apps](#apps). |
| `[datasets."<name>"]` | A dataset's settings: whether visitors see its data. [Datasets](#datasets). |
Expand Down Expand Up @@ -97,7 +97,7 @@ Each key can go in `[defaults]` or in `[pipelines.<name>]`.
- `fills = "all"` for a keyed pipeline, a sensor, or one with no first partition. `morca register` refuses it with the file and line, because it has to see the pipeline first; see [Fills](#fills).
- An `env` name that isn't a valid variable name.
- An `env` name that looks like a secret (`*TOKEN*`, `*SECRET*`, `*PASSWORD*`, `*DATABASE_URL*`). Put those in `secrets` instead.
- An `env` variable that morca sets itself: `MORCA_DATABASE_URL`, `MORCA_IMAGE`, `MORCA_SECRETS`, `MORCA_WORKERS`, `DISTA_ROLE`, `DISTA_HEAD`, `DISTA_ADVERTISE`, `DISTA_TOKEN`, `DISTA_PORT`, `DISTA_GROUP`, `MORCA_GRANT_CPUS`, `MORCA_GRANT_MEMORY_MB`, `MORCA_GRANT_GPUS`, `CUDA_VISIBLE_DEVICES`, `MORCA_MEMORY_PRESSURE_FILE`. `DISTA_WORKER_SLOTS` isn't one of them: a pipeline sets it (["auto" from the grant](#auto-from-the-grant)).
- An `env` variable that morca sets itself: `MORCA_DATABASE_URL`, `MORCA_IMAGE`, `MORCA_SECRETS`, `MORCA_WORKERS`, `MORCA_GROUPS`, `DISTA_ROLE`, `DISTA_HEAD`, `DISTA_ADVERTISE`, `DISTA_TOKEN`, `DISTA_PORT`, `DISTA_GROUP`, `MORCA_GRANT_CPUS`, `MORCA_GRANT_MEMORY_MB`, `MORCA_GRANT_GPUS`, `CUDA_VISIBLE_DEVICES`, `MORCA_MEMORY_PRESSURE_FILE`. `DISTA_WORKER_SLOTS` isn't one of them: a pipeline sets it (["auto" from the grant](#auto-from-the-grant)).
- A [worker group](#worker-groups) without `workers`, with a key it doesn't have, with a name that isn't lowercase letters, digits, `-` and `_` starting with a letter (at most 32), or in `[defaults]`.

Each refusal names the file and line, and nothing is registered:
Expand Down Expand Up @@ -329,20 +329,25 @@ env = { DISTA_WORKER_SLOTS = "auto", GHARCHIVE_PARALLEL = "auto" }
which free devices and passes their indexes in `MORCA_GRANT_GPUS` and
`CUDA_VISIBLE_DEVICES` (`0,2`). On a host with GPUs, a start granted
none gets both variables empty, so it sees no GPU; on a host without,
neither is set. Only a [group](#worker-groups) asks for GPUs, so only a
member of a group on a pool is granted any.
neither is set. Only a [group](#worker-groups) asks for GPUs: on a pool
a member of the group is granted them, and on the local runner and the
control host the run is granted those of all its groups from the
scheduler's host, counted the same way the first time a run asks for
some (an older scheduler, and a run that asks for none, set neither
variable there, as before).

### Worker groups

A pipeline may split its workers into named groups, each with its own size
and GPUs ([groups.md](groups.md)). Groups are recorded, shown and exported,
and used on a pool: a run of a pipeline placed `worker:<pool>` that
declares groups spreads over the pool's workers as a cluster, and gets
members of each group ([workers.md](workers.md#members-by-group)). A dista
task names its group (`Task[..., group="gpu"]`) and runs only on a member
of that group; a task that names none runs on the workers with no group.
Every other placement ignores groups for now (local runs, `control`,
Kubernetes and `ec2`).
members of each group ([workers.md](workers.md#members-by-group)). The
local runner, `control` and Kubernetes start each group's workers too, a
fixed count of them ([Groups off a pool](#groups-off-a-pool)). A dista task
names its group (`Task[..., group="gpu"]`) and runs only on a worker of
that group; a task that names none runs on the workers with no group. The
`ec2` placement ignores groups.

```toml
[pipelines.embed]
Expand All @@ -366,9 +371,11 @@ A group's name is lowercase letters, digits, `-` and `_`, starting with a
letter, at most 32 bytes. Groups are a pipeline's own: `[defaults]` can't
have them, and no flag sets them. They are stored in
`orca.pipelines.groups` (migration 70), and `morca config show` lists each
as `groups.<group>`. The `ec2` placement ignores groups, and `morca
register` and `morca config check` warn when a pipeline placed on it
declares some.
as `groups.<group>`. `morca register` and `morca config check` warn when
a pipeline placed on `ec2` declares groups, which that placement ignores
(its tasks of a group fail there: place it on a pool instead), and when a
pipeline placed on `control` gives a group `cpus` or `memory_gb`, which
the control host ignores.

On a pool, each group's members are its own:

Expand Down Expand Up @@ -399,6 +406,34 @@ On a pool, each group's members are its own:
such a worker starts a run as a cluster; one without stays queued, held
saying so.

#### Groups off a pool

The local runner, the control host and Kubernetes start each group's
workers beside the workers with no group, from the run's start to its end.
None of them scales: each group gets its MAX (a count is its own), the
MIN of a range is used only where demand is reported, on a pool.

- **Local runner and `control`.** The run's process forks its dista
workers itself: as before, `MORCA_WORKERS` with no group (control's
`MORCA_CONTROL_WORKERS`), and now also each group's MAX, which it reads
from `MORCA_GROUPS` (`gpu=2,io=1`). The run is admitted and granted as
one: its groups' `gpus` for each of their MAX workers are part of its
request, held from the scheduler's host's GPUs (`MORCA_HOST_GPUS`, else
`nvidia-smi -L`) and given to the run's process in `MORCA_GRANT_GPUS`
and `CUDA_VISIBLE_DEVICES`, which all its workers see. A run that asks
for more GPUs than the host has waits, saying so ("waiting: needs 2
GPUs, more than the 1 this host grants at most"). A group's `cpus` and
`memory_gb` aren't used: the workers share the run's grant.
- **Kubernetes.** Each worker of a group is a pod of its own,
`morca-<run>-<start>-worker-<group>-<i>` (an `_` in the name becomes
`-`), labelled `orca.group`, with `DISTA_GROUP=<group>`. It is sized as
the pipeline's workers are ([On Kubernetes](#on-kubernetes)) from the
group's `cpus` and `memory_gb`, the pipeline's where it sets none, and a
group's `gpus` are in its limits as `nvidia.com/gpu`, which a cluster
with NVIDIA's device plugin schedules; inside the pod they are numbered
from 0 in `MORCA_GRANT_GPUS` and `CUDA_VISIBLE_DEVICES`. The groups'
pods count towards the run's `cpu_millis` and the vCPU budget.

### On Kubernetes

A run's driver, and each of its dista workers, asks for the pipeline's
Expand Down
6 changes: 4 additions & 2 deletions docs/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,10 @@ reports demand, it starts with MIN and grows by demand. With reporting
turned off, or a head on a worker from before this, a range still asks for
MAX at once.

Only pools use groups for now: a local run, `control`, Kubernetes and the
`ec2` placement start their workers as before, with no group.
Off a pool, the local runner, `control` and Kubernetes start each group's
MAX of workers for the run's life, without demand
([morca-toml.md](morca-toml.md#groups-off-a-pool)); the `ec2` placement
ignores groups.

**On a pool morca grows** (`[pools.<name>]`), this is set up for you:
- every Hetzner machine joins a private network of the stack's, and its
Expand Down
10 changes: 5 additions & 5 deletions src/morca/_internal/config.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ from morca._internal.fill import (
)
from morca._internal.groups import (
Group,
ec2_ignores_groups,
placement_warnings,
groups_json,
groups_problem,
read_groups,
Expand Down Expand Up @@ -684,12 +684,12 @@ struct ProjectConfig(Movable):
return read_groups(self.doc, pipeline)

def group_warnings(self) raises -> List[String]:
"""`file:line: [pipelines.<name>] ...` for each pipeline placed on
`ec2` that declares groups, which that placement ignores."""
"""`file:line: [pipelines.<name>] ...` for what each pipeline's
groups are ignored for where it's placed
(`morca._internal.groups.placement_warnings`)."""
var out = List[String]()
for p in self.pipelines():
var why = ec2_ignores_groups(p, self.placement(p), self.groups(p))
if why:
for why in placement_warnings(p, self.placement(p), self.groups(p)):
out.append(
String(
self._loc(["pipelines", p, "groups"]),
Expand Down
15 changes: 10 additions & 5 deletions src/morca/_internal/control.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ image's). Small runs then start in a second, without an instance to boot.

A run held by either of the last two stays queued with the reason in
`runs.held`, which its page and JSON show. dista inside such a run is in
local mode, `MORCA_CONTROL_WORKERS` (1) forked workers.
local mode, `MORCA_CONTROL_WORKERS` (1) forked workers with no group, and
each worker group's MAX (docs/groups.md, `morca._internal.provider`).

**Secrets** (`--secret NAME=ID`) are read by the scheduler when it starts
the run, with `MORCA_SECRET_FETCH` as the instances read them, else from
Expand All @@ -45,6 +46,7 @@ from json import loads
from morca._internal.awsjson import aws_json
from morca._internal.json import quote
from morca._internal.proc import binary_seconds, capture
from morca._internal.provider import local_env
from morca._internal.system import Now

comptime CONTROL = "control"
Expand Down Expand Up @@ -212,12 +214,15 @@ def run_env(
limits: ControlLimits,
image: String,
secrets: List[Tuple[String, String]],
groups: String = "",
) -> List[String]:
"""What a control-placed run's process gets beside the scheduler's
environment: its local workers, its image (which its version records)
and its secrets' values, `secrets` being (NAME, value) pairs, named in
`MORCA_SECRETS`."""
var out: List[String] = [String("MORCA_WORKERS=", limits.workers)]
environment: its local workers and those of its `groups`
(`name=count,...`), as the control provider gives them
(`morca._internal.provider.local_env`), its image (which its version
records) and its secrets' values, `secrets` being (NAME, value) pairs,
named in `MORCA_SECRETS`."""
var out = local_env(CONTROL, limits.workers, groups)
if image:
out.append(String("MORCA_IMAGE=", image))
out.extend(secrets_env(secrets))
Expand Down
Loading
Loading