Four items from one workflow, committed together because their build and CI
wiring genuinely interleaves — nisps/CMakeLists.txt, run-all-tests.sh and
ci.yml each carry hunks from two of them, and the stage renumbering (1/5 ->
1/6) touches every line. Splitting would produce commits that do not build,
which is worse than a commit that does four things and says so.
S26 part 2 — the curve declaration now matches reality. params[].curve stays
the mode-wide DEFAULT; a voice_spaces entry may now be {name, curve_overrides}
declaring only the slots where THAT voice space deviates. The 6 modes with one
voice space are byte-identical. The values were derived MECHANICALLY by a new
codegen/curve-audit.ts that models the four idioms a p[N]*p[N] regex misses
(alias form, memlcelium's implicit-counter sq() lambda, loop-generated indices,
smooth_params_), inlines helpers, and RAISES rather than guessing when it
cannot reduce an expression. A drift gate cross-checks 1179 (voice space x
param) slots against engine source on every run and was proved to fail loudly
on three drift classes. Application stays in the engine: nisps/engines,
nisps/pipeline and nisps/core are untouched, generated output is pure insertion
(755 insertions, 0 deletions), and the rebuilt nisps.wasm was byte-identical.
S4 / 7.2 — firmware reads the active mode's driver config at mode start, and
mic/line is real. My brief assumed the engine owns this; the code disagreed and
the code was right. sound_analysis_midi's EngineT is NoOpEngine — the mic lives
on a separately-composed AnalysisEngine member — so engine-level wiring would
have compiled, passed every gate, and left the one mic mode on line input.
Hence a mode-level seam defaulting to engine().driver_config(). Separately,
DriverConfig's defaults (line_level 0, output_volume 1.0) had drifted from
memllib's actual 3/0.8 because nothing had ever read them; wiring them as-is
would have made every silent mode louder and its line input maximally
insensitive — a behaviour change disguised as plumbing. Now pinned by a test.
Also: GetSysClockSpeed() panic()s on unsupported sample rates and runs on the
first line of setup(), so sample_rate needed a fallback ahead of clock setup.
CI's firmware env list gains soundanalysismidi — it is the only mic variant and
nothing else compiles that path.
Plan 5e — telemetry is real. A loss_history C-API entry across the full 5-layer
chain lets the browser read the per-iteration loss the core already records.
The audit named one fabrication site; there were two — wasm-iml.ts's
synchronous train() published lossHistory: [loss] as well. A third, ctx.loss,
was not merely dead but actively synthetic (fallbacks of prev * 0.82 and a
literal 0.5, rendered by nothing) and is deleted. The firmware buffer stays
untouched, per the L25 call. EngineApi.lossHistory() reads spine state rather
than the MLP handle, because trainAsync() fits on the worker's mirror net and
the handle would give a subtly-wrong second answer.
Plan 5f — engine throughput is measurable. One source compiled twice (CMake
natively, emcc for WASM) so the targets compare directly and no WASM export is
added. Sequencers are driven into a working state, and every row prints its own
working-state evidence so a number produced by an idle engine is visible rather
than plausible. Reports, never asserts: a wall-clock threshold on shared
hardware is meaningless or flaky, same call as the firmware size job.
ALIGNMENT: the telemetry defect is deleted (built, not deferred); the
performance defect is rewritten to what is actually left — these are HOST
numbers, and nothing measures the RP2350 at 150 MHz, which is the target the
mission's constraint is about. Q4 (memllib ownership) and Q5 (legacy feedback
modes) are closed.
Corrections to my own earlier claims, both found by agents contradicting the
brief: manifold/ONBOARDING.md was NOT "now accurate" — its primitives list
still named five deleted primitives and cited a seededGradient() that does not
exist. And the parity harness misses the sequencer engines because it runs 128
frames while their sequencers evaluate every 400-500 samples, NOT because
all-params-0.5 fails to trigger them (it does trigger: 0.5 maps to ratio 2,
firing three times per bar). The fix is a longer window, not different params.
Gates: run-all-tests.sh ALL GREEN — 4/4 ctest, parity PASS, lint clean, curve
drift 1179 slots ok, 39 e2e (was 33). Firmware: 5 envs built including the mic
variant.
159 lines
5.2 KiB
TypeScript
159 lines
5.2 KiB
TypeScript
/**
|
|
* TrainingHealth — the advanced-surface answer to "is the network learning?".
|
|
*
|
|
* Every number here is read live out of the C++ core:
|
|
* - the loss curve is `nisps::ml::MLPCore::loss_history` (one entry per SGD
|
|
* iteration of the last training run), read through `nisps_ml_loss_history`
|
|
* and published on the spine by both the sync and the worker train paths;
|
|
* - the per-layer weight health is `nisps::ml::compute_layer_stats`, read
|
|
* through the already-plumbed `nisps_ml_get_layer_stats`.
|
|
*
|
|
* NOTHING is synthesised. When the core has no history (nothing trained yet)
|
|
* this renders a plain "no training run yet" line rather than a plausible
|
|
* placeholder plot — that distinction is the entire point of this panel
|
|
* (ALIGNMENT defect 6 / simplification-plan §6.5e).
|
|
*
|
|
* It is a component (not a plain render helper like its sibling drawer
|
|
* sections) precisely so it can hold the engine hooks and re-read on version
|
|
* bumps without dragging the whole Console into a re-render.
|
|
*
|
|
* Surfaced only at the Learning drawer's `expanded` depth — Manifold's existing
|
|
* advanced-surface mechanism (`DrawerDepth`), not a new flag.
|
|
*/
|
|
import { useEngine, useEngineVersion } from '../engine';
|
|
|
|
const W = 320;
|
|
const H = 64;
|
|
|
|
function fmt(v: number, dp = 4): string {
|
|
if (!Number.isFinite(v)) return '—';
|
|
return v.toFixed(dp);
|
|
}
|
|
|
|
function pct(v: number): string {
|
|
if (!Number.isFinite(v)) return '—';
|
|
return `${(v * 100).toFixed(1)}%`;
|
|
}
|
|
|
|
const mono = {
|
|
fontSize: 10,
|
|
fontFamily: 'var(--font-mono)',
|
|
color: 'var(--fg-mute)',
|
|
} as const;
|
|
|
|
/** Per-iteration loss curve, log-scaled on y (loss spans orders of magnitude). */
|
|
function LossPlot({ history }: { history: ReadonlyArray<number> }) {
|
|
const n = history.length;
|
|
// A single point has no curve to draw; the readout below still reports it.
|
|
if (n < 2) return null;
|
|
|
|
const logs = history.map((v) => Math.log10(Math.max(v, 1e-9)));
|
|
let lo = Infinity;
|
|
let hi = -Infinity;
|
|
for (const l of logs) {
|
|
if (l < lo) lo = l;
|
|
if (l > hi) hi = l;
|
|
}
|
|
const span = hi - lo < 1e-6 ? 1 : hi - lo;
|
|
|
|
const pts = logs
|
|
.map((l, i) => {
|
|
const x = (i / (n - 1)) * W;
|
|
const y = H - ((l - lo) / span) * H;
|
|
return `${x.toFixed(2)},${y.toFixed(2)}`;
|
|
})
|
|
.join(' ');
|
|
|
|
return (
|
|
<svg
|
|
viewBox={`0 0 ${W} ${H}`}
|
|
preserveAspectRatio="none"
|
|
role="img"
|
|
aria-label={`Training loss over ${n} iterations, ${fmt(history[0])} down to ${fmt(history[n - 1])}`}
|
|
style={{
|
|
width: '100%',
|
|
height: H,
|
|
display: 'block',
|
|
background: 'var(--bg-2)',
|
|
border: '1px solid var(--line)',
|
|
borderRadius: 'var(--r-sm, 4px)',
|
|
}}
|
|
>
|
|
<polyline
|
|
points={pts}
|
|
fill="none"
|
|
stroke="var(--accent)"
|
|
strokeWidth={1.5}
|
|
vectorEffect="non-scaling-stroke"
|
|
/>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function TrainingHealth() {
|
|
const engine = useEngine();
|
|
// Re-read on every engine state change (training publishes a new history).
|
|
useEngineVersion(engine);
|
|
|
|
if (!engine) {
|
|
return <p style={{ ...mono, margin: 0 }}>engine not ready</p>;
|
|
}
|
|
|
|
const history = engine.lossHistory();
|
|
const stats = engine.getLayerStats();
|
|
const first = history.length ? history[0] : null;
|
|
const last = history.length ? history[history.length - 1] : null;
|
|
|
|
return (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
{history.length === 0 ? (
|
|
<p style={{ ...mono, margin: 0 }}>
|
|
no training run yet — the loss curve appears after the first fit
|
|
</p>
|
|
) : (
|
|
<>
|
|
<LossPlot history={history} />
|
|
<div style={{ ...mono, display: 'flex', gap: 12, flexWrap: 'wrap' }}>
|
|
<span>{history.length} iter</span>
|
|
<span>start {fmt(first ?? 0)}</span>
|
|
<span style={{ color: 'var(--accent)' }}>end {fmt(last ?? 0)}</span>
|
|
<span>
|
|
{first !== null && last !== null && last < first
|
|
? 'converging'
|
|
: 'not improving'}
|
|
</span>
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
<table
|
|
style={{ ...mono, width: '100%', borderCollapse: 'collapse', textAlign: 'right' }}
|
|
>
|
|
<thead>
|
|
<tr style={{ color: 'var(--fg-dim)' }}>
|
|
<th style={{ textAlign: 'left', fontWeight: 400 }}>layer</th>
|
|
<th style={{ fontWeight: 400 }}>mean|w|</th>
|
|
<th style={{ fontWeight: 400 }}>max|w|</th>
|
|
<th style={{ fontWeight: 400 }}>dead</th>
|
|
<th style={{ fontWeight: 400 }}>sat</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{stats.map((s, i) => (
|
|
<tr key={i}>
|
|
<td style={{ textAlign: 'left' }}>L{i}</td>
|
|
<td>{fmt(s.meanAbs, 3)}</td>
|
|
<td>{fmt(s.maxAbs, 3)}</td>
|
|
<td>{pct(s.deadFrac)}</td>
|
|
<td>{pct(s.saturatingFrac)}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<p style={{ ...mono, margin: 0, color: 'var(--fg-dim)', lineHeight: 1.5 }}>
|
|
dead = |w| < 0.001, sat = |w| > 3 (nisps/ml/stats.hpp). A layer that is
|
|
mostly dead or mostly saturating is not learning usefully.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|