savings
savings
¶
Savings calculation — compare local inference cost against cloud providers.
FLOPs and energy use a no-KV-cache model: P * N * (N+1) where P = params, N = total tokens. This reflects full recompute without cached attention.
Classes¶
ProviderSavings
dataclass
¶
ProviderSavings(provider: str = '', label: str = '', input_cost: float = 0.0, output_cost: float = 0.0, total_cost: float = 0.0, energy_wh: float = 0.0, energy_joules: float = 0.0, flops: float = 0.0)
Savings compared to a single cloud provider.
SavingsSummary
dataclass
¶
SavingsSummary(total_calls: int = 0, total_prompt_tokens: int = 0, total_completion_tokens: int = 0, total_tokens: int = 0, local_cost: float = 0.0, per_provider: List[ProviderSavings] = list(), monthly_projection: Dict[str, float] = dict(), session_start_ts: float = 0.0, session_duration_hours: float = 0.0, avg_cost_per_query: Dict[str, float] = dict(), cloud_agent_equivalent: Dict[str, int] = dict(), token_counting_version: int = TOKEN_COUNTING_VERSION)
Overall savings summary across all cloud providers.
Functions¶
compute_savings
¶
compute_savings(prompt_tokens: int, completion_tokens: int, total_calls: int = 0, session_start: float = 0.0, prompt_tokens_evaluated: int = 0) -> SavingsSummary
Compute savings vs cloud providers given token counts.
Two token counts are used:
prompt_tokens— full prompt size (system prompt + all history). Used for dollar cost comparison since cloud providers bill for every input token on every request.prompt_tokens_evaluated— actual tokens processed (KV-cache- aware). In multi-turn conversations, subsequent turns only evaluate new tokens; the system prompt and prior context are served from KV cache. Used for FLOPs and energy calculations since these reflect actual compute.
When prompt_tokens_evaluated is 0 we used to fall back to
prompt_tokens. That's wrong in multi-turn: routes.py aggregates
by summing each turn's full prompt — which counts the system prompt
N times for an N-turn conversation — so the fallback turned the FLOPs
and energy estimates into N×-too-high numbers. That was the dominant
contributor to the bimodal Wh/token distribution on the leaderboard.
Conservative behaviour now: when the KV-cache-aware count is
missing, treat prompt_tokens_evaluated as 0 — so the FLOPs/energy
denominator becomes just completion_tokens. That under-estimates
rather than over-estimates compute, and (intentionally) cascades
into the leaderboard's isMissingTelemetry UI render so those
rows show — instead of a misleading zero.
Source code in src/openjarvis/server/savings.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
savings_to_dict
¶
savings_to_dict(summary: SavingsSummary) -> Dict[str, Any]