Skip to content
Back to search

zeus

SkillWorks with Claude CodeGitHub

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.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/ml-energy/zeus with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/ml-energy/zeus'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/ml-energy--zeus/badge.svg)](/listings/ml-energy--zeus)

HTML

<a href="/listings/ml-energy--zeus"><img src="/api/listings/ml-energy--zeus/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Please refer to our [Getting Started](https://ml.energy/zeus/getting_started) page. After that, you might look at

- [Measuring Energy](https://ml.energy/zeus/measure) - [Optimizing Energy](https://ml.energy/zeus/optimize)

Docker image

We provide a Docker image fully equipped with all dependencies and environments. Refer to our [Docker Hub repository](https://hub.docker.com/r/mlenergy/zeus) and [`Dockerfile`](docker/Dockerfile).

Examples

We provide working examples for integrating and running Zeus in the [`examples/`](/examples) directory.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/plugin.json · Manifest · 13 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "zeus",
  3. "displayName": "Zeus",
  4. "description": "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.",
  5. "author": {
  6. "name": "ML.ENERGY",
  7. "url": "https://ml.energy/zeus"
  8. },
  9. "homepage": "https://ml.energy/zeus",
  10. "repository": "https://github.com/ml-energy/zeus",
  11. "license": "Apache-2.0",
  12. "keywords": ["energy", "power", "gpu", "cpu", "measurement", "profiling"]
  13. }
README.md · README · 110 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <div align="center">
  2. <picture>
  3. <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ml-energy/zeus/master/docs/assets/img/logo_dark.svg">
  4. <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ml-energy/zeus/master/docs/assets/img/logo_light.svg">
  5. <img alt="Zeus logo" width="55%" src="https://raw.githubusercontent.com/ml-energy/zeus/master/docs/assets/img/logo_light.svg">
  6. </picture>
  7. <h1>Deep Learning Energy Measurement and Optimization</h1>
  8. [![Slack workspace](https://badgen.net/badge/icon/Join%20workspace/b31b1b?icon=slack&label=Slack)](https://join.slack.com/t/zeus-ml/shared_invite/zt-36fl1m7qa-Ihky6FbfxLtobx40hMj3VA)
  9. [![Docker Hub](https://badgen.net/docker/pulls/symbioticlab/zeus?icon=docker&label=Docker%20pulls)](https://hub.docker.com/r/symbioticlab/zeus)
  10. [![Homepage](https://custom-icon-badges.demolab.com/badge/Homepage-ml.energy-23d175.svg?logo=home&logoColor=white&logoSource=feather)](https://ml.energy/zeus)
  11. [![Apache-2.0 License](https://custom-icon-badges.herokuapp.com/github/license/ml-energy/zeus?logo=law)](/LICENSE)
  12. </div>
  13. ---
  14. **Project News** ⚡
  15. - \[2026/02\] Supported by [Laude Institute's Slingshots // TWO](https://www.laude.org/updates/slingshots-two)!
  16. - \[2025/12\] With NVIDIA, Google, and Meta, we led a NeurIPS 25 tutorial on [Energy and Power as First‑Class ML Design Metrics](https://ml.energy/tutorials/neurips25/)!
  17. - \[2025/12\] [The ML.ENERGY leaderboard](https://ml.energy/leaderboard) got a major upgrade to v3. Read our in-depth [technical analysis blog post](https://ml.energy/blog/measurement/energy/diagnosing-inference-energy-consumption-with-the-mlenergy-leaderboard-v30/).
  18. - \[2025/09\] We shared our experience and design philosophy for [The ML.ENERGY Benchmark](https://github.com/ml-energy/benchmark) in our [NeurIPS 25 D&B Spotlight paper](https://neurips.cc/virtual/2025/loc/san-diego/poster/121781).
  19. - \[2025/05\] Zeus now supports CPU, DRAM, AMD GPU, Apple Silicon, and NVIDIA Jetson platform energy measurement!
  20. - \[2024/11\] Perseus, an optimizer for large model training, appeared at SOSP'24! [Paper](https://dl.acm.org/doi/10.1145/3694715.3695970) | [Blog](https://ml.energy/zeus/research_overview/perseus) | [Optimizer](https://ml.energy/zeus/optimize/pipeline_frequency_optimizer)
  21. - \[2024/05\] Zeus is now a PyTorch ecosystem project. Read the PyTorch blog post [here](https://pytorch.org/blog/zeus/)!
  22. - \[2024/02\] Zeus was selected as a [2024 Mozilla Technology Fund awardee](https://foundation.mozilla.org/en/blog/open-source-AI-for-environmental-justice/)!
  23. ---
  24. Zeus is a library for (1) [**measuring**](https://ml.energy/zeus/measure) the energy consumption of Deep Learning workloads and (2) [**optimizing**](https://ml.energy/zeus/optimize) their energy consumption.
  25. Zeus is a project of [The ML.ENERGY Initiative](https://ml.energy).
  26. ## Repository Organization
  27. ```
  28. zeus/
  29. ├── zeus/ # ⚡ Zeus Python package
  30. │ ├── monitor/ # - Energy and power measurement (programmatic & CLI)
  31. │ ├── optimizer/ # - Collection of time and energy optimizers
  32. │ ├── device/ # - Abstraction layer over CPU and GPU devices
  33. │ ├── utils/ # - Utility functions and classes
  34. │ ├── _legacy/ # - Legacy code to keep our research papers reproducible
  35. │ ├── metric.py # - Prometheus metric export support
  36. │ ├── show_env.py # - Installation & device detection verification script
  37. │ └── callback.py # - Base class for callbacks during training
  38. │
  39. ├── zeusd # 🌩️ Zeus daemon
  40. │
  41. ├── docker/ # 🐳 Dockerfiles and Docker Compose files
  42. │
  43. └── examples/ # 🛠️ Zeus usage examples
  44. ```
  45. ## Getting Started
  46. Please refer to our [Getting Started](https://ml.energy/zeus/getting_started) page.
  47. After that, you might look at
  48. - [Measuring Energy](https://ml.energy/zeus/measure)
  49. - [Optimizing Energy](https://ml.energy/zeus/optimize)
  50. ### Docker image
  51. We provide a Docker image fully equipped with all dependencies and environments.
  52. Refer to our [Docker Hub repository](https://hub.docker.com/r/mlenergy/zeus) and [`Dockerfile`](docker/Dockerfile).
  53. ### Examples
  54. We provide working examples for integrating and running Zeus in the [`examples/`](/examples) directory.
  55. ## Agent skill
  56. [`skills/measuring-energy/`](skills/measuring-energy/SKILL.md) is a portable [Agent Skill](https://agentskills.io/) that teaches AI coding agents to measure energy and power with Zeus.
  57. Claude Code and Codex users can install it from the [ML.ENERGY plugin marketplace](https://github.com/ml-energy/plugins); other tools can load the `skills/` directory directly.
  58. ## Releases
  59. Zeus follows semantic versioning; pushing a `zeus-v*` tag releases the Python package to [PyPI](https://pypi.org/project/zeus/) and a `zeusd-v*` tag releases the daemon to [crates.io](https://crates.io/crates/zeusd).
  60. We cut a release when meaningful changes have landed, which has meant roughly every one to three months, and fixes that affect measurement correctness or security fixes ship as soon as they are ready.
  61. Every release requires green CI on `master`, and breaking changes are called out in the [release notes](https://github.com/ml-energy/zeus/releases).
  62. ## Research
  63. Zeus is rooted on multiple research papers.
  64. Even more research is ongoing, and Zeus will continue to expand and get better at what it's doing.
  65. 1. Zeus (NSDI 23): [Paper](https://www.usenix.org/conference/nsdi23/presentation/you) | [Blog](https://ml.energy/zeus/research_overview/zeus) | [Slides](https://www.usenix.org/system/files/nsdi23_slides_chung.pdf)
  66. 1. Chase (ICLR Workshop 23): [Paper](https://arxiv.org/abs/2303.02508)
  67. 1. Perseus (SOSP 24): [Paper](https://arxiv.org/abs/2312.06902) | [Blog](https://ml.energy/zeus/research_overview/perseus) | [Slides](https://jaewonchung.me/pdf.js/web/viewer.html?file=/assets/attachments/pubs/Perseus_slides.pdf#pagemode=none)
  68. 1. The ML.ENERGY Benchmark (NeurIPS 25 D&B Spotlight): [Paper](https://arxiv.org/abs/2505.06371) | [Repository](https://github.com/ml-energy/benchmark) | [Leaderboard](https://ml.energy/leaderboard)
  69. 1. Where Do the Joules Go? Diagnosing Inference Energy Consumption: [ArXiv](https://arxiv.org/abs/2601.22076) | [Blog](https://ml.energy/blog/measurement/energy/diagnosing-inference-energy-consumption-with-the-mlenergy-leaderboard-v30/)
  70. If you find Zeus relevant to your research, please consider citing:
  71. ```bibtex
  72. @inproceedings{zeus-nsdi23,
  73. title = {Zeus: Understanding and Optimizing {GPU} Energy Consumption of {DNN} Training},
  74. author = {Jie You and Jae-Won Chung and Mosharaf Chowdhury},
  75. booktitle = {USENIX NSDI},
  76. year = {2023}
  77. }
  78. ```
  79. ## Other Resources
  80. 1. Energy-Efficient Deep Learning with PyTorch and Zeus (PyTorch conference 2023): [Recording](https://youtu.be/veM3x9Lhw2A) | [Slides](https://ml.energy/assets/attachments/pytorch_conf_2023_slides.pdf)
  81. 1. NeurIPS 2025 Tutorial: Energy and Power as First-Class ML Design Metrics: [Recording](https://neurips.cc/virtual/2025/loc/san-diego/tutorial/109589) | [Homepage](https://ml.energy/tutorials/neurips25/)
  82. ## Newsletter
  83. Subscribe to the [ML.ENERGY newsletter](https://buttondown.com/ml-energy) for the latest news on Zeus and other projects by the ML.ENERGY Initiative.
zeusd/scripts/test-windows-gpu.sh · Bundled script · 461 lines · 2 findings marked
  1. #!/usr/bin/env bash
  2. # Provision a Windows g4dn.xlarge, build zeusd from a Git branch, run smoke
  3. # tests over TCP and Windows Named Pipe, install Python+PyTorch+zeus and run a
  4. # sustained matmul + power/energy + power-limit/clock validation against the
  5. # live NVML, then tear down.
  6. #
  7. # Prereqs (script aborts if missing):
  8. # - aws CLI v2 with valid credentials (`aws sts get-caller-identity` ok)
  9. # - jq
  10. # - base64
  11. # - bash 4+
  12. #
  13. # Usage:
  14. # ./test-windows-gpu.sh [options]
  15. # Options:
  16. # --region <r> AWS region (default: us-west-2)
  17. # --ami <id> Windows AMI id (default: pinned DCV-Windows-2022 + NVIDIA)
  18. # --instance-type <t> EC2 instance type (default: g4dn.xlarge)
  19. # --git-ref <ref> Branch/tag/SHA on origin to test (default: current branch)
  20. # --keep Skip teardown (instance + resources stay around)
  21. # --no-quota-check Skip the G-family quota pre-flight
  22. #
  23. # Env overrides:
  24. # AWS_REGION, ZEUSD_TEST_AMI, ZEUSD_TEST_INSTANCE_TYPE, ZEUSD_TEST_GIT_REF
  25. set -euo pipefail
  26. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  27. PY_TEST_FILE="$SCRIPT_DIR/test-windows-gpu.py"
  28. [[ -f "$PY_TEST_FILE" ]] || { echo "missing $PY_TEST_FILE" >&2; exit 1; }
  29. # ---------- parse args ----------
  30. REGION="${AWS_REGION:-us-west-2}"
  31. AMI="${ZEUSD_TEST_AMI:-ami-03f09307db43011ca}" # DCV-Windows-2022 + NVIDIA 538.67 (us-west-2)
  32. ITYPE="${ZEUSD_TEST_INSTANCE_TYPE:-g4dn.xlarge}"
  33. GIT_REF="${ZEUSD_TEST_GIT_REF:-$(git rev-parse --abbrev-ref HEAD)}"
  34. KEEP=0
  35. SKIP_QUOTA=0
  36. while [[ $# -gt 0 ]]; do
  37. case "$1" in
  38. --region) REGION="$2"; shift 2 ;;
  39. --ami) AMI="$2"; shift 2 ;;
  40. --instance-type) ITYPE="$2"; shift 2 ;;
  41. --git-ref) GIT_REF="$2"; shift 2 ;;
  42. --keep) KEEP=1; shift ;;
  43. --no-quota-check) SKIP_QUOTA=1; shift ;;
  44. -h|--help) sed -n '2,/^set -euo/p' "$0" | sed '$d'; exit 0 ;;
  45. *) echo "unknown arg: $1" >&2; exit 2 ;;
  46. esac
  47. done
  48. # ---------- pre-flight ----------
  49. command -v aws >/dev/null || { echo "aws CLI v2 not installed"; exit 1; }
  50. command -v jq >/dev/null || { echo "jq not installed"; exit 1; }
  51. command -v base64 >/dev/null || { echo "base64 not installed"; exit 1; }
  52. aws sts get-caller-identity --output text --query Arn >/dev/null || {
  53. echo "AWS credentials missing or expired. Log in with your usual method and re-run." >&2
  54. exit 1
  55. }
  56. echo "Region: $REGION AMI: $AMI Instance: $ITYPE Git ref: $GIT_REF"
  57. if [[ $SKIP_QUOTA -eq 0 ]]; then
  58. Q=$(aws service-quotas get-service-quota --region "$REGION" --service-code ec2 \
  59. --quota-code L-DB2E81BA --query 'Quota.Value' --output text)
  60. REQUIRED=$(aws ec2 describe-instance-types --region "$REGION" --instance-types "$ITYPE" \
  61. --query 'InstanceTypes[0].VCpuInfo.DefaultVCpus' --output text)
  62. if (( $(printf '%.0f' "$Q") < REQUIRED )); then
  63. echo "G/VT On-Demand vCPU quota in $REGION is $Q; $ITYPE needs $REQUIRED." >&2
  64. echo "Request a quota increase via Service Quotas (code L-DB2E81BA) and retry." >&2
  65. exit 1
  66. fi
  67. fi
  68. TAG_VALUE="zeusd-test-$(date -u +%Y%m%d-%H%M%S)-$$-$(openssl rand -hex 3)"
  69. KEY_NAME="$TAG_VALUE"
  70. SG_NAME="$TAG_VALUE"
  71. ROLE_NAME="$TAG_VALUE-role"
  72. PROFILE_NAME="$TAG_VALUE-profile"
  73. INSTANCE_ID=""
  74. SG_ID=""
  75. KEY_FILE="$(mktemp -u)-${KEY_NAME}.pem"
  76. # ---------- cleanup trap ----------
  77. cleanup() {
  78. local rc=$?
  79. if [[ $KEEP -eq 1 ]]; then
  80. echo "[--keep] leaving resources behind (tag zeusd-test=$TAG_VALUE)"
  81. [[ -n "$INSTANCE_ID" ]] && echo " instance: $INSTANCE_ID"
  82. [[ -n "$SG_ID" ]] && echo " sg: $SG_ID"
  83. echo " key file: $KEY_FILE"
  84. exit $rc
  85. fi
  86. # If credentials died during the run, AWS calls below will all silently
  87. # fail (each is `|| true`). Detect that up front and tell the user exactly
  88. # what to delete manually so the state is actionable.
  89. if ! aws sts get-caller-identity --output text --query Arn >/dev/null 2>&1; then
  90. {
  91. echo "WARNING: AWS credentials are not valid; cleanup cannot run."
  92. echo "After re-logging in, run this to clean up everything tagged for this run:"
  93. echo " bash $SCRIPT_DIR/cleanup-test-aws.sh --delete --tag-value $TAG_VALUE"
  94. echo "Or delete by hand:"
  95. [[ -n "$INSTANCE_ID" ]] && \
  96. echo " aws ec2 terminate-instances --region $REGION --instance-ids $INSTANCE_ID"
  97. echo " aws iam remove-role-from-instance-profile --instance-profile-name $PROFILE_NAME --role-name $ROLE_NAME"
  98. echo " aws iam delete-instance-profile --instance-profile-name $PROFILE_NAME"
  99. echo " aws iam detach-role-policy --role-name $ROLE_NAME --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
  100. echo " aws iam delete-role --role-name $ROLE_NAME"
  101. [[ -n "$SG_ID" ]] && \
  102. echo " aws ec2 delete-security-group --region $REGION --group-id $SG_ID"
  103. echo " aws ec2 delete-key-pair --region $REGION --key-name $KEY_NAME"
  104. } >&2
  105. rm -f "$KEY_FILE"
  106. exit $rc
  107. fi
  108. echo "Cleaning up (tag $TAG_VALUE)..."
  109. if [[ -n "$INSTANCE_ID" ]]; then
  110. aws ec2 terminate-instances --region "$REGION" --instance-ids "$INSTANCE_ID" >/dev/null 2>&1 || true
  111. aws ec2 wait instance-terminated --region "$REGION" --instance-ids "$INSTANCE_ID" 2>/dev/null || true
  112. fi
  113. aws iam remove-role-from-instance-profile --instance-profile-name "$PROFILE_NAME" --role-name "$ROLE_NAME" 2>/dev/null || true
  114. aws iam delete-instance-profile --instance-profile-name "$PROFILE_NAME" 2>/dev/null || true
  115. aws iam detach-role-policy --role-name "$ROLE_NAME" --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore 2>/dev/null || true
  116. aws iam delete-role --role-name "$ROLE_NAME" 2>/dev/null || true
  117. [[ -n "$SG_ID" ]] && aws ec2 delete-security-group --region "$REGION" --group-id "$SG_ID" 2>/dev/null || true
  118. aws ec2 delete-key-pair --region "$REGION" --key-name "$KEY_NAME" 2>/dev/null || true
  119. rm -f "$KEY_FILE"
  120. exit $rc
  121. }
  122. trap cleanup EXIT INT TERM
  123. # ---------- provision ----------
  124. VPC_ID=$(aws ec2 describe-vpcs --region "$REGION" --filters Name=is-default,Values=true --query 'Vpcs[0].VpcId' --output text)
  125. aws ec2 create-key-pair --region "$REGION" --key-name "$KEY_NAME" --key-type rsa \
  126. --tag-specifications "ResourceType=key-pair,Tags=[{Key=zeusd-test,Value=$TAG_VALUE}]" \
  127. --query KeyMaterial --output text > "$KEY_FILE"
  128. chmod 600 "$KEY_FILE"
  129. SG_ID=$(aws ec2 create-security-group --region "$REGION" --group-name "$SG_NAME" \
  130. --description "zeusd Windows test (no inbound)" --vpc-id "$VPC_ID" \
  131. --tag-specifications "ResourceType=security-group,Tags=[{Key=zeusd-test,Value=$TAG_VALUE}]" \
  132. --query GroupId --output text)
  133. aws iam create-role --role-name "$ROLE_NAME" \
  134. --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}' \
  135. --tags "Key=zeusd-test,Value=$TAG_VALUE" >/dev/null
  136. aws iam attach-role-policy --role-name "$ROLE_NAME" --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
  137. aws iam create-instance-profile --instance-profile-name "$PROFILE_NAME" \
  138. --tags "Key=zeusd-test,Value=$TAG_VALUE" >/dev/null
  139. aws iam add-role-to-instance-profile --instance-profile-name "$PROFILE_NAME" --role-name "$ROLE_NAME"
  140. sleep 8 # let IAM propagate
  141. INSTANCE_ID=$(aws ec2 run-instances --region "$REGION" \
  142. --image-id "$AMI" --instance-type "$ITYPE" --count 1 \
  143. --key-name "$KEY_NAME" --security-group-ids "$SG_ID" \
  144. --iam-instance-profile "Name=$PROFILE_NAME" \
  145. --block-device-mappings "DeviceName=/dev/sda1,Ebs={VolumeSize=60,VolumeType=gp3,DeleteOnTermination=true}" \
  146. --metadata-options "HttpTokens=required,HttpPutResponseHopLimit=2,HttpEndpoint=enabled" \
  147. --tag-specifications "ResourceType=instance,Tags=[{Key=zeusd-test,Value=$TAG_VALUE},{Key=Name,Value=$TAG_VALUE}]" \
  148. "ResourceType=volume,Tags=[{Key=zeusd-test,Value=$TAG_VALUE}]" \
  149. --query 'Instances[0].InstanceId' --output text)
  150. echo "Instance: $INSTANCE_ID"
  151. echo "Waiting for SSM agent..."
  152. until aws ssm describe-instance-information --region "$REGION" \
  153. --filters "Key=InstanceIds,Values=$INSTANCE_ID" \
  154. --query 'InstanceInformationList[0].PingStatus' --output text 2>/dev/null \
  155. | grep -q Online; do sleep 20; done
  156. echo "SSM Online."
  157. # ---------- build & test (one big PowerShell payload via SSM) ----------
  158. # Base64-encode the local Python test script so we can ship it intact through
  159. # bash -> jq JSON -> SSM -> PowerShell -> file without escape-soup.
  160. PY_B64=$(base64 -w0 "$PY_TEST_FILE" 2>/dev/null || base64 "$PY_TEST_FILE" | tr -d '\n')
  161. PS_SCRIPT=$(cat <<POWERSHELL
  162. \$ErrorActionPreference = 'Stop'
  163. \$ProgressPreference = 'SilentlyContinue'
  164. # ---------- Visual Studio Build Tools (C++ workload) ----------
  165. if (-not (Test-Path 'C:\\BuildTools\\VC')) {
  166. Invoke-WebRequest -UseBasicParsing -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile "\$env:TEMP\\vs_BuildTools.exe"
    • Dismissed after review: Links to a Windows program from code, which is how droppers fetch their payload
    • Line 183 on GitHub
  167. \$p = Start-Process -FilePath "\$env:TEMP\\vs_BuildTools.exe" -ArgumentList '--quiet','--wait','--norestart','--nocache','--installPath','C:\\BuildTools','--add','Microsoft.VisualStudio.Workload.VCTools','--includeRecommended' -Wait -NoNewWindow -PassThru
  168. if (\$p.ExitCode -notin 0,3010) { throw "vs_BuildTools exit \$(\$p.ExitCode)" }
  169. }
  170. # ---------- Rust (MSVC) ----------
  171. [Environment]::SetEnvironmentVariable('CARGO_HOME','C:\\rust\\cargo','Machine')
  172. [Environment]::SetEnvironmentVariable('RUSTUP_HOME','C:\\rust\\rustup','Machine')
  173. \$env:CARGO_HOME='C:\\rust\\cargo'; \$env:RUSTUP_HOME='C:\\rust\\rustup'
  174. if (-not (Test-Path 'C:\\rust\\cargo\\bin\\cargo.exe')) {
  175. Invoke-WebRequest -UseBasicParsing -Uri 'https://win.rustup.rs/x86_64' -OutFile "\$env:TEMP\\rustup-init.exe"
  176. Start-Process -FilePath "\$env:TEMP\\rustup-init.exe" -ArgumentList '-y','--default-toolchain','stable-x86_64-pc-windows-msvc','--profile','minimal','--no-modify-path' -Wait -NoNewWindow
  177. }
  178. \$env:Path = "C:\\rust\\cargo\\bin;\$env:Path"
  179. # ---------- Python 3.12 ----------
  180. if (-not (Test-Path 'C:\\Python312\\python.exe')) {
  181. Invoke-WebRequest -UseBasicParsing -Uri 'https://www.python.org/ftp/python/3.12.7/python-3.12.7-amd64.exe' -OutFile "\$env:TEMP\\python-installer.exe"
    • Dismissed after review: Links to a Windows program from code, which is how droppers fetch their payload
    • Line 200 on GitHub
  182. Start-Process -FilePath "\$env:TEMP\\python-installer.exe" -ArgumentList '/quiet','InstallAllUsers=1','PrependPath=1','Include_pip=1','Include_test=0','Include_doc=0','TargetDir=C:\\Python312' -Wait -NoNewWindow
  183. }
  184. \$env:Path = "C:\\Python312;C:\\Python312\\Scripts;\$env:Path"
  185. # ---------- Python deps (torch + zeus + requests) ----------
  186. & cmd /c "C:\\Python312\\python.exe -m pip install --upgrade pip 2>&1" | Select-Object -Last 3
  187. & cmd /c "C:\\Python312\\python.exe -m pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cu121 2>&1" | Select-Object -Last 3
  188. & cmd /c "C:\\Python312\\python.exe -m pip install --no-cache-dir requests zeus 2>&1" | Select-Object -Last 3
  189. # ---------- Fetch source (branch zip) ----------
  190. \$src = 'C:\\zeusbuild'
  191. if (-not (Test-Path \$src)) { New-Item -ItemType Directory \$src | Out-Null }
  192. \$zip = "\$src\\zeus.zip"; if (Test-Path \$zip) { Remove-Item \$zip }
  193. Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/ml-energy/zeus/archive/${GIT_REF}.zip' -OutFile \$zip
  194. Get-ChildItem -Path \$src -Directory | Where-Object Name -Like 'zeus-*' | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
  195. Expand-Archive -Path \$zip -DestinationPath \$src
  196. \$repo = Get-ChildItem -Path \$src -Directory | Where-Object Name -Like 'zeus-*' | Select-Object -First 1
  197. \$zeusd = Join-Path \$repo.FullName 'zeusd'
  198. # ---------- Build ----------
  199. Set-Location \$zeusd
  200. & cmd /c "cargo build > \$src\\build.log 2>&1"
  201. if (\$LASTEXITCODE -ne 0) { Get-Content "\$src\\build.log" -Tail 80; throw "cargo build failed" }
  202. Write-Host "BUILD_OK"
  203. \$exe = "\$zeusd\\target\\debug\\zeusd.exe"
  204. # ---------- TCP smoke ----------
  205. Write-Host "===== TCP smoke ====="
  206. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
  207. \$p = Start-Process -FilePath \$exe -ArgumentList @('serve','--mode','tcp','--tcp-bind-address','127.0.0.1:4938','--enable','gpu-control,gpu-read') -PassThru -NoNewWindow -RedirectStandardOutput "\$src\\zeusd-tcp.out" -RedirectStandardError "\$src\\zeusd-tcp.err"
  208. Start-Sleep -Seconds 4
  209. foreach (\$spec in @(
  210. @{ M='GET'; P='/discover' },
  211. @{ M='GET'; P='/gpu/get_power' },
  212. @{ M='GET'; P='/gpu/get_cumulative_energy' },
  213. @{ M='POST'; P='/gpu/set_persistence_mode?gpu_ids=0&enabled=true&block=true' },
  214. @{ M='POST'; P='/gpu/set_persistence_mode?gpu_ids=0&enabled=false&block=true' }
  215. )) {
  216. Write-Host ">>> TCP \$(\$spec.M) \$(\$spec.P)"
  217. & curl.exe -sS -o - -w " HTTP %{http_code}\`n" -X \$spec.M "http://127.0.0.1:4938\$(\$spec.P)"
  218. }
  219. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  220. Start-Sleep -Seconds 1
  221. # ---------- Named-pipe smoke ----------
  222. Write-Host "===== Named-pipe smoke ====="
  223. \$p = Start-Process -FilePath \$exe -ArgumentList @('serve','--mode','named-pipe','--pipe-name','\\\\.\\pipe\\zeusd','--enable','gpu-control,gpu-read') -PassThru -NoNewWindow -RedirectStandardOutput "\$src\\zeusd-pipe.out" -RedirectStandardError "\$src\\zeusd-pipe.err"
  224. Start-Sleep -Seconds 4
  225. function Invoke-PipeHttp(\$m,\$path) {
  226. \$pipe = New-Object System.IO.Pipes.NamedPipeClientStream('.','zeusd',[System.IO.Pipes.PipeDirection]::InOut)
  227. \$pipe.Connect(3000)
  228. \$req = "\$m \$path HTTP/1.1\`r\`nHost: localhost\`r\`nConnection: close\`r\`nContent-Length: 0\`r\`n\`r\`n"
  229. \$b = [Text.Encoding]::ASCII.GetBytes(\$req); \$pipe.Write(\$b,0,\$b.Length); \$pipe.Flush()
  230. \$ms = New-Object IO.MemoryStream; \$buf = New-Object byte[] 8192
  231. while ((\$n = \$pipe.Read(\$buf,0,\$buf.Length)) -gt 0) { \$ms.Write(\$buf,0,\$n) }
  232. \$pipe.Close(); return [Text.Encoding]::ASCII.GetString(\$ms.ToArray())
  233. }
  234. # Expected codes encode the regression we hit before: actix-web's AppInit
  235. # drains its services Vec on the first new_service() call, so if zeusd
  236. # calls new_service() per connection (as it used to), the FIRST pipe
  237. # request hits a populated router (200) and EVERY SUBSEQUENT request hits
  238. # an empty router (404). Asserting per-route status codes catches this.
  239. \$failed = 0
  240. foreach (\$x in @(
  241. @{m='GET' ; p='/discover' ; expect=200},
  242. @{m='GET' ; p='/gpu/get_power' ; expect=200},
  243. @{m='GET' ; p='/gpu/get_cumulative_energy' ; expect=200},
  244. @{m='POST'; p='/gpu/set_persistence_mode?gpu_ids=0&enabled=true&block=true' ; expect=200},
  245. @{m='POST'; p='/gpu/set_persistence_mode?gpu_ids=0&enabled=false&block=true' ; expect=400}
  246. )) {
  247. Write-Host ">>> PIPE \$(\$x.m) \$(\$x.p)"
  248. \$resp = Invoke-PipeHttp \$x.m \$x.p
  249. \$statusLine = (\$resp -split "\`r\`n",2)[0]
  250. Write-Host " \$statusLine"
  251. if (\$statusLine -notmatch "HTTP/1\.1 \$(\$x.expect)") {
  252. Write-Host " expected HTTP \$(\$x.expect)"
  253. \$failed = 1
  254. }
  255. }
  256. if (\$failed) { throw "Named-pipe smoke failed (see expected vs actual above)" }
  257. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  258. Start-Sleep -Seconds 1
  259. # ---------- PyTorch load + zeus.device.gpu test ----------
  260. Write-Host "===== PyTorch load + ranges ====="
  261. \$pyPath = "\$src\\zeusd_gpu_test.py"
  262. \$pyBytes = [Convert]::FromBase64String('${PY_B64}')
  263. [IO.File]::WriteAllBytes(\$pyPath, \$pyBytes)
  264. \$p = Start-Process -FilePath \$exe -ArgumentList @('serve','--mode','tcp','--tcp-bind-address','127.0.0.1:4938','--enable','gpu-control,gpu-read') -PassThru -NoNewWindow -RedirectStandardOutput "\$src\\zeusd-load.out" -RedirectStandardError "\$src\\zeusd-load.err"
  265. Start-Sleep -Seconds 4
  266. & cmd /c "C:\\Python312\\python.exe \`"\$pyPath\`" 2>&1"
  267. \$pyExit = \$LASTEXITCODE
  268. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  269. if (\$pyExit -ne 0) { throw "python test exit \$pyExit" }
  270. # ---------- SDDL test: unprivileged client reaching elevated daemon ----------
  271. # Validates the Windows pipe DACL. The other tests in this script run as
  272. # SYSTEM (the SSM agent's identity), which has admin rights and is allowed
  273. # by any DACL; without this stage we would not know whether --pipe-sddl
  274. # actually grants access to non-admin clients, which is the core reason
  275. # zeusd needs an SDDL on Windows at all.
  276. #
  277. # We can't use \`Start-Process -Credential\` here: under SSM-as-SYSTEM on EC2
  278. # the privilege to assign a primary token to another process is stripped,
  279. # and a fresh local user does not get SeBatchLogonRight (so scheduled tasks
  280. # also fail to run as them). Instead, we LogonUser + WindowsIdentity.Impersonate
  281. # inside this same process; the kernel checks the pipe DACL against the
  282. # impersonated token at CreateFile time, which is exactly what a real
  283. # unprivileged client process would experience.
  284. Write-Host "===== SDDL test (positive + negative) ====="
  285. Add-Type -TypeDefinition @'
  286. using System;
  287. using System.Runtime.InteropServices;
  288. public static class TokenUtils {
  289. [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  290. public static extern bool LogonUser(
  291. string lpszUsername, string lpszDomain, string lpszPassword,
  292. int dwLogonType, int dwLogonProvider, out IntPtr phToken);
  293. [DllImport("kernel32.dll", SetLastError = true)]
  294. public static extern bool CloseHandle(IntPtr hObject);
  295. public const int LOGON32_LOGON_INTERACTIVE = 2;
  296. public const int LOGON32_PROVIDER_DEFAULT = 0;
  297. }
  298. '@
  299. \$testUser = 'zd_pipeclient'
  300. # Password must not contain the username and must hit Windows complexity:
  301. # >= 8 chars and >= 3 of {upper, lower, digit, symbol}.
  302. \$testPass = 'Xz7@Kv9!Mq3#Rt5\$Pw2'
  303. \$securePass = ConvertTo-SecureString \$testPass -AsPlainText -Force
  304. if (Get-LocalUser -Name \$testUser -ErrorAction SilentlyContinue) {
  305. Remove-LocalUser -Name \$testUser
  306. }
  307. New-LocalUser -Name \$testUser -Password \$securePass -PasswordNeverExpires -UserMayNotChangePassword | Out-Null
  308. Remove-LocalGroupMember -Group 'Administrators' -Member \$testUser -ErrorAction SilentlyContinue
  309. function Send-Request-As-User(\$pipeName, \$method, \$path) {
  310. \$token = [IntPtr]::Zero
  311. \$ok = [TokenUtils]::LogonUser(
  312. \$testUser, '.', \$testPass,
  313. [TokenUtils]::LOGON32_LOGON_INTERACTIVE,
  314. [TokenUtils]::LOGON32_PROVIDER_DEFAULT,
  315. [ref]\$token)
  316. if (-not \$ok) {
  317. return "FAILED: LogonUser win32 err \$([Runtime.InteropServices.Marshal]::GetLastWin32Error())"
  318. }
  319. \$identity = New-Object System.Security.Principal.WindowsIdentity(\$token)
  320. \$context = \$identity.Impersonate()
  321. try {
  322. try {
  323. \$pipe = New-Object System.IO.Pipes.NamedPipeClientStream('.', \$pipeName, 'InOut')
  324. \$pipe.Connect(5000)
  325. \$req = "\$method \$path HTTP/1.1\`r\`nHost: localhost\`r\`nConnection: close\`r\`nContent-Length: 0\`r\`n\`r\`n"
  326. \$b = [Text.Encoding]::ASCII.GetBytes(\$req)
  327. \$pipe.Write(\$b, 0, \$b.Length); \$pipe.Flush()
  328. \$ms = New-Object IO.MemoryStream
  329. \$buf = New-Object byte[] 8192
  330. while ((\$n = \$pipe.Read(\$buf, 0, \$buf.Length)) -gt 0) { \$ms.Write(\$buf, 0, \$n) }
  331. \$resp = [Text.Encoding]::ASCII.GetString(\$ms.ToArray())
  332. \$pipe.Close()
  333. return \$resp
  334. } catch {
  335. return "FAILED: \$(\$_.Exception.Message)"
  336. }
  337. } finally {
  338. \$context.Undo()
  339. [TokenUtils]::CloseHandle(\$token) | Out-Null
  340. }
  341. }
  342. # --- Positive: default SDDL ('D:(A;;GRGW;;;AU)') should let an AU connect AND
  343. # trigger a privileged NVML write through the elevated daemon. This is the
  344. # whole reason zeusd exists on Windows: an unprivileged client process must be
  345. # able to ask the elevated daemon to change power-limit / locked-clocks. The
  346. # READ check alone (GET /discover) only proves pipe ACL access; it doesn't
  347. # prove the privilege bridge works.
  348. \$pipeOk = 'zeusd-sddl-pos'
  349. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
  350. Start-Sleep 1
  351. \$null = Start-Process -FilePath \$exe \`
  352. -ArgumentList @('serve','--mode','named-pipe','--pipe-name',"\\\\.\\pipe\\\$pipeOk",'--enable','gpu-control,gpu-read') \`
  353. -PassThru -NoNewWindow -RedirectStandardOutput "\$src\\sddl-pos.out" -RedirectStandardError "\$src\\sddl-pos.err"
  354. Start-Sleep -Seconds 4
  355. # (a) READ: unprivileged client should be able to reach /discover.
  356. \$respDisc = Send-Request-As-User \$pipeOk 'GET' '/discover'
  357. if (-not (\$respDisc -match 'HTTP/1\\.1 200 OK')) {
  358. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  359. Remove-LocalUser -Name \$testUser -ErrorAction SilentlyContinue
  360. Write-Host " positive read: FAIL. client output:"; Write-Host \$respDisc
  361. throw "SDDL positive read test failed"
  362. }
  363. Write-Host " positive read: PASS (unprivileged client got 200 OK on /discover)"
  364. # (b) WRITE: unprivileged client triggers a privileged NVML op (set_power_limit).
  365. # Daemon (SYSTEM) executes nvmlDeviceSetPowerManagementLimit on its behalf.
  366. \$respSet = Send-Request-As-User \$pipeOk 'POST' '/gpu/set_power_limit?gpu_ids=0&power_limit_mw=65000&block=true'
  367. if (-not (\$respSet -match 'HTTP/1\\.1 200 OK')) {
  368. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  369. Remove-LocalUser -Name \$testUser -ErrorAction SilentlyContinue
  370. Write-Host " positive write: FAIL. client output:"; Write-Host \$respSet
  371. throw "SDDL positive write test failed (privilege bridge broken)"
  372. }
  373. Write-Host " positive write: PASS (unprivileged client drove privileged NVML write via daemon)"
  374. # (c) WRITE-BAD-ARG: same path but with out-of-range value should yield 400 (proves
  375. # the daemon really did call NVML and propagated the InvalidArg, rather than
  376. # rubber-stamping 200 to anything from the unprivileged client).
  377. \$respBad = Send-Request-As-User \$pipeOk 'POST' '/gpu/set_power_limit?gpu_ids=0&power_limit_mw=99999999&block=true'
  378. if (-not (\$respBad -match 'HTTP/1\\.1 400 Bad Request')) {
  379. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  380. Remove-LocalUser -Name \$testUser -ErrorAction SilentlyContinue
  381. Write-Host " positive 400: FAIL. client output:"; Write-Host \$respBad
  382. throw "SDDL positive 400 test failed (daemon didn't propagate NVML error)"
  383. }
  384. Write-Host " positive 400: PASS (out-of-range power limit returns 400 to unprivileged client)"
  385. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  386. Start-Sleep 1
  387. # --- Negative: restrictive SDDL ('D:(A;;GA;;;BA)') should DENY AU at pipe-open ---
  388. \$pipeNo = 'zeusd-sddl-neg'
  389. \$null = Start-Process -FilePath \$exe \`
  390. -ArgumentList @('serve','--mode','named-pipe','--pipe-name',"\\\\.\\pipe\\\$pipeNo",'--pipe-sddl','D:(A;;GA;;;BA)','--enable','gpu-control,gpu-read') \`
  391. -PassThru -NoNewWindow -RedirectStandardOutput "\$src\\sddl-neg.out" -RedirectStandardError "\$src\\sddl-neg.err"
  392. Start-Sleep -Seconds 4
  393. \$respNo = Send-Request-As-User \$pipeNo 'GET' '/discover'
  394. Get-Process -Name zeusd -ErrorAction SilentlyContinue | Stop-Process -Force
  395. Start-Sleep 1
  396. if (\$respNo -match 'FAILED') {
  397. Write-Host " negative: PASS (got expected failure: \$((\$respNo -split "\`r\`n",2)[0].Trim()))"
  398. } else {
  399. Write-Host " negative: FAIL: expected denial but got:"
  400. Write-Host \$respNo
  401. Remove-LocalUser -Name \$testUser -ErrorAction SilentlyContinue
  402. throw "SDDL negative test failed"
  403. }
  404. Remove-LocalUser -Name \$testUser -ErrorAction SilentlyContinue
  405. Write-Host "ALL_OK"
  406. POWERSHELL
  407. )
  408. echo "Sending build+smoke+load to instance (this takes ~15-25 min on first run)..."
  409. PS_JSON=$(mktemp)
  410. jq -Rn --arg s "$PS_SCRIPT" '{commands: [$s], executionTimeout: ["3600"]}' > "$PS_JSON"
  411. CMD_ID=$(aws ssm send-command --region "$REGION" --document-name AWS-RunPowerShellScript \
  412. --instance-ids "$INSTANCE_ID" --parameters "file://$PS_JSON" --timeout-seconds 3600 \
  413. --query 'Command.CommandId' --output text)
  414. rm -f "$PS_JSON"
  415. until aws ssm get-command-invocation --region "$REGION" --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" \
  416. --query Status --output text 2>/dev/null | grep -qE '^(Success|Failed|Cancelled|TimedOut)$'; do sleep 30; done
  417. STATUS=$(aws ssm get-command-invocation --region "$REGION" --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query Status --output text)
  418. echo "--- ssm stdout ---"
  419. aws ssm get-command-invocation --region "$REGION" --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardOutputContent --output text
  420. echo "--- ssm stderr ---"
  421. aws ssm get-command-invocation --region "$REGION" --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardErrorContent --output text
  422. [[ "$STATUS" == Success ]] || { echo "FAILED ($STATUS)"; exit 1; }
  423. echo "All Windows GPU tests passed."

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.