metrics: fix carbon unit conversion (Wh -> kWh is /1e3, not /1e6)

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.
This commit is contained in:
inference-bot committed 2026-10-28 04:34:50 +00:00
1 parent 997d047323
commit 0ae1404ab5
1 file changed
+13 -1
+13 -1
View File
@@ -342,7 +342,19 @@ def impact_for(models: dict[str, int]) -> tuple[float | None, float | None]:
break break
f = f or IMPACT_PROXY f = f or IMPACT_PROXY
wh += toks / 1000.0 * f["wh_per_1k_out"] 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) return round(wh, 6), round(co2, 6)