ml-energy/zeus/measuring-energy
Claude Code and agent skill by ml-energy/zeus
- community
Checking that the SKILL.md file is still in the repository.
Measure the energy and power consumption of code with Zeus, on NVIDIA and AMD GPUs, Intel/AMD CPUs and DRAM (RAPL), Apple silicon, and NVIDIA Jetson. Use when asked to measure, monitor, log, or profile the energy consumption, power draw, or energy efficiency of a computing workload.
Install
npx vskill@latest install ml-energy/zeus/measuring-energySKILL.md
Measuring Energy and Power with Zeus
Zeus is a Python library for measuring and optimizing the energy consumption of any computation running on GPUs, CPUs, and SoCs. Install it with pip install zeus (Python 3.10 or later), or pip install 'zeus[apple]' to enable energy measurement on Apple silicon. Run python -m zeus.show_env to check which frameworks and devices Zeus detects. Full documentation: https://ml.energy/zeus
Choosing an API
| Goal | API | |
|---|---|---|
| Energy and time of a block of code | zeus.monitor.ZeusMonitor | |
| Power draw over time | zeus.monitor.PowerMonitor | |
| Low-variance energy per iteration of a repeatable function | zeus.profile | |
| Custom tooling on raw device counters | zeus.device |
For a quick measurement without writing code, run python -m zeus.monitor energy (prints total energy on Ctrl-C) or python -m zeus.monitor power (prints power draw periodically).
Permissions
GPU energy and power measurement requires no special privileges. CPU and DRAM energy measurement uses RAPL (Intel and most modern AMD CPUs), which requires root due to kernel restrictions. Without root, ZeusMonitor reports cpu_energy=None when cpu_indices is omitted or empty, and raises RuntimeError when a non-empty cpu_indices is passed explicitly. Alternatives are running inside Docker as root with the RAPL sysfs directory mounted, or deploying the Zeus daemon (zeusd) and setting ZEUSD_SOCK_PATH so unprivileged processes relay RAPL reads through it.
ZeusMonitor: energy and time of a code block
gpu_indices=None(default) monitors all GPUs.
Indices follow CUDA_VISIBLE_DEVICES (NVIDIA) or HIP_VISIBLE_DEVICES (AMD), so index N is cuda:N in frameworks like PyTorch.
end_windowreturns aMeasurementwithtime(seconds),gpu_energy(dict of GPU index to Joules),cpu_energyanddram_energy(dict of RAPL package index to Joules, orNonewhen unavailable), andsoc_energy(Apple silicon or Jetson subsystem energies in millijoules, orNone).
result.total_energy is the sum of GPU energy only.
- Multiple windows can be open at once, and they can nest or overlap.
Window names must be unique among open windows; use begin_window(key, restart=True) in notebooks where a crashed cell may have left a window open, and end_window(key, cancel=True) to discard a window.
begin_windowandend_windowsynchronize asynchronously dispatched GPU computations (torch.cuda.synchronizeby default) so the window captures exactly the code inside it.
Pass sync_execution_with="jax" or "cupy" to the constructor for those frameworks, or sync_execution=False to begin_window/end_window when the workload uses none of them (otherwise a missing framework raises RuntimeError on machines with GPUs).
- GPU energy counters update roughly every 100 ms, so a very short window can read zero energy.
Constructing with approx_instant_energy=True replaces such zero readings with instant power draw times window duration, which is an approximation, not a measurement. Never enable it unprompted: explain this implication to the user and get their approval first, or lengthen the window instead. The flag is also unsupported on AMD GPUs that cannot report instant power; end_window raises ZeusGPUNotSupportedError there.
log_file="measurement.csv"writes one row per completed window.
Zeus monitors may spawn helper processes with the spawn start method, which re-imports your __main__ module. Keep monitor construction and heavy initialization (e.g., loading models or large data) under if __name__ == "__main__": or inside functions, or every helper process will repeat that work.
PowerMonitor: power draw over time
- Polling starts on construction, with one background process per power domain.
Domains are device_instant, device_average, and memory_average; only domains the GPU supports are monitored, and get_all_power_timelines returns every monitored one.
- Querying a domain that is not monitored raises
ValueError; on GPUs that cannot report instant power (some AMD GPUs), passpower_domain="device_average"toget_power. update_period=None(default) infers each GPU model's power counter update period by polling; pass a value in seconds (at least 0.05) to skip that.get_energy(start_time, end_time)integrates the power timeline into Joules per GPU, usingtime.time()timestamps.- All monitored GPUs must be the same model.
- Call
stop()when done to terminate the polling processes.
zeus.profile: thermally stable energy profiling
Back-to-back energy measurements of the same workload drift because the GPU heats up and hotter silicon leaks more power. This module runs trials of the form cooldown (idle), then warmup iterations, then a measured window of iterations, yielding low-variance energy per iteration. Use it when benchmarking or comparing configurations rather than measuring a single long run end to end.
- The target function takes no arguments and runs one iteration of the workload.
TrialResultholdsenergy_per_iter,time_per_iter,total_energy,total_time,iterations, and GPUtemperature_before/temperature_after.profile_parameters(and the single-parameter variantsprofile_measurement_durationandprofile_cooldown_duration) returnSweepReportobjects whoseentriesmark each configurationis_validwhen the energy standard deviation across trials falls belowtrial_stddev_threshold.
Each sweep holds the other duration fixed at the maximum of its search range. Printing a report gives a one-line-per-configuration summary.
- In a distributed setting, every rank creates its own
ZeusMonitor(gpu_indices=[local_rank])and calls the same profiling function; results are aggregated across ranks and rank 0 logs.
zeus.device: low-level device APIs
When the higher-level APIs do not fit, build on the device abstraction layer directly.
- Each getter raises
ZeusGPUInitError,ZeusCPUInitError, orZeusSoCInitErrorwhen the corresponding hardware or vendor library is unavailable. - Units at this layer are milliwatts and millijoules;
zeus.monitorconverts to Watts and Joules. - Energy counters are cumulative, so measure a window by subtracting two readings.
Where supports_get_total_energy_consumption is False (e.g., NVIDIA GPUs older than Volta), integrate power samples over time instead, which is what ZeusMonitor does internally.
- GPU measurement methods, all taking a
gpu_index:get_instant_power_usage,get_average_power_usage,get_average_memory_power_usage,get_total_energy_consumption, andget_gpu_temperature.
Some AMD GPUs do not support instant power, in which case use get_average_power_usage.
CPUs.get_total_energy_consumption(index)returns aCpuDramMeasurementwithcpu_mjanddram_mj(the latterNonewhen DRAM energy is unsupported); RAPL counter wraparound is handled internally.SoCalso offersbegin_window/end_windowreturning a platform-specificSoCMeasurement.- The GPU interface additionally exposes power limit and frequency control (
set_power_management_limit,set_gpu_locked_clocks, etc.), which require theSYS_ADMINcapability orzeusd.
Troubleshooting
- Warning about zero energy consumption: the window is shorter than the GPU energy counter update period; lengthen the window, or propose
approx_instant_energy=Trueto the user (see theZeusMonitorsection for its implications). cpu_energyisNone: RAPL requires root; see the Permissions section.- Out-of-memory or repeated log lines at startup: the
__main__module is being re-imported by helper processes; add theif __name__ == "__main__":guard. RuntimeError: Failed to import Pytorch: the machine has GPUs but no PyTorch; setsync_execution_withto the framework in use or passsync_execution=Falsetobegin_window/end_window.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/measuring-energy/SKILL.md
Popularity
- Repository stars
- 373
- Repository forks
- 48
- 7-day trend score
- 30
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 13 Sep 2026, a month ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ml-energy/zeus/measuring-energy)