Files
lightcraft/crates/segment
helgehelge123andClaude Opus 5.5 48a002e73a M12: SAM 3 accelerator plumbing: backend choice, CPU fallback and the AI masks setting
Part 1 of 5 of #2167. lightcraft-segment gets a BackboneAccel trait
(backbone, plus optional necks, DETR encoder and mask decoder, asked only
when runs_heads()), WeightReader and Sam3::load_accelerated. Whatever an
accelerator returns is checked (length, finite values); an error, a wrong
size or a NaN falls back to candle, logged once, with the reason kept for
the status. The engine worker places the model (Metal on macOS, the CPU
elsewhere, or the CPU when chosen or switched off), reloads it when a GPU
switch or the setting changes, and reports where it ran in
segment.model.status. Settings > Performance > AI masks gets Run on:
Automatic / CPU.

#2067's retry is kept: a job that fails on candle's GPU (Metal) runs once
more on the CPU, which then serves the session (now a placement with the
reason); LIGHTCRAFT_GPU=0 / LIGHTCRAFT_GPU_BACKEND=off keep the model on the
CPU on macOS too. #1963's semantic mask comes from the mask decoder as
before (on an accelerator: one more row of its mask product).

This build has no GPU backbone (GPU_BACKBONE is None), so the GPU path is
off: outside macOS candle runs everything on the CPU, as on main.

Also on the CPU: the text features of the last 16 prompts are cached per
model, and the detector's box relative-position bias is one pass, with the
decoder MLPs' bias and ReLU fused (bit-identical outputs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 20:52:47 +02:00
..