Adaptive Edge Inference — Continuous Batching with Thermal-Aware Scheduling
A production-ready research framework for low-latency LLM inference on edge devices, featuring iteration-level continuous batching, in-flight request preemption, and power-aware thermal scheduling over llama.cpp.
Highlights
| Capability | Description |
|---|---|
| Continuous Batching | Token-level iteration loop via the llama.cpp low-level API — new requests are injected between decode steps, not between batches. |
| In-Flight Preemption | Realtime (interactive) requests instantly preempt background tasks without waiting for a batch to finish. |
| Power-Aware Thermal Scheduling | A hardware monitor feeds thermal pressure and battery level into the scheduler, which throttles background work under thermal stress. |
| Real Baseline Suite | Built-in Fixed-Batch, Throughput-First, and Single-Request baselines for empirical evaluation. |
Architecture
┌─────────────────────────────────────────────────────┐
│ EdgeBatchingService │
│ ┌───────────┐ ┌──────────────────────────────┐ │
│ │ Hardware │──▶│ AdaptiveBatchScheduler │ │
│ │ Monitor │ │ │ │
│ │ (thermal, │ │ ┌─────────┐ ┌──────────┐ │ │
│ │ battery) │ │ │Realtime │ │Background│ │ │
│ │ plugged │ │ │ Queue │ │ Queue │ │ │
│ └───────────┘ │ └────┬────┘ └────┬─────┘ │ │
│ │ │ Preemption│ │ │
│ │ ▼ ▼ │ │
│ │ ┌──────────────────────┐ │ │
│ │ │ Active Batch │ │ │
│ │ │ (token-level step) │ │ │
│ │ └──────────┬───────────┘ │ │
│ └─────────────┼───────────────┘ │
│ ▼ │
│ ┌─────────────────────────┐ │
│ │ LlamaCppIterationEngine │ │
│ │ (llama_decode per token) │ │
│ └─────────────────────────┘ │
└─────────────────────────────────────────────────────┘
Repository Structure
edge_batching/
├── models.py # Data models — GenerationRequest, DeviceProfile, WorkloadType
├── engine.py # Production engine — LlamaCppIterationEngine (100% Real)
├── scheduler.py # Core scheduler — continuous batching + preemption logic
├── service.py # Async service layer — Future-based API + hardware monitor
├── hardware_monitor.py # Cross-platform thermal pressure & battery monitoring
├── policies.py # Real baseline schedulers — Fixed, Throughput-First, Single
├── benchmark.py # Real-time workload generator + policy comparison framework
├── research.py # Empirical experiment runner with CSV/Markdown output
└── simulation.py # Interactive CLI simulation for live validation
download_model.py # Downloads Qwen-0.5B GGUF for local testing
RESULTS.md # Empirical results with raw metrics
Quick Start
1. Install Dependencies
pip install llama-cpp-python numpy huggingface-hub
2. Download the Test Model
python download_model.py
3. Run the Empirical Research Suite
python -m edge_batching.research --model models/qwen1_5-0_5b-chat-q4_k_m.gguf
This generates:
research_outputs/real_benchmark_results.csv— raw metrics from real inferenceresearch_outputs/real_findings.md— formatted comparison tables
4. Run Interactive Simulation
python -m edge_batching.simulation --model models/qwen1_5-0_5b-chat-q4_k_m.gguf
Integration Example
from edge_batching import (
AdaptiveBatchScheduler,
DeviceProfile,
EdgeBatchingService,
GenerationRequest,
LlamaCppIterationEngine,
WorkloadType,
)
# 1. Initialize real engine
engine = LlamaCppIterationEngine(model_path="models/qwen1_5-0_5b-chat-q4_k_m.gguf")
# 2. Define hardware profile
device = DeviceProfile(
name="macbook-m2",
memory_gb=16.0,
compute_score=5.0,
max_batch_size=4,
target_realtime_latency_ms=250.0,
background_weight=0.30,
)
# 3. Setup scheduler and service
scheduler = AdaptiveBatchScheduler(device=device, engine=engine)
service = EdgeBatchingService(scheduler)
service.start()
# 4. Submit a realtime request
future = service.submit(
GenerationRequest(
request_id="chat-1",
prompt="What is the capital of France?",
prompt_tokens=8,
max_new_tokens=32,
workload=WorkloadType.REALTIME,
)
)
result = future.result(timeout=10.0)
print(result.output_text)
service.stop()
License
Apache 2.0 — see LICENSE.
Metadata
Release files for adaptive-edge-inference 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| adaptive_edge_inference-1.1.0.tar.gz | 22.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| adaptive_edge_inference-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.2 kB
Release files / adaptive_edge_inference-1.1.0.tar.gz
| Download URL | adaptive_edge_inference-1.1.0.tar.gz |
|---|---|
| Size | 22.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca715ecef1b1a7aa198284bc4fd9a1a0917f8cec927f44fd1b2865bca848a9d3
|
|
BLAKE2b-256 checksum How to use checksums |
fea7370a871acf9afe193f89e01dbed7e27037b99554fdbaa059e86251763e5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / adaptive_edge_inference-1.1.0-py3-none-any.whl
| Download URL | adaptive_edge_inference-1.1.0-py3-none-any.whl |
|---|---|
| Size | 29.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0b5eb209da6cf9e848dd477c0286f4c63da25213161b18c4b80d4495cd6104c
|
|
BLAKE2b-256 checksum How to use checksums |
a2aceef07fec062bd5fd940ef3d7f41133b91793e4e921980c3a29a2249e17df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for adaptive-edge-inference 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.