Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fc69aec
fix: use concurrent pread for Qwen4-Exp PLE row lookups (~10x SSD thr…
scott-kim-7 Sep 8, 2026
7c192ab
feat(cluster): add qualification, staging, planning, and deployment (…
jonathan308 Sep 8, 2026
cd7d533
test: tighten PLE prefetch regression coverage (#3287)
jundot Sep 8, 2026
9fb488c
fix(cluster): reload deployments when model paths change
jundot Sep 8, 2026
e9a89d5
distributed: verified teardown with SIGKILL retry, rank-marker sweep,…
jonathan308 Aug 18, 2026
c33117d
distributed: unit tests for verified teardown, rank sweep, and launch…
jonathan308 Aug 18, 2026
8548043
distributed: rank-side force-cancel hook driven by a coordinator canc…
jonathan308 Aug 18, 2026
ff7b1ca
distributed: require rank-side quiescence evidence in pool unload gate
jonathan308 Aug 18, 2026
03d83f5
distributed: surface abort (not transport error) when a closed stream…
jonathan308 Aug 18, 2026
b3873ac
distributed: graduated PeerWatchdog response — abort before exit
jonathan308 Aug 18, 2026
ba65273
distributed: widen launcher watchdog, wire abort stages on both watch…
jonathan308 Aug 18, 2026
8062c7b
runtime: jaccl-if-all-rdma_ctl-else-ring selection; N-node manifest +…
jonathan308 Aug 19, 2026
716591f
fix(cluster): close thundermlx stability gaps — unwire before kill, M…
jonathan308 Aug 22, 2026
a90f17f
Let rank-ready markers own the load barrier
jonathan308 Aug 22, 2026
5f8f0f9
Gate serving on every rank-ready marker
jonathan308 Aug 22, 2026
0e73850
Separate rank control from tensor collectives
jonathan308 Aug 22, 2026
c059256
Use sustained cluster readiness canary
jonathan308 Aug 22, 2026
df0d1a0
Clear stale cluster engines after reused PGIDs
jonathan308 Aug 23, 2026
5706dbf
Ignore cluster control JSON in runtime marker reader
jonathan308 Aug 22, 2026
763b547
Bootstrap JACCL through resilient side channel
jonathan308 Aug 24, 2026
0a205c4
Route JACCL bootstrap through macOS sidecar
jonathan308 Aug 24, 2026
ca2690d
Hold a process lease for JACCL RDMA
jonathan308 Aug 24, 2026
633e48e
fix(cluster): verify rank exit on unload
jonathan308 Aug 26, 2026
0e38d5c
fix(cluster): keep control transport on the runtime layer
jonathan308 Aug 26, 2026
85680c8
fix(cluster): fail closed when rank exit cannot be proven
jonathan308 Aug 26, 2026
c02055e
test(cluster): mark runtime-first UI seams explicitly
jonathan308 Aug 26, 2026
0ff8237
fix(cluster): authenticate rank-control admission without listener DoS
jonathan308 Aug 26, 2026
1d7428b
fix(cluster): replace public plan hash with launch-scoped control secret
jonathan308 Aug 26, 2026
e3eac11
fix(cluster): mutually authenticate rank-control sessions and payloads
jonathan308 Aug 26, 2026
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
5 changes: 5 additions & 0 deletions docs/distributed-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ KV cache stays on the rank that owns the corresponding layers. Centralizing KV
on one Mac would add a network read/write to every layer and generated token,
so it is not the default.

Each inference rank and synthetic performance worker also holds a kernel-owned
`flock` lease for the device. The lease releases automatically on crash or
SIGKILL, so it prevents cross-process races without creating a stale-lock
recovery problem.

## Requirements

On every Mac:
Expand Down
158 changes: 158 additions & 0 deletions omlx/cluster/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# SPDX-License-Identifier: Apache-2.0
"""Per-cluster collective backend selection: JACCL everywhere, or TCP ring.

The rule is deliberately binary and fail-safe: ``jaccl`` is selected only when
**every** cluster member reports ``rdma_ctl`` enabled *and* at least one RDMA
device; anything else selects the TCP ``ring``. A single member without RDMA
silently downgrading only its own stage is exactly how half-configured JACCL
clusters hang at ``mx.distributed.init`` — the whole cluster shares one
backend, so the weakest member decides, out loud.

This module is pure: members arrive as data (from ``collect_cluster_status``
locally, from peer probes remotely, or from posted host records), which keeps
selection offline-testable. Live ``rdma_ctl`` state is re-verified at launch
preflight; a selection made from stale evidence can only fail closed there.

Ring is a first-class runtime path, not a degraded one: ring deployments run
through the same ``DistributedJobSupervisor`` verified teardown (process-group
SIGTERM→SIGKILL escalation with proof, plus the marker-pid rank sweep —
including remote ranks over SSH) as JACCL deployments. Nothing in the teardown
machinery is backend-conditional.
"""

from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass, field
from typing import Any


@dataclass(frozen=True)
class MemberFabric:
"""One member's RDMA capability, as observed by a probe or host record."""

node_id: str
rdma_ctl_enabled: bool = False
rdma_devices: tuple[str, ...] = ()

def __post_init__(self) -> None:
if not self.node_id:
raise ValueError("member node_id is required")
object.__setattr__(self, "rdma_devices", tuple(sorted(set(self.rdma_devices))))

@property
def jaccl_ready(self) -> bool:
return self.rdma_ctl_enabled and bool(self.rdma_devices)

def to_dict(self) -> dict[str, Any]:
return {
"node_id": self.node_id,
"rdma_ctl_enabled": self.rdma_ctl_enabled,
"rdma_devices": list(self.rdma_devices),
"jaccl_ready": self.jaccl_ready,
}


@dataclass(frozen=True)
class BackendSelection:
"""The backend a whole cluster will use, and why."""

backend: str # "jaccl" | "ring"
reason: str
blockers: tuple[str, ...] = ()
members: tuple[MemberFabric, ...] = field(default_factory=tuple)

def to_dict(self) -> dict[str, Any]:
return {
"backend": self.backend,
"reason": self.reason,
"blockers": list(self.blockers),
"members": [member.to_dict() for member in self.members],
}


def select_cluster_backend(members: Iterable[MemberFabric]) -> BackendSelection:
"""Pick ``jaccl`` when rdma_ctl is enabled on ALL members, else ``ring``.

``jaccl-ring`` (Thunderbolt without RDMA) remains manually selectable on
the deployment endpoints; automatic selection never picks it because its
hostfile still needs a complete RDMA device matrix, which "no RDMA"
members by definition cannot supply.
"""

members = tuple(members)
if len(members) < 2:
raise ValueError("backend selection needs at least two cluster members")
node_ids = [member.node_id for member in members]
if len(set(node_ids)) != len(node_ids):
raise ValueError("cluster member node IDs must be unique")

blockers = tuple(member.node_id for member in members if not member.jaccl_ready)
if not blockers:
return BackendSelection(
backend="jaccl",
reason=(
f"rdma_ctl is enabled with RDMA devices on all {len(members)} members"
),
members=members,
)
details = []
for member in members:
if member.jaccl_ready:
continue
if not member.rdma_ctl_enabled:
details.append(f"{member.node_id} has rdma_ctl disabled")
else:
details.append(f"{member.node_id} reports no RDMA device")
return BackendSelection(
backend="ring",
reason=(
"JACCL needs rdma_ctl enabled on every member; falling back to "
"the TCP ring for the whole cluster (" + "; ".join(details) + ")"
),
blockers=blockers,
members=members,
)


def members_from_host_records(hosts: Iterable[Any]) -> tuple[MemberFabric, ...]:
"""Derive member fabric evidence from posted host records.

A host that carries a complete RDMA connectivity matrix (one entry per
peer, null diagonal, no null off-diagonal) is treated as rdma_ctl-enabled:
that matrix can only be produced from live interface names. This is
request evidence, not a probe — launch preflight re-verifies the live
state, so stale input fails closed at activation rather than launching a
collective that blocks.
"""

hosts = list(hosts)
size = len(hosts)
members: list[MemberFabric] = []
for host in hosts:
rdma = list(getattr(host, "rdma", ()) or ())
complete = len(rdma) == size and size >= 2
devices: list[str] = []
if complete:
for index, path in enumerate(rdma):
expected_none = index == len(members)
if expected_none:
if path is not None:
complete = False
break
continue
if path is None:
complete = False
break
if isinstance(path, (list, tuple)):
devices.extend(str(item) for item in path)
else:
devices.append(str(path))
members.append(
MemberFabric(
node_id=str(getattr(host, "node_id", "")),
rdma_ctl_enabled=complete,
rdma_devices=tuple(devices) if complete else (),
)
)
return tuple(members)
47 changes: 33 additions & 14 deletions omlx/cluster/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def context_is_limited(self) -> bool:
"""Does memory, not the model, set the usable context?"""

declared = self.declared_context_tokens
return bool(
self.fits and declared and self.max_context_tokens < declared
)
return bool(self.fits and declared and self.max_context_tokens < declared)

def describe(self) -> str:
"""One line a person can act on."""
Expand Down Expand Up @@ -175,12 +173,17 @@ def _splits(
*,
tensor_parallel_ok: bool,
pipeline_ok: bool = True,
prefer_tensor: bool = False,
) -> tuple[tuple[int, int], ...]:
"""Every (tensor_parallel_size, pipeline_stages) this cluster can form.

Ordered fewest-nodes-first, then pipeline before tensor parallelism at
equal width: pipeline loads faster, uses less memory, and survives a
slow link, so it is the better answer when both fit.
Ordered fewest-nodes-first. At equal width the default is pipeline before
tensor parallelism: pipeline loads faster, uses less memory, and survives
a slow link, so it is the better answer when both fit and nothing is
known about the link. ``prefer_tensor`` flips the tie-break for callers
that know every link is fast (JACCL/Thunderbolt): there, splitting each
layer's compute across the group cuts per-token latency, which is what a
user who just cabled two Macs together is after.
"""

options: list[tuple[int, int]] = []
Expand All @@ -196,7 +199,15 @@ def _splits(
# weights and then fail at load.
continue
options.append((tp, used // tp))
return tuple(sorted(options, key=lambda item: (item[0] * item[1], item[0])))
return tuple(
sorted(
options,
key=lambda item: (
item[0] * item[1],
-item[0] if prefer_tensor else item[0],
),
)
)


_SHORTFALL_RE = re.compile(r"\bat least (\d+) additional bytes required\b")
Expand Down Expand Up @@ -340,11 +351,14 @@ def assess_model(
tensor_parallel_ok: bool | None = None,
pipeline_ok: bool | None = None,
workload_profile: str = "balanced",
prefer_tensor: bool = False,
) -> ModelFit:
"""Whether this model runs here, using the fewest nodes that work.

``tensor_parallel_ok`` defaults to what the layout already determined, so
a model mlx-lm cannot shard is never offered a tensor-parallel plan.
``prefer_tensor`` requests the tensor-parallel split when both strategies
fit at equal width — callers set it when every link is known-fast.
"""

if tensor_parallel_ok is None:
Expand All @@ -361,16 +375,15 @@ def assess_model(
len(nodes),
tensor_parallel_ok=tensor_parallel_ok,
pipeline_ok=pipeline_ok,
prefer_tensor=prefer_tensor,
)
for tp_size, stages in splits:
used = tp_size * stages
# Nodes are rank-ordered; a narrower split uses the first `used` of
# them, which is where the fast links were placed. Ranks are positional
# to the planner and must be contiguous from zero, so a subset — or a
# caller's single node that happened to be rank 1 — is renumbered.
subset = [
replace(node, rank=index) for index, node in enumerate(nodes[:used])
]
subset = [replace(node, rank=index) for index, node in enumerate(nodes[:used])]
plan, reason = _plan_or_none(
layout,
subset,
Expand Down Expand Up @@ -466,9 +479,7 @@ def assess_model(
if standalone_node_id:
failure_kind = "single_node_only"
context = (
f" at up to {standalone_context:,} tokens"
if standalone_context
else ""
f" at up to {standalone_context:,} tokens" if standalone_context else ""
)
last_reason = (
"This model cannot combine Macs because mlx-lm supports neither "
Expand Down Expand Up @@ -508,6 +519,7 @@ def assess_model_path(
nodes: Sequence[NodeBudget],
*,
workload_profile: str = "balanced",
prefer_tensor: bool = False,
) -> ModelFit:
"""Assess a model directory, reading its real layout and config."""

Expand Down Expand Up @@ -536,6 +548,7 @@ def assess_model_path(
model_id=root.name,
declared_context_tokens=declared,
workload_profile=workload_profile,
prefer_tensor=prefer_tensor,
)


Expand All @@ -544,6 +557,7 @@ def catalogue_for_cluster(
nodes: Sequence[NodeBudget],
*,
workload_profile: str = "balanced",
prefer_tensor: bool = False,
) -> tuple[ModelFit, ...]:
"""Assess every model, largest first among those that fit.

Expand All @@ -553,7 +567,12 @@ def catalogue_for_cluster(
"""

fits = [
assess_model_path(path, nodes, workload_profile=workload_profile)
assess_model_path(
path,
nodes,
workload_profile=workload_profile,
prefer_tensor=prefer_tensor,
)
for path in model_paths
]
runnable = sorted(
Expand Down
Loading