From 0ae1404ab5cafeb94a107f4f93e9b3a947645624 Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Wed, 28 Oct 2026 04:34:50 +0000 Subject: [PATCH] metrics: fix carbon unit conversion (Wh -> kWh is /1e3, not /1e6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The carbon column was 1000x too low: 2.9 gCO2e for 55 days and 14.35 kWh, where 14.35 kWh at the factor table's own intensities must be ~2.9 kg. Energy was right, so nothing looked broken unless you did the arithmetic — 938 Wh in a day cannot be 0.2 g of CO2. Adds a tripwire in impact_for(): if the implied grid intensity falls outside 5-500 gCO2e/kWh, it prints a warning rather than quietly returning numbers. The factors themselves span 24-250, so a blend outside that band means a unit or factor error, not a cleaner grid. --- metrics_snapshot.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/metrics_snapshot.py b/metrics_snapshot.py index 6c2a9b1..133a168 100644 --- a/metrics_snapshot.py +++ b/metrics_snapshot.py @@ -342,7 +342,19 @@ def impact_for(models: dict[str, int]) -> tuple[float | None, float | None]: break f = f or IMPACT_PROXY wh += toks / 1000.0 * f["wh_per_1k_out"] - co2 += toks / 1000.0 * f["wh_per_1k_out"] / 1e6 * f["gco2e_per_kwh"] + # Wh -> kWh is /1e3, then x gCO2e/kWh. This divided by 1e6 once, which + # understated carbon exactly 1000x: the energy column stayed plausible + # while carbon read ~0.2 g/day for a day using ~1 kWh. + co2 += toks / 1000.0 * f["wh_per_1k_out"] / 1e3 * f["gco2e_per_kwh"] + # Tripwire against unit errors: the blend of the factors above must imply a + # grid intensity inside a sane band (the factors themselves span 24-250). + if wh > 0: + implied = co2 / wh * 1000.0 # gCO2e per kWh + if not (5.0 <= implied <= 500.0): + print( + f"metrics: WARNING implied grid intensity {implied:.1f} gCO2e/kWh is outside " + f"the plausible band — suspect a unit error before trusting these numbers" + ) return round(wh, 6), round(co2, 6)