Skip to content

Commit b904914

Browse files
uncSoftclaude
andcommitted
Fix energy-per-token unit label and aggregate calculation
Per #22, the per-token energy figure was displayed as "W/Tk" but the underlying value is W ÷ (tok/s) = J/tok. Relabel everywhere user-facing (UI cells, chart, report markdown, exports) to J/Tk / J/tok. Also fix the session aggregate: it was the arithmetic mean of per-sample ratios, each dividing by cumulative tok/s. Early samples divide by a warming-up tok/s, biasing the mean ~40% high. Now computed as avgSystemPower / stats.tokensPerSecond at session.complete, which is the principled J/tok and matches what users derive from the displayed avg power and avg tok/s. DB column names (watts_per_token / avg_watts_per_token) and CSV/JSON export keys are unchanged for downstream compatibility. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 64ef490 commit b904914

8 files changed

Lines changed: 39 additions & 27 deletions

File tree

‎anubis/anubis/Features/Benchmark/BenchmarkView.swift‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ struct BenchmarkView: View {
540540
.padding(.top, Spacing.xxs)
541541
} label: {
542542
HStack {
543-
Text("Performance")
543+
Text("Performance/Thinking")
544544
.font(.caption)
545545
.foregroundStyle(.secondary)
546546
if !viewModel.streamResponse
@@ -673,7 +673,7 @@ struct BenchmarkView: View {
673673
)
674674

675675
CompactMetricsCard(
676-
title: "W/Token",
676+
title: "J/Token",
677677
value: viewModel.currentWattsPerTokenFormatted,
678678
icon: "leaf.fill",
679679
color: .chartEfficiency,
@@ -829,7 +829,7 @@ struct BenchmarkView: View {
829829
color: .anubisMuted
830830
)
831831

832-
// Row 3: Thermal / Peak GPU Power / Avg W/Token / Connection
832+
// Row 3: Thermal / Peak GPU Power / Avg J/Token / Connection
833833
DetailStatCell(
834834
title: "Thermal",
835835
value: viewModel.currentMetrics?.thermalState.description ?? "—",
@@ -845,8 +845,8 @@ struct BenchmarkView: View {
845845
)
846846

847847
DetailStatCell(
848-
title: "Avg W/Token",
849-
value: viewModel.currentSession?.avgWattsPerToken.map { String(format: "%.2f W/tok", $0) } ?? "—",
848+
title: "Avg J/Token",
849+
value: viewModel.currentSession?.avgWattsPerToken.map { String(format: "%.2f J/tok", $0) } ?? "—",
850850
icon: "leaf.fill",
851851
color: .chartEfficiency
852852
)
@@ -1343,7 +1343,7 @@ struct ExpandedMetricsView: View {
13431343
chartHeight: chartHeight
13441344
)
13451345

1346-
// Row 4: GPU Power | W/Token | GPU Frequency
1346+
// Row 4: GPU Power | Energy per Token | GPU Frequency
13471347
TimelineChart(
13481348
title: "GPU Power",
13491349
data: chartData.gpuPower,
@@ -1352,10 +1352,10 @@ struct ExpandedMetricsView: View {
13521352
chartHeight: chartHeight
13531353
)
13541354
TimelineChart(
1355-
title: "Watts per Token",
1355+
title: "Energy per Token",
13561356
data: chartData.wattsPerToken,
13571357
color: .chartEfficiency,
1358-
unit: "W/tok",
1358+
unit: "J/tok",
13591359
chartHeight: chartHeight
13601360
)
13611361
TimelineChart(
@@ -1515,10 +1515,10 @@ struct ExpandedMetricsView: View {
15151515
chartHeight: exportHeight
15161516
)
15171517
TimelineChart(
1518-
title: "Watts per Token",
1518+
title: "Energy per Token",
15191519
data: chartData.wattsPerToken,
15201520
color: .chartEfficiency,
1521-
unit: "W/tok",
1521+
unit: "J/tok",
15221522
chartHeight: exportHeight
15231523
)
15241524
TimelineChart(
@@ -1720,7 +1720,7 @@ struct ExpandedMetricsView: View {
17201720
// Row 2: Power
17211721
expandedStat(icon: "bolt.horizontal.fill", label: "GPU Power", value: viewModel.avgGPUPowerFormatted, color: .chartGPUPower, available: viewModel.hasPowerMetrics)
17221722
expandedStat(icon: "powerplug.fill", label: "System Power", value: viewModel.avgSystemPowerFormatted, color: .chartSystemPower, available: viewModel.hasPowerMetrics)
1723-
expandedStat(icon: "leaf.fill", label: "W/Token", value: viewModel.currentWattsPerTokenFormatted, color: .chartEfficiency, available: viewModel.hasPowerMetrics)
1723+
expandedStat(icon: "leaf.fill", label: "J/Token", value: viewModel.currentWattsPerTokenFormatted, color: .chartEfficiency, available: viewModel.hasPowerMetrics)
17241724
expandedStat(icon: "gauge.with.dots.needle.67percent", label: "GPU Freq", value: viewModel.currentGPUFrequencyFormatted, color: .chartFrequency, available: viewModel.hasPowerMetrics)
17251725

17261726
// Row 3: Session details
@@ -1974,10 +1974,10 @@ struct ChartGrid: View {
19741974
)
19751975

19761976
TimelineChart(
1977-
title: "Watts per Token",
1977+
title: "Energy per Token",
19781978
data: data.wattsPerToken,
19791979
color: .chartEfficiency,
1980-
unit: "W/tok",
1980+
unit: "J/tok",
19811981
chartHeight: chartHeight
19821982
)
19831983

‎anubis/anubis/Features/Benchmark/BenchmarkViewModel.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,15 +1576,15 @@ extension BenchmarkViewModel {
15761576
return "—"
15771577
}
15781578

1579-
/// Watts per token formatted (avg system power / avg tok/s)
1579+
/// Energy per token formatted as J/tok (avg system power / avg tok/s).
15801580
var currentWattsPerTokenFormatted: String {
15811581
if let session = currentSession, session.status == .completed,
15821582
let wpt = session.avgWattsPerToken {
1583-
return String(format: "%.2f W/tok", wpt)
1583+
return String(format: "%.2f J/tok", wpt)
15841584
}
15851585
guard avgSystemPower > 0, currentTokensPerSecond > 0 else { return "—" }
15861586
let wpt = avgSystemPower / currentTokensPerSecond
1587-
return String(format: "%.2f W/tok", wpt)
1587+
return String(format: "%.2f J/tok", wpt)
15881588
}
15891589

15901590
/// Effective backend memory: compensates when process tree walk misses the model runner.

‎anubis/anubis/Features/Benchmark/SessionHistoryView.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ struct SessionDetailView: View {
471471
value: session.avgSystemPowerWatts.map { Formatters.watts($0) } ?? "—"
472472
)
473473
StatCell(
474-
title: "Avg W/Token",
475-
value: session.avgWattsPerToken.map { String(format: "%.2f W/tok", $0) } ?? "—"
474+
title: "Avg J/Token",
475+
value: session.avgWattsPerToken.map { String(format: "%.2f J/tok", $0) } ?? "—"
476476
)
477477
StatCell(
478478
title: "Avg GPU Freq",

‎anubis/anubis/Features/Reports/ModelReportView.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct ModelReportView: View {
289289
HStack(spacing: Spacing.sm) {
290290
sortableHeaderCell("Model", column: .modelName, flexible: true, alignment: .leading)
291291
sortableHeaderCell("Avg Tk/s", column: .avgTokensPerSecond, width: 70)
292-
sortableHeaderCell("Avg W/Tk", column: .avgWattsPerToken, width: 70)
292+
sortableHeaderCell("Avg J/Tk", column: .avgWattsPerToken, width: 70)
293293
sortableHeaderCell("TTFT", column: .avgTimeToFirstToken, width: 80)
294294
sortableHeaderCell("Avg Power", column: .avgSystemPowerWatts, width: 80)
295295
sortableHeaderCell("Peak Mem", column: .peakMemoryBytes, width: 80)
@@ -374,7 +374,7 @@ struct ModelReportView: View {
374374
.font(.mono(13, weight: .semibold))
375375
.frame(width: 70, alignment: .trailing)
376376

377-
// W/Tk
377+
// J/Tk
378378
Text(model.avgWattsPerToken.map { String(format: "%.2f", $0) } ?? "—")
379379
.font(.mono(13))
380380
.foregroundStyle(model.avgWattsPerToken != nil ? .primary : .tertiary)
@@ -426,7 +426,7 @@ struct ModelReportView: View {
426426
}
427427
if let eff = mostEfficient {
428428
Label {
429-
Text("Most efficient: **\(eff.modelName)** (\(String(format: "%.2f", eff.avgWattsPerToken!)) W/tk)")
429+
Text("Most efficient: **\(eff.modelName)** (\(String(format: "%.2f", eff.avgWattsPerToken!)) J/tk)")
430430
.font(.caption)
431431
} icon: {
432432
Image(systemName: "leaf.fill")

‎anubis/anubis/Features/Reports/ModelReportViewModel.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ModelReportRow: Identifiable {
2929
enum ReportSortColumn: String, CaseIterable {
3030
case modelName = "Model"
3131
case avgTokensPerSecond = "Avg Tk/s"
32-
case avgWattsPerToken = "Avg W/Tk"
32+
case avgWattsPerToken = "Avg J/Tk"
3333
case avgTimeToFirstToken = "TTFT"
3434
case avgSystemPowerWatts = "Avg Power"
3535
case peakMemoryBytes = "Peak Mem"

‎anubis/anubis/Models/BenchmarkSample.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ struct BenchmarkSample: Identifiable, Codable, FetchableRecord, MutablePersistab
8484
self.backendProcessMemoryBytes = metrics.backendProcessMemoryBytes
8585
self.backendProcessCPUPercent = metrics.backendProcessCPUPercent
8686

87-
// Compute watts per token: system power / current tok/s
87+
// Running J/token estimate at this sample: system power (W)
88+
// ÷ cumulative tok/s. Stored as `wattsPerToken` for DB
89+
// compatibility; physically the unit is joules/token (W/(tok/s)
90+
// = J/tok). Charted as a running efficiency curve — session
91+
// aggregate is computed separately in BenchmarkSession.complete.
8892
if let power = metrics.systemPowerWatts, power > 0,
8993
let tps = cumulativeTokensPerSecond, tps > 0 {
9094
self.wattsPerToken = power / tps

‎anubis/anubis/Models/BenchmarkSession.swift‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,15 @@ struct BenchmarkSession: Identifiable, Codable, Hashable, FetchableRecord, Mutab
190190
self.peakSystemPowerWatts = power.peakSystemPowerWatts
191191
self.avgGpuFrequencyMHz = power.avgGpuFrequencyMHz
192192
self.peakGpuFrequencyMHz = power.peakGpuFrequencyMHz
193-
self.avgWattsPerToken = power.avgWattsPerToken
193+
// Energy per token (J/tok) = avg power (W) / avg tok/s.
194+
// Computed from session aggregates rather than averaging
195+
// per-sample ratios — the per-sample value divides by a
196+
// ramp-up cumulative tok/s, which biases the mean high.
197+
if let avgP = power.avgSystemPowerWatts, stats.tokensPerSecond > 0 {
198+
self.avgWattsPerToken = avgP / stats.tokensPerSecond
199+
} else {
200+
self.avgWattsPerToken = nil
201+
}
194202
}
195203
self.backendProcessName = backendProcessName
196204
}

‎anubis/anubis/Services/ExportService.swift‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ enum ExportService {
199199
report += "Peak System Power: \(String(format: "%.2f", v))W\n"
200200
}
201201
if let v = session.avgWattsPerToken {
202-
report += "Avg Watts/Token: \(String(format: "%.4f", v)) W/tok\n"
202+
report += "Avg Energy/Token: \(String(format: "%.4f", v)) J/tok\n"
203203
}
204204
if let v = session.avgGpuFrequencyMHz {
205205
report += "Avg GPU Frequency: \(String(format: "%.0f", v)) MHz\n"
@@ -282,7 +282,7 @@ enum ExportService {
282282
md += "\(chip.gpuCores) GPU · \(chip.unifiedMemoryGB) GB\n\n"
283283

284284
md += "## Models (\(rows.count))\n\n"
285-
md += "| Model | Quant | Format | Backend | Avg Tk/s | Avg W/Tk | TTFT | Avg Power | Peak Mem | Runs |\n"
285+
md += "| Model | Quant | Format | Backend | Avg Tk/s | Avg J/Tk | TTFT | Avg Power | Peak Mem | Runs |\n"
286286
md += "|---|---|---|---|---:|---:|---:|---:|---:|---:|\n"
287287
for row in rows {
288288
let quant = row.quantization ?? "—"
@@ -306,7 +306,7 @@ enum ExportService {
306306
if let efficient = rows.filter({ $0.avgWattsPerToken != nil })
307307
.min(by: { $0.avgWattsPerToken! < $1.avgWattsPerToken! }) {
308308
md += "- **Most efficient:** \(efficient.modelName) — "
309-
md += "\(String(format: "%.2f", efficient.avgWattsPerToken!)) W/tk\n"
309+
md += "\(String(format: "%.2f", efficient.avgWattsPerToken!)) J/tk\n"
310310
}
311311
let totalRuns = rows.reduce(0) { $0 + $1.runCount }
312312
md += "- **Total:** \(rows.count) models · \(totalRuns) runs\n"

0 commit comments

Comments
 (0)