From 8de21eaafc33b4c25224d74bacd1d145d62b1331 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Tue, 6 Oct 2026 19:54:18 -0700 Subject: [PATCH] feat(provider): default sampled MTP acceptance to typical --- CHANGELOG.md | 3 ++- docs/architecture/inference.md | 21 +++++++++++++------ docs/provider/cli-reference.md | 12 +++++++++-- docs/reference/configuration.md | 9 +++++++- .../ProviderCore/Config/ProviderConfig.swift | 2 +- .../Inference/MTP/MTPAcceptancePolicy.swift | 8 +++++-- .../Config/MTPAcceptanceConfigTests.swift | 20 ++++++++++++++++-- 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa985a345..aae682cc71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Unreleased - typical MTP acceptance -- Add per-model typical MTP draft acceptance for sampled requests (`[backend] mtp_acceptance`, `mtp_acceptance_by_model`; default `exact`), ported from mlx-serve PR #427. Greedy requests are unchanged; slot posture telemetry reports `mtp_acceptance`. +- Default eligible sampled target-prefix MTP requests to typical acceptance (delta `0.2`) when `[backend] mtp_acceptance` and the model override are absent. Sampled output is approximate, not distribution-exact; explicit `exact` restores exact acceptance and invalid values remain safely exact. Greedy behavior, native MiMo exact acceptance, disabled MTP and model eligibility are unchanged. Benchmark acceptance still defaults to `exact`; the recorded single-host B=1 runs do not qualify sampled quality or fleet-wide speed. +- Add per-model typical MTP draft acceptance for sampled requests (`[backend] mtp_acceptance`, `mtp_acceptance_by_model`), ported from mlx-serve PR #427. Greedy requests are unchanged; slot posture telemetry reports `mtp_acceptance`. - Pin the merged SDK implementation from `mlx-swift-lm` main; its file tree matches the engine revision used in the recorded acceptance benchmarks. ## 0.9.18 - prepared candidate (not published) diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 1b9d04d3b6..986bf30ef4 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -1,6 +1,6 @@ # Provider inference engine -> Last updated: 2026-10-06 +> Last updated: 2026-10-07 How a chat-completion request is served inside the `darkbloom` provider process: one in-process engine (`mlx-swift-lm` @@ -430,17 +430,26 @@ constraints retain their ordinary-decode exclusions. Explicit offline serial verification remains available as a diagnostic oracle; drafter-required modes retain priority (`provider-swift/Sources/ProviderCore/Inference/MTP/EngineV2MTPAssistant.swift`, `providerMTPVerificationPolicy`). -`[backend] mtp_acceptance = "typical"`, or the `mtp_acceptance_by_model` -table, installs typical acceptance for eligible sampled target-prefix rows of -that model: a draft is kept when the sampler-filtered target row gives it probability above +When neither a global nor a per-model acceptance value is configured, serving +defaults to typical acceptance for eligible sampled target-prefix rows: +a draft is kept when the sampler-filtered target row gives it probability above `min(1, 0.2 * exp(-H))`, `H` the row's entropy in nats; the first rejected position and the bonus position still commit the keyed target sample. Output -is then not distribution-exact for the target. Greedy rows keep the exact -walk, and the default is `exact` (`MTPAcceptancePolicy.resolve`; +is approximate, not distribution-exact for the target. Greedy rows keep the exact +walk. Explicit `"exact"` opts out; invalid values warn and safely resolve to +exact, including an invalid per-model override rather than falling back to the +global value (`MTPAcceptancePolicy.resolve`; `CBv2MTPAcceptance` in `libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/MTP/MTPContractsV2.swift`; `mtp_acceptance` in slot posture telemetry). Design record: [`../design/typical-mtp-acceptance.md`](../design/typical-mtp-acceptance.md). +Configuration precedence and exact rollback are in the +[CLI reference](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). +The benchmark session and default `--mtp-acceptance exact` are unchanged +(`provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift`). The +[recorded benchmarks](../reports/2026-10-07-typical-mtp-acceptance-benchmarks.md) +cover only single-host B=1 runs; they do not qualify sampled-output quality or +fleet-wide speed. Native MiMo remains exact: its separately owned slot construction does not apply this preference, so `typical` is unsupported on that path (`provider-swift/Sources/ProviderCore/Inference/Engine/Factory/EngineV2SlotFactory+Native.swift`, diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index b7898e6883..f7847a8249 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -1,6 +1,6 @@ # Provider CLI reference -> Last updated: 2026-10-06 +> Last updated: 2026-10-07 Reference for the `darkbloom` command-line tool: every subcommand and flag, the files and identifiers it creates, the `provider.toml` keys it reads with their @@ -1350,7 +1350,7 @@ override `provider.toml` for one process, are in | `[backend] engine_v2_max_concurrent_by_model` | `{}` | Exact model ID → operator cap; overrides the default for that model under the same qualification, architecture and memory bounds. `status` and `doctor` show the default policy and all configured model overrides, with unknown-profile bounds when different from the requested cap (`provider-swift/Sources/ProviderCore/Inference/Performance/ServingPerformanceProfile.swift`, `ServingPerformanceProfiles.summary`) | | `[backend] engine_v2_kv_backend` | `"auto"` | `auto` / `paged` / `contiguous`; per-model table `engine_v2_kv_backend_by_model` takes precedence. Candidate `auto` tries paged only for the [exact qualified-artifact allowlist](../architecture/prefix-cache.md#kv-layouts), with contiguous fallback; all other IDs remain contiguous (`EngineV2KVBackendPolicy.parseSelection`, `preferredBackend`) | | `[backend] mtp_mode` | `auto` | Written by `darkbloom beta enable|disable mtp` | -| `[backend] mtp_acceptance` | unset (resolves to `exact`) | `exact` / `typical` draft acceptance for eligible sampled target-prefix requests. `typical` keeps a draft when the target's filtered probability for it is above `min(1, 0.2 * exp(-H))` (`H` = the target row's entropy in nats); output is then not distribution-exact. Greedy requests never change. Native MiMo remains exact and does not apply this preference. Parsing ignores case and surrounding whitespace; unknown values warn and resolve to `exact` (`provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift`, `resolve`) | +| `[backend] mtp_acceptance` | unset (resolves to `typical`, delta `0.2`) | `exact` / `typical` draft acceptance for eligible sampled target-prefix requests. `typical` keeps a draft when the target's filtered probability for it is above `min(1, 0.2 * exp(-H))` (`H` = the target row's entropy in nats); sampled output is approximate, not distribution-exact. Greedy requests never change. Native MiMo remains exact and does not apply this preference. This setting does not enable disabled MTP or widen eligibility. Parsing ignores case and surrounding whitespace; unknown values warn and resolve to `exact` (`provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift`, `resolve`) | | `[backend] mtp_acceptance_by_model` | `{}` | Exact model ID to acceptance string; overrides `mtp_acceptance` for that model. An unknown override resolves to `exact`, not the global value. Same eligibility and native MiMo exclusion as above (`MTPAcceptancePolicy.resolve`) | | `[backend.model_autopilot] enabled` | `false` | Experimental cached-inventory enrollment/consent, not activation; nonempty verified inventory is required, and only a live lease enables residency control (`provider-swift/Sources/ProviderCore/Autopilot/ModelAutopilotSettings.swift`) | | `[backend.model_autopilot] min_dwell_seconds` | `1800` | Minimum residence before Autopilot replacement; runtime clamps to `60...86400` (`ModelAutopilotSettings.effectiveMinDwellSeconds`) | @@ -1363,6 +1363,14 @@ override `provider.toml` for one process, are in | `config_version` | retired | Ignored top-level key left by releases up to v0.9.9; no longer written | | `[backend] continuous_batching`, `adaptive_prefill`, `engine_v2`, `legacy_compiled_decode`, `kv_quant`, `mtp` | retired | Parsed for presence only; one startup WARN each (`RetiredCodingKeys`). The boolean `mtp` is superseded by `mtp_mode` | +To restore exact acceptance, set `mtp_acceptance = "exact"` under `[backend]` +in `provider.toml` and restart the provider. Per-model entries take precedence: +remove any `"typical"` overrides from `[backend.mtp_acceptance_by_model]`, or +set them to `"exact"` too. To opt out for only one model, set its exact model +ID to `"exact"` in that table. Removing both settings restores the typical +default, not exact acceptance. The benchmark default `--mtp-acceptance exact` +is unchanged; see the [benchmark-only environment rule](../reference/configuration.md#engine-and-scheduler). + For foreground/local mixed-prefill tuning, `DARKBLOOM_CBV2_MIXED_PREFILL_CAP` sets a process-wide token cap and `DARKBLOOM_CBV2_MIXED_PREFILL_CAP_BY_MODEL` accepts comma-separated exact overrides such as `gemma-4-26b-qat-4bit=128,gpt-oss-20b=256`. diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index de593dfd02..c83cc5a52a 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -1,6 +1,6 @@ # Configuration reference -> Last updated: 2026-10-06 +> Last updated: 2026-10-07 Every environment variable read by the coordinator, the provider CLI (`darkbloom`), console-ui and admin-ui: accepted values, the compiled default, @@ -675,6 +675,13 @@ provider or model command is running. Code: ### Engine and scheduler +Serving acceptance is config-backed, not an environment override. Its default +and rollback are defined in the [provider configuration reference](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). + +| Config key | Default | Read in | Effect | +|---|---|---|---| +| `[backend] mtp_acceptance`, `mtp_acceptance_by_model` | unset resolves to `typical` (delta `0.2`); model map `{}` | `provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift` (`resolve`) | Exact model override precedes global, then the built-in default. Eligible sampled target-prefix MTP output is approximate, not distribution-exact; explicit `exact` opts out and invalid values safely resolve to `exact`. Greedy behavior and native MiMo exact acceptance are unchanged. Does not enable disabled MTP or widen eligibility. | + | Variable | Values / type | Default | Read in | Effect | |---|---|---|---|---| | `DARKBLOOM_CBV2_PAGED_KV` | `0` forces contiguous | unset (policy decides) | `provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2KVBackendPolicy.swift` (`preferredBackend`, `killSwitchDisabled`) | Kill switch for paged KV; beats the `provider.toml` setting. The [owned Flash-Next candidate](qwen4-next-support.md#identity-and-serving-policy) joins the exact automatic policy; a default is not runtime qualification. | diff --git a/provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift b/provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift index 2d5870174c..afd8e24ff4 100644 --- a/provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift +++ b/provider-swift/Sources/ProviderCore/Config/ProviderConfig.swift @@ -253,7 +253,7 @@ public struct BackendSettings: Sendable, Equatable, Codable { public var mtpDrafterPath: String? /// MTP draft acceptance rule for sampled requests (`mtp_acceptance` /// under `[backend]`): `"exact"` or `"typical"`. nil (default, key - /// absent) means "not set" and resolves to the built-in `exact`. + /// absent) means "not set" and resolves to the built-in `typical`. /// Optional on purpose: `TOMLEncoder` writes every non-optional key, and /// a written default would shadow every lower-precedence source for the /// life of the file. `typical` keeps a draft when the target's filtered diff --git a/provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift b/provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift index a7ed910751..50a050ef18 100644 --- a/provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift +++ b/provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift @@ -5,7 +5,7 @@ import MLXLMCommon /// provider configuration. /// /// Precedence: `[backend] mtp_acceptance_by_model` for the exact model id, -/// then `[backend] mtp_acceptance`, then the built-in `exact`. A value that +/// then `[backend] mtp_acceptance`, then the built-in `typical`. A value that /// names no known rule is reported and resolves to `exact`, so a typo can /// never install a lossy rule. The typical threshold is the engine constant /// `CBv2MTPAcceptance.defaultTypicalDelta`; it is not a production key. @@ -32,7 +32,11 @@ public enum MTPAcceptancePolicy { global: String?, byModel: [String: String], modelID: String ) -> Resolution { let raw = byModel[modelID] ?? global - guard let raw else { return Resolution(acceptance: .exact, unrecognized: nil) } + guard let raw else { + return Resolution( + acceptance: .typical(delta: CBv2MTPAcceptance.defaultTypicalDelta), + unrecognized: nil) + } guard let parsed = parse(raw) else { return Resolution(acceptance: .exact, unrecognized: raw) } diff --git a/provider-swift/Tests/ProviderCoreTests/Config/MTPAcceptanceConfigTests.swift b/provider-swift/Tests/ProviderCoreTests/Config/MTPAcceptanceConfigTests.swift index 234505fcf9..18a44bb308 100644 --- a/provider-swift/Tests/ProviderCoreTests/Config/MTPAcceptanceConfigTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Config/MTPAcceptanceConfigTests.swift @@ -11,7 +11,7 @@ import Testing @Suite("MTP acceptance config") struct MTPAcceptanceConfigTests { - @Test("absent keys decode to nil and an empty table, and resolve to exact") + @Test("absent keys decode to nil and an empty table, and resolve to typical") func absentKeys() { let config = ConfigManager.parse( """ @@ -27,7 +27,7 @@ struct MTPAcceptanceConfigTests { global: config.backend.mtpAcceptance, byModel: config.backend.mtpAcceptanceByModel, modelID: "gemma-4-26b-qat-4bit") - #expect(resolved.acceptance == .exact) + #expect(resolved.acceptance == .typical(delta: CBv2MTPAcceptance.defaultTypicalDelta)) #expect(resolved.unrecognized == nil) } @@ -61,6 +61,22 @@ struct MTPAcceptanceConfigTests { #expect(other.unrecognized == nil) } + @Test("explicit exact settings opt out of the typical default") + func exactOptOut() { + let global = MTPAcceptancePolicy.resolve(global: "exact", byModel: [:], modelID: "m") + #expect(global.acceptance == .exact) + #expect(global.unrecognized == nil) + + let perModel = MTPAcceptancePolicy.resolve( + global: nil, byModel: ["m": "exact"], modelID: "m") + #expect(perModel.acceptance == .exact) + #expect(perModel.unrecognized == nil) + + let other = MTPAcceptancePolicy.resolve( + global: nil, byModel: ["m": "exact"], modelID: "other") + #expect(other.acceptance == .typical(delta: CBv2MTPAcceptance.defaultTypicalDelta)) + } + @Test("an unknown value resolves to exact and is reported") func unknownValue() { let resolved = MTPAcceptancePolicy.resolve(