Skip to content

Fix two crashes on the Mac's GPU and an unfitted-manifold error, for 5.4.1 - #67

Merged
a9lim merged 4 commits into
mainfrom
fix/probe-gpu-race
Nov 1, 2026
Merged

a9lim merged 4 commits into
mainfrom
fix/probe-gpu-race

Conversation

@a9lim

@a9lim a9lim commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Three fixes for 5.4.0 on Apple-silicon Macs, for a 5.4.1 release. 6.0 will not read 5.x saved chats, so 5.4 stays in use for a while.

Fixes

The server could abort while a reply streamed (MPS). Every device operation on MPS goes through one global command buffer that is not thread-safe. Three request handlers copied tensors off the GPU without the lock while another thread generated: GET /probes (each geometry probe's node coordinates), GET /probes/{name}/geometry (the whitened factors) and POST /tree/transcript (hashing a probe). The server then died on failed assertion _status < MTLCommandBufferStatusCommitted. Attach already builds each geometry probe from a host copy, so it now keeps what those readers need from that copy, and the readers never touch the device. Digests and inspector payloads are byte-identical to 5.4.0's, so 5.4.0 transcripts still verify. A guarded six-round stress recorded no off-thread MPS operation, where the old code made about 197,000.

Attaching an unfitted multi-node manifold failed after minutes of work. POST /probes naming an installed manifold with no fit for the model (emotions, personas) fell back to extraction: it fitted every node, wrote the fit, and only then failed with a bare ValueError (a scrubbed 500). It now refuses up front with a ManifoldSpecError (400) that names the fit command, before any corpus or fit work.

Any flat steering term beside a curved % term failed to install on MPS. The affine synthesis runs on the host at install, while a curved manifold's basis lives on the GPU, so orthogonalising one against the other mixed devices. The basis is now moved to the synthesis device first (drowse/steering/hooks.py).

Tests

  • New: tests/server/test_probe_device_reads.py, the multi-node extraction refusal, the monitor/probe-geometry payload tests, and tests/gpu/test_session.py::TestMixedSteering (flat + curved steering on MPS).
  • CPU suite: 4,872 passed, 7 skipped.
  • GPU suite on MPS (SmolLM2-360M-Instruct): 48 passed and 1 skipped; the steered-throughput gate failed once while other jobs loaded the machine (load average about 7), then passed on two reruns at load 12–25, as it does on 5.4.0 under the same load.
  • TestMixedSteering fails on MPS without the hooks fix and passes with it.

Release

The version is not bumped here. Bump __version__ in drowse/__init__.py to 5.4.1 before merging; the push to main then tags, publishes to PyPI and cuts the release.

a9lim added 4 commits October 31, 2026 20:01
On MPS, every device op goes through one global command buffer that is not
thread-safe, and a copy off the device on a request thread while another
thread's model op holds it aborts the server (failed assertion _status <
MTLCommandBufferStatusCommitted). Three readers did that without the lock:
GET /probes copied each geometry probe's resident node_coords,
GET /probes/{name}/geometry copied the whitened factors, and POST
/tree/transcript folded and copied the resident basis to hash a probe. A
guard that flags MPS ops made off the GPU lock recorded about 197,000 of them
from these three while replies streamed on SmolLM2.

Attach already builds a geometry probe from a host copy, so it now keeps what
those readers need from that copy before the upload
(AttachedManifoldProbe.node_coords_host, .geometry and .digest). The listing
reads the node coords, Monitor.probe_geometry lists the inspector payload
(monitor_attach.probe_geometry_payload, moved from the Monitor with the same
output; its arrays stay fp32 host tensors that pack_to_device skips), and
GeometryInstrument.probe_hash reads the digest (monitor_attach.probe_digest,
hashing rule unchanged). The inspector stays lock-free on purpose: taking the
session lock instead made it wait out a whole streamed reply, past a 30 s
client timeout under the same stress. The token replay renders its ids, which
uploads them, inside the exclusive section.

On MPS the host digests and geometry payloads equal what the resident path
produced (every default probe plus the curved emotions manifold, digests
equal and payloads byte-identical), so 5.4.0 transcripts still verify, and a
six-round guarded stress records no off-thread MPS op.
A probe selector naming an installed manifold that is not fitted for the
model falls back to extraction. For a multi-node manifold (emotions,
personas) extraction reused the folder, fitted every node, wrote and adopted
the fit, and only then failed to fold it into one direction with a bare
ValueError, so POST /probes answered a scrubbed 500 after minutes of work
(and a retry then succeeded off the fit the failure had written). Reusing a
folder of more than two nodes is now a ManifoldSpecError (400) with the fit
command, raised under the manifest lock before any corpus or fit work.
The affine synthesis is host-side at install while a curved manifold's
basis is resident on the session device, so any affine term beside a
curved % term failed to install on MPS (present since 5.4.0).
Keeps the lock-free probe readers off the GPU, refuses to extract a multi-node manifold as a vector before fitting it, and installs affine steering beside a curved term on MPS.
@a9lim
a9lim enabled auto-merge November 1, 2026 15:14
@a9lim
a9lim merged commit 6678a17 into main Nov 1, 2026
12 checks passed
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