Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **Admin email login** — Encode Privy OTP email/code fields as JSON strings so quoted addresses and escape characters cannot break or reshape the upstream request.
- Persist independently approved App Attest builds and revocations; refresh qualification without per-release coordinator restarts, with bounded failure/expiry and stale-grant fencing.
- Stage immutable signed provider artifacts before publication. Block unqualified releases before updater/latest aliases advance; retry the separate publication job using the same signed bytes, without rebuilding or notarizing again.
- Regression-test standard benchmark iteration timing across whole-second boundaries through a pure `ModelBenchmark.iterationResult`, including the generation prompt-time fallback when no first chunk arrives (folded from #1100).

## Release candidate v0.9.7 — MDM-optional providers and account-scoped SLAs (not shipped; 2026-09-20)

Expand Down
11 changes: 10 additions & 1 deletion docs/provider/cli-reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Provider CLI reference

> Last updated: 2026-09-20 · commit `a26b1107b`
> Last updated: 2026-09-29 · commit `90e4138c9`

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
Expand Down Expand Up @@ -541,6 +541,15 @@ the first generated token, including prompt preparation; model loading and
integrity hashing are outside the reported iteration time. An eight-token
smoke proves entry-point operation, not sustained decode performance.

The standard table measures first-token and total elapsed time with
`ContinuousClock`. Both values include the complete `Duration` seconds and
attoseconds components before decode throughput is derived; generations longer
than one second therefore retain their whole seconds
(`provider-swift/Sources/ProviderBenchmark/BenchmarkMeasurements.swift`
(`BenchmarkMeasurements.milliseconds`);
`provider-swift/Sources/ProviderBenchmark/ModelBenchmark.swift`
(`ModelBenchmark.iterationResult`)).

### Teacher-forced scores

`--teacher-forced-input <json>` selects bounded ordinary target scoring with an
Expand Down
38 changes: 28 additions & 10 deletions provider-swift/Sources/ProviderBenchmark/ModelBenchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,54 @@ public struct ModelBenchmark: Sendable {

var promptTokens = 0
var completionTokens = 0
var prefillLatencyMs: Double = 0
var infoPromptTimeSeconds: Double = 0
var firstTokenTime: ContinuousClock.Instant?

for await generation in generationStream {
switch generation {
case .chunk:
if firstTokenTime == nil {
firstTokenTime = .now
let elapsed = firstTokenTime! - iterationStart
prefillLatencyMs = BenchmarkMeasurements.milliseconds(elapsed)
}

case .info(let info):
promptTokens = info.promptTokenCount
completionTokens = info.generationTokenCount
// Use the info's own timing if we didn't capture first token
if prefillLatencyMs == 0 {
prefillLatencyMs = info.promptTime * 1000
}
infoPromptTimeSeconds = info.promptTime

case .toolCall:
break
}
}

let totalElapsed = ContinuousClock.now - iterationStart
let totalTimeMs = BenchmarkMeasurements.milliseconds(totalElapsed)

// Calculate decode TPS from the generation info's timing when available,
// otherwise approximate from wall-clock
return iterationResult(
iteration: iteration,
promptTokens: promptTokens,
completionTokens: completionTokens,
prefillElapsed: firstTokenTime.map { $0 - iterationStart },
infoPromptTimeSeconds: infoPromptTimeSeconds,
totalElapsed: totalElapsed
)
}

/// Derive the reported metrics from monotonic-clock observations.
///
/// Kept pure so whole-second duration conversion and decode arithmetic can
/// be tested without loading an MLX model.
static func iterationResult(
iteration: Int,
promptTokens: Int,
completionTokens: Int,
prefillElapsed: Duration?,
infoPromptTimeSeconds: Double,
totalElapsed: Duration
) -> BenchmarkIterationResult {
let prefillLatencyMs =
prefillElapsed.map(BenchmarkMeasurements.milliseconds)
?? infoPromptTimeSeconds * 1000
let totalTimeMs = BenchmarkMeasurements.milliseconds(totalElapsed)
let decodeTimeMs = totalTimeMs - prefillLatencyMs
let decodeTokensPerSecond: Double
if completionTokens > 0 && decodeTimeMs > 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Foundation
import Testing

@testable import ProviderBenchmark

@Suite("standard model benchmark")
struct ModelBenchmarkTests {
@Test(
"iteration timings retain whole seconds",
arguments: [
(
Duration.milliseconds(900),
Duration.seconds(2) + .milliseconds(100),
900.0,
2_100.0,
213.33333333333334
),
(
Duration.seconds(2) + .milliseconds(168),
Duration.seconds(4),
2_168.0,
4_000.0,
139.73799126637555
),
(
Duration.milliseconds(168),
Duration.milliseconds(900),
168.0,
900.0,
349.7267759562842
),
] as [(Duration, Duration, Double, Double, Double)]
)
func iterationTimingsRetainWholeSeconds(
prefill: Duration,
total: Duration,
expectedPrefillMs: Double,
expectedTotalMs: Double,
expectedTPS: Double
) {
let result = ModelBenchmark.iterationResult(
iteration: 1,
promptTokens: 12,
completionTokens: 256,
prefillElapsed: prefill,
infoPromptTimeSeconds: 0,
totalElapsed: total
)

#expect(abs(result.prefillLatencyMs - expectedPrefillMs) < 1e-9)
#expect(abs(result.totalTimeMs - expectedTotalMs) < 1e-9)
#expect(abs(result.decodeTokensPerSecond - expectedTPS) < 1e-9)
}

@Test("iteration uses generation prompt timing when no chunk arrives")
func iterationUsesGenerationPromptTimingWithoutChunk() {
let result = ModelBenchmark.iterationResult(
iteration: 2,
promptTokens: 12,
completionTokens: 0,
prefillElapsed: nil,
infoPromptTimeSeconds: 1.25,
totalElapsed: .seconds(3)
)

#expect(result.prefillLatencyMs == 1_250)
#expect(result.totalTimeMs == 3_000)
#expect(result.decodeTokensPerSecond == 0)
}
}
Loading