This repository contains experimental validation of the Energy Flow Graph (EFG) framework, which models computational processes as state-transition systems with calibrated energy costs for both states and transitions. The EFG enables systematic analysis of energy consumption patterns and optimization strategies across different computational domains.
The EFG framework represents a fundamental shift from treating energy as an aggregate property to modeling it as a composable, analyzable characteristic of computational processes. This repository demonstrates the framework's applicability through two distinct case studies spanning software algorithms and AI pipelines.
├── cs1/ # Case Study 1: AI Pipeline Optimization
├── cs2/analysis/ # Case Study 2: Path-Dependent Software Energy
│ ├── analysis.py # Main analysis script
│ └── plots/ # Generated figures (combined_results.png)
├── derivations.md # Mathematical Theory & Proofs
└── README.md
Location: cs1/
Objective: Validate the multiplicative cascade model for predicting combined energy savings from multiple optimization techniques in transformer-based AI pipelines.
Dataset: Fine-tuning distilBERT on SST-2 sentiment analysis task with 31 optimization variants including:
- Gradient checkpointing
- LoRA/PEFT quantization
- Layer pruning (4-20 layers)
- Mixed precision (FP16)
- Torch compilation
- Attention mechanisms
- Combined optimizations
Key Results:
- Energy reduction range: 4.6% to 94.6% across variants
- Optimal configuration (v30): 94.6% energy reduction while maintaining F1 score of 0.954
- Validated multiplicative cascade model:
S_combined = 1 - ∏(1 - s_i)for orthogonal optimizations - Non-orthogonal optimization interactions captured through contention factors
Data Files:
combined_metrics.csv: Comprehensive energy and performance metrics for all variantsby_variant.csv: Per-variant energy consumption breakdownby_variant_stage.csv: Stage-wise energy analysis (training, inference, evaluation)combined_metrics.json: Structured results for programmatic access
Usage:
cd cs1/
# View results
cat combined_metrics.csv
# Analyze specific variant
grep "v30_optimal" combined_metrics.csvLocation: cs2/analysis/
Objective: Analyze energy variance across 3.5M+ executions of 39,744 solutions to 1,474 problems to validate the EFG path activation model.
Theoretical Foundation: See derivations.md for the formal mathematical proofs of Deterministic Path Energy, Stochastic Bellman Equations, and Structural Optimization bounds.
Key Findings:
-
Path Dependency: 15.6% of solutions exhibit significant energy variation (
$CV > 0.1$ ) due to input-dependent path selection. High-variance solutions show massive instruction count spread (e.g.,$\sigma_{inst} \approx 5.5 \times 10^6$ ), confirming that inputs drive execution along energetically distinct paths. -
Structural Optimization: 42% of problems offer
$>90%$ energy reduction potential through algorithm selection alone. -
Magnitude of Impact: Problem
p02907demonstrates a 705x energy difference between the worst (\qty{21.10}{\joule}) and best (\qty{0.03}{\joule}) topological structures. -
Orthogonality: Power consumption varies significantly (
$\sigma=33.6W$ ) for fixed runtimes, proving that architectural efficiency is an optimization axis orthogonal to algorithmic complexity.
Visualizations:
cs2/analysis/plots/combined_results.pdf: Summary figure showing CV distribution, optimization potential, and Power vs. Runtime scatter.
Usage:
cd cs2/analysis/
# Run comprehensive analysis and generate plots
python analysis.py
# View generated report
cat cs2.txtThe EFG is constructed at statement-level granularity where:
- Vertices represent computational states (assignments, conditionals, loops)
- Edges represent control flow transitions
- Costs are ML-calibrated using Random Forest regressors trained on micro-benchmark measurements
Operation costs are derived through:
- Micro-benchmarking: Fundamental operations executed 50 times to isolate energy costs
- Hardware profiling: psutil-based CPU and memory metrics
- ML calibration: Random Forest regression to map code patterns to energy consumption
- Thermodynamic validation: Ensuring costs respect physical lower bounds
For an execution path P = (v1, e12, v2, ..., ek, vk):
E_total(P) = Σ C_s(v) + Σ C_t(e)
where:
C_s(v): Energy cost of state v (vertex)C_t(e): Energy cost of transition e (edge)
Common:
- Python 3.8+
- NumPy, SciPy
- scikit-learn
- matplotlib
Case Study 1 (cs1):
- transformers
- torch
- datasets
Case Study 2 (cs2):
- tree-climber (for CFG generation)
- networkx
- psutil
- ast (standard library)
# Clone repository
git clone <repository-url>
cd energy-flow-graph-case-study
# Install dependencies for CS2
cd cs2
pip install networkx matplotlib psutil scikit-learn
# For visualization, tree-climber is required
# Ensure tree-climber virtual environment is activated when running CS2 scriptsResearch prototype - see individual file headers for specific licensing information.
For questions or collaboration inquiries, please refer to the manuscript contact information.