GreenGate
Cut the cost and carbon of LLM inference with one line of routing. Easy queries are answered by a small local model; only genuinely hard ones escalate to a large model. Every query is carbon-accounted, honestly.
pip install greengate
import greengate
gw = greengate.GreenGate(
small="Qwen/Qwen2.5-0.5B-Instruct", # runs locally, exposes logits
large="gpt-4o-mini", # or any local model
budget_g=0.5, # optional carbon ceiling
)
r = gw.route("Summarise this document ...")
print(r.response) # answered by whichever tier was appropriate
print(r.decision) # "LOCAL" or "ESCALATE"
print(r.carbon_g) # gCO2 for this query, including any wasted small run
gw.profile() # session totals: carbon, escalation rate, latency
Why this exists
Today every query, easy or hard, is sent to the same large model. Most queries do not need it. GreenGate sits between your application and your models, measures how uncertain the small model is, and escalates only when that uncertainty is high.
Three things it does that other cascading systems do not:
- Measures real energy. Local inference is metered with NVML at 100 ms across all GPUs, not estimated. API tiers use EcoLogits and are labelled as estimates.
- Full carbon accounting. When a query escalates, it is charged for both the discarded small-model run and the large-model run. Most published cascade savings omit the first, which overstates them.
- Routes vision queries too, using the average token probability of the generated answer as the confidence signal.
What to expect
From the evaluation in the accompanying study (ShareGPT, MMLU and VQAv2; measured on dual T4):
| Workload | Carbon reduction | Quality retention |
|---|---|---|
| MMLU (structured) | 29.5% | 95.0% |
| ShareGPT (open-ended) | 49.8% | 80.6% |
| ShareGPT (quality-first) | 14.5% | 90.1% |
| VQAv2 (vision) | escalates only 5% | exceeds both tiers |
Savings depend on four measurable things: the energy ratio between your tiers, your escalation rate, the retention you accept, and your hardware. GreenGate reports all of them rather than assuming them. On an inefficient local GPU, escalating to an efficient API can genuinely be greener — the profiler tells you which case you are in.
Tiers
- Small tier must be a local open-weight model. The routing signal is computed from token logits, which hosted APIs do not expose. This is also where the privacy and cost win comes from.
- Large tier can be anything: another local model, or an OpenAI API model.
Calibration
Language models are overconfident, so raw entropy thresholds are unreliable. GreenGate ships fitted temperature-scaling values for evaluated models and self-calibrates for anything else:
gw.calibrate() # ~15 min, fits T on held-out MMLU validation, saved to ~/.greengate/
Modes and budgets
gw.config(mode="green") # escalate less; "balanced" and "quality" also available
gw.config(threshold=2.9) # or set the entropy threshold explicitly
gw.config(budget_g=0.05) # sliding-window carbon ceiling; escalation defers when exhausted
Honest limitations
- On open-ended generation with small models, token entropy is a weak signal (near chance in our evaluation). It is informative on structured tasks and vision. Where it is weak, savings come from the cascade structure rather than from selective routing.
- Energy measurement requires an NVIDIA GPU (NVML). CPU runs fall back to a documented estimate.
- API-tier carbon is an estimate, not a measurement, and is not directly comparable to metered local figures.
Install extras
pip install greengate[gpu] # bitsandbytes + pynvml for quantised local models and metering
pip install greengate[api] # openai + ecologits for API large tiers
pip install greengate[eval] # pandas/matplotlib for the evaluation scripts
Reproducing the evaluation
The RUNBOOK.md in this repository reproduces every published number: calibration, three deployment configurations, four baselines, threshold sweeps, grid conditions, trace replay against real Azure arrival traces, and three ablation studies. Raw per-query records for all runs are in experiments/.
Citation
If you use GreenGate in academic work, please cite the accompanying study:
T. R. Hemachandra, "GreenGate: A Confidence-Aware Cascading Framework for Optimizing Energy and Cost in Large Language and Multimodal Model Inference," BSc thesis, NSBM Green University, 2026.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file greengate-0.1.0.tar.gz.
File metadata
- Download URL: greengate-0.1.0.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9c79fa60b82036f168e58dc048384c99f0ad9f3b88fbffe0fbff4c167b29847
|
|
| MD5 |
478e86fd99e80ebd1c5609005f6fed40
|
|
| BLAKE2b-256 |
0f464bb56996bc0504d8606b6e03a7f6c334ee63465b99ca6dc3b166eac34f3f
|
File details
Details for the file greengate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: greengate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a5039e246049cd9b26c7beb16d8b8dd47cd068516a1078d0ef9a862701dae2d
|
|
| MD5 |
1b9a67eb1346e06b3b21938fc66aa49a
|
|
| BLAKE2b-256 |
62de92c8590d8fa9b2bd5be2a1f364bb727673791c85929e35c19949649dd412
|