Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 08798728b463f0710edd5c90308e2fabde198525
parent 4441f5eec0122328c6ac952c39ddacc9098b0643
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon, 16 Nov 2026 08:38:34 -0500

tts tuning: quantise decimals, one shared normaliser and its defaults

parseTtsTuning rounds temperature, top_p, min_p and repeat_penalty to 3
places (-0 as 0) before the range check, so 0.550000001 is the default
(main's key) and 0.7000000000000001 keys as 0.7. normalizeTtsTuning and
ORPHEUS_TUNING_DEFAULTS move into lib/ttsTuning.mjs so umtool normalises
as the editor does; ttsApps.ts uses it, and a test holds the defaults equal
to ORPHEUS_SAMPLER and the settings' takes. The golden pins stay green.
The plan's S1 says changing ORPHEUS_SAMPLER needs a CACHE_KEY_VERSION bump.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/ttsFile.test.ts | 7+++++++
Mcommon/lib/ttsApps.test.ts | 8++++++++
Mcommon/lib/ttsApps.ts | 27+++++++++++++--------------
Mcommon/lib/ttsTuning.d.mts | 4++++
Mcommon/lib/ttsTuning.mjs | 49+++++++++++++++++++++++++++++++++++++++++++++----
Mcommon/lib/ttsTuning.test.ts | 32++++++++++++++++++++++++++++++++
Mplans/orpheus-retune.md | 4++++
7 files changed, 113 insertions(+), 18 deletions(-)

diff --git a/common/controller/ttsFile.test.ts b/common/controller/ttsFile.test.ts @@ -218,6 +218,13 @@ test("no tuning and no reading key as main did -- and so do the defaults spelled } }); +test("floats are quantised before the key: a default within rounding is main's key, 0.7000000000000001 keys as 0.7, -0 as 0", () => { + assert.equal(goldenKey("orpheus", { tuning: { temperature: 0.550000001, top_p: 0.8500000001, repeat_penalty: 1.2000004 } }), GOLDEN_SHA_MAIN.orpheus); + assert.equal(goldenKey("orpheus", { tuning: { min_p: -0, top_k: -0 + 50 } }), GOLDEN_SHA_MAIN.orpheus); + assert.equal(goldenKey("orpheus", { tuning: { temperature: 0.7000000000000001 } }), goldenKey("orpheus", { tuning: { temperature: 0.7 } })); + assert.notEqual(goldenKey("orpheus", { tuning: { temperature: 0.7 } }), GOLDEN_SHA_MAIN.orpheus); +}); + test("a tuning or a reading is a new key for Orpheus; the same one again is the same key", () => { const seen = new Set<string>([GOLDEN_SHA_MAIN.orpheus]); for (const extra of [ diff --git a/common/lib/ttsApps.test.ts b/common/lib/ttsApps.test.ts @@ -17,6 +17,7 @@ import { normalizeOrpheusAsk, } from "./ttsApps"; import { DEFAULT_TTS_SETTINGS, sanitizeTts } from "./ttsSettings"; +import { ORPHEUS_DEFAULT_TAKES, ORPHEUS_TUNING_DEFAULTS } from "./ttsTuning.mjs"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test lib/ttsApps.test.ts @@ -247,6 +248,13 @@ test("a tuning changes only what it names; a reading moves the seed base by 9973 assert.deepEqual(o.keyExtra!(five, { tuning: { takes: 3 } }), o.keyExtra!(DEFAULT_TTS_SETTINGS)); }); +test("the shared defaults (lib/ttsTuning.mjs) are ORPHEUS_SAMPLER's and the settings' takes", () => { + for (const [k, v] of Object.entries(ORPHEUS_TUNING_DEFAULTS)) { + assert.equal(ORPHEUS_SAMPLER[k as keyof typeof ORPHEUS_SAMPLER], v, k); + } + assert.equal(DEFAULT_TTS_SETTINGS.orpheus.takes, ORPHEUS_DEFAULT_TAKES); +}); + test("kokoro and espeak-ng take no tuning: no key extra, no report", () => { for (const id of ["kokoro", "espeak-ng"]) { const e = getTtsEngine(id)!; diff --git a/common/lib/ttsApps.ts b/common/lib/ttsApps.ts @@ -36,7 +36,7 @@ import path from "node:path"; import { normalizeTtsText } from "./ttsText"; import { chunkTtsText, nPredictFor } from "./ttsChunk"; import type { TtsSettings } from "./ttsSettings"; -import { ttsReadingSeedBase, type TtsTuning } from "./ttsTuning.mjs"; +import { normalizeTtsTuning, ttsReadingSeedBase, type TtsTuning } from "./ttsTuning.mjs"; export type TtsDevice = "cpu" | "gpu"; @@ -242,23 +242,22 @@ export const ORPHEUS_SAMPLER = { } as const; export const ORPHEUS_SEED_BASE = 1234; -// The sampler knobs a tuning may set (lib/ttsTuning.mjs); repeat_last_n and the -// presence / frequency penalties stay as above. -const ORPHEUS_TUNED_SAMPLER = ["temperature", "top_p", "top_k", "min_p", "repeat_penalty"] as const; +// The sampler knobs a tuning may set are lib/ttsTuning.mjs's (its +// ORPHEUS_TUNING_DEFAULTS are these values; a test holds them equal); +// repeat_last_n and the presence / frequency penalties stay as above. +// +// NOTE: a change to a value above changes Orpheus's output WITHOUT changing an +// untuned ask's cache key (the key holds only what differs from the defaults): +// bump CACHE_KEY_VERSION (controller/ttsFile.ts) with it. /** - * An Orpheus ask with every value that EQUALS its default left out (the - * sampler's against ORPHEUS_SAMPLER, takes against settings.tts.orpheus.takes) - * and reading 0 dropped: `{}` is "no tuning". What the cache key holds. + * An Orpheus ask with every value that EQUALS its default left out (quantised + * first, lib/ttsTuning.mjs: the sampler's against its defaults, takes against + * settings.tts.orpheus.takes) and reading 0 dropped: `{}` is "no tuning". What + * the cache key holds. */ export function normalizeOrpheusAsk(tts: TtsSettings, ask: TtsAsk = {}): TtsAsk { - const tuning: TtsTuning = {}; - for (const k of ORPHEUS_TUNED_SAMPLER) { - const v = ask.tuning?.[k]; - if (v !== undefined && v !== ORPHEUS_SAMPLER[k]) tuning[k] = v; - } - const takes = ask.tuning?.takes; - if (takes !== undefined && takes !== tts.orpheus.takes) tuning.takes = takes; + const tuning: TtsTuning = normalizeTtsTuning(ask.tuning, { takes: tts.orpheus.takes }); return { ...(Object.keys(tuning).length ? { tuning } : {}), ...(ask.reading ? { reading: ask.reading } : {}), diff --git a/common/lib/ttsTuning.d.mts b/common/lib/ttsTuning.d.mts @@ -6,7 +6,11 @@ export type TtsTuningRange = { min: number; max: number; integer: boolean }; export const TTS_TUNING_RANGES: Readonly<Record<TtsTuningField, TtsTuningRange>>; export const TTS_TUNING_FIELDS: readonly TtsTuningField[]; +export const ORPHEUS_TUNING_DEFAULTS: Readonly<Record<Exclude<TtsTuningField, "takes">, number>>; +export const ORPHEUS_DEFAULT_TAKES: number; export const TTS_READING_MAX: number; +export function quantizeTtsTuningValue(field: TtsTuningField, value: unknown): unknown; +export function normalizeTtsTuning(tuning: unknown, opts?: { takes?: number }): TtsTuning; export const TTS_READING_SEED_STEP: number; export function ttsTuningRangeText(field: TtsTuningField): string; export function ttsTuningValueError(field: TtsTuningField, value: unknown, name?: string): string | null; diff --git a/common/lib/ttsTuning.mjs b/common/lib/ttsTuning.mjs @@ -30,6 +30,15 @@ export const TTS_TUNING_RANGES = Object.freeze({ export const TTS_TUNING_FIELDS = Object.freeze(Object.keys(TTS_TUNING_RANGES)); +/** + * Orpheus's defaults for the tunable fields: common/lib/ttsApps.ts + * ORPHEUS_SAMPLER's (a test holds the two equal) and the settings' default + * takes (ttsSettings.ts DEFAULT_ORPHEUS_TTS_SETTINGS.takes). Here so a caller in + * bare node (umtool) normalises a tuning as the editor does. + */ +export const ORPHEUS_TUNING_DEFAULTS = Object.freeze({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2 }); +export const ORPHEUS_DEFAULT_TAKES = 3; + /** The highest reading (the seed base stays under 2^31). */ export const TTS_READING_MAX = 99_999; @@ -39,6 +48,36 @@ export const TTS_READING_SEED_STEP = 9973; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const shown = (v) => (typeof v === "number" ? String(v) : JSON.stringify(v) ?? String(v)); +/** + * One field's value as it is checked, sent and keyed: a decimal field rounded + * to 3 places (0.550000001 is 0.55, 0.7000000000000001 is 0.7), -0 as 0. A + * value that is not a finite number is returned as it is (and refused). + */ +export function quantizeTtsTuningValue(field, value) { + if (typeof value !== "number" || !Number.isFinite(value)) return value; + const r = TTS_TUNING_RANGES[field]; + const q = r && !r.integer ? Math.round(value * 1000) / 1000 : value; + return q === 0 ? 0 : q; +} + +/** + * A tuning with every value that EQUALS its default left out (after + * quantising): the sampler's against ORPHEUS_TUNING_DEFAULTS, `takes` against + * `opts.takes` (the settings' takes; omitted: `takes` is kept as given). `{}` is + * "no tuning". Unknown and non-numeric fields are dropped. + */ +export function normalizeTtsTuning(tuning, { takes } = {}) { + const out = {}; + if (!isObj(tuning)) return out; + for (const k of TTS_TUNING_FIELDS) { + const v = quantizeTtsTuningValue(k, tuning[k]); + if (typeof v !== "number" || !Number.isFinite(v)) continue; + if (k === "takes" ? takes !== undefined && v === takes : v === ORPHEUS_TUNING_DEFAULTS[k]) continue; + out[k] = v; + } + return out; +} + /** "a number from 0.1 to 1.5" / "a whole number from 1 to 6". */ export function ttsTuningRangeText(field) { const r = TTS_TUNING_RANGES[field]; @@ -53,8 +92,9 @@ export function ttsTuningValueError(field, value, name = `"tuning.${field}"`) { } /** - * A tuning as asked: an object of the known fields, each in range. Undefined - * and null fields are left out; an empty result is `{}`. + * A tuning as asked: an object of the known fields, each quantised + * (quantizeTtsTuningValue) and then in range. Undefined and null fields are + * left out; an empty result is `{}`. * @returns {{ ok: true, value: Record<string, number> } | { ok: false, error: string }} */ export function parseTtsTuning(raw, { name = "tuning" } = {}) { @@ -65,9 +105,10 @@ export function parseTtsTuning(raw, { name = "tuning" } = {}) { return { ok: false, error: `"${name}.${k}" is not a tuning field (${TTS_TUNING_FIELDS.join(", ")})` }; } if (v === undefined || v === null) continue; - const err = ttsTuningValueError(k, v, `"${name}.${k}"`); + const q = quantizeTtsTuningValue(k, v); + const err = ttsTuningValueError(k, q, `"${name}.${k}"`); if (err) return { ok: false, error: err }; - value[k] = v; + value[k] = q; } return { ok: true, value }; } diff --git a/common/lib/ttsTuning.test.ts b/common/lib/ttsTuning.test.ts @@ -8,10 +8,14 @@ import assert from "node:assert/strict"; // range, at its edges and past them, refused in a sentence naming the field. import { + ORPHEUS_DEFAULT_TAKES, + ORPHEUS_TUNING_DEFAULTS, TTS_READING_MAX, TTS_TUNING_FIELDS, TTS_TUNING_RANGES, + normalizeTtsTuning, parseTtsTuning, + quantizeTtsTuningValue, ttsReadingError, ttsReadingSeedBase, ttsTuningValueError, @@ -83,3 +87,31 @@ test("a reading: a whole number from 0 to 99999; its seed base steps by 9973", ( // The highest one's seeds stay a signed 32-bit integer (llama-server's seed). assert.ok(ttsReadingSeedBase(1234, TTS_READING_MAX) + 101 * 6 + 5000 < 2 ** 31); }); + +test("decimals are quantised to 3 places before the range check, and -0 is 0", () => { + assert.equal(quantizeTtsTuningValue("temperature", 0.550000001), 0.55); + assert.equal(quantizeTtsTuningValue("temperature", 0.7000000000000001), 0.7); + assert.equal(quantizeTtsTuningValue("top_p", 0.12345), 0.123); + assert.ok(Object.is(quantizeTtsTuningValue("min_p", -0), 0)); + assert.ok(Object.is(quantizeTtsTuningValue("top_k", -0), 0)); + assert.equal(quantizeTtsTuningValue("repeat_penalty", 1.0004), 1); + // Whole-number fields are not rounded (2.5 is still refused). + assert.equal(quantizeTtsTuningValue("takes", 2.5), 2.5); + assert.deepEqual(parseTtsTuning({ temperature: 0.7000000000000001, min_p: -0 }), { ok: true, value: { temperature: 0.7, min_p: 0 } }); + assert.ok(Object.is((parseTtsTuning({ min_p: -0 }) as { value: { min_p: number } }).value.min_p, 0)); + // Rounded first, then checked: 1.5004 is 1.5, in range; 1.5006 is 1.501, out. + assert.deepEqual(parseTtsTuning({ temperature: 1.5004 }), { ok: true, value: { temperature: 1.5 } }); + assert.ok(!parseTtsTuning({ temperature: 1.5006 }).ok); +}); + +test("the normaliser drops what equals its default, quantised; takes only against the takes it is given", () => { + assert.deepEqual(ORPHEUS_TUNING_DEFAULTS, { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2 }); + assert.equal(ORPHEUS_DEFAULT_TAKES, 3); + assert.deepEqual(normalizeTtsTuning({ temperature: 0.550000001, top_p: 0.85, min_p: -0, top_k: 50, repeat_penalty: 1.2 }), {}); + assert.deepEqual(normalizeTtsTuning({ temperature: 0.7000000000000001, takes: 3 }), { temperature: 0.7, takes: 3 }); + assert.deepEqual(normalizeTtsTuning({ temperature: 0.7, takes: 3 }, { takes: 3 }), { temperature: 0.7 }); + assert.deepEqual(normalizeTtsTuning({ takes: 3 }, { takes: 5 }), { takes: 3 }); + // In the registry's order, whatever order it was written in; unknown fields gone. + assert.deepEqual(Object.keys(normalizeTtsTuning({ top_k: 40, temperature: 0.7, seed: 4 })), ["temperature", "top_k"]); + assert.deepEqual(normalizeTtsTuning(null), {}); +}); diff --git a/plans/orpheus-retune.md b/plans/orpheus-retune.md @@ -77,6 +77,10 @@ not a new model. input.json literally). - Tuning and reading go INTO the cache key only when non-default (no CACHE_KEY_VERSION bump): the same ask again is still free; "another reading" is a new key. + The key holds only what DIFFERS from the code's defaults, so **changing `ORPHEUS_SAMPLER` (or + `ORPHEUS_SEED_BASE`) needs a `CACHE_KEY_VERSION` bump**, or untuned asks keep hitting files made with the + old values (a pre-existing property, not changed by S1). Decimal values are quantised to 3 places (-0 is 0) + before they are checked, normalised and keyed. - The result JSON, the cache sidecar and a post take's record say the effective tuning, the reading and the seed base, so a reading can be made again exactly, and its numbers can be copied into a character. - Through every layer: `ttsApps.ts` → `ttsFile.ts` → `scripts/tts.mjs` → `tts_orpheus.py` (already reads