Skip to content

feat(planner): power budget enforcement - #9684

Closed
kaim-eng wants to merge 5 commits into
pr1b/planner-infrafrom
pr2/power-budget
Closed

kaim-eng wants to merge 5 commits into
pr1b/planner-infrafrom
pr2/power-budget

Conversation

@kaim-eng

@kaim-eng kaim-eng commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Part of the PR #9369 split plan.
This is PR 3 of 6 (PR 2 — Power Budget Enforcement). Held in Draft per plan §4.5 until PR 1a + PR 1b are approved.

Predecessor: #9683 — Planner power infrastructure
Successor: #9685 (Draft) — AIC closed-loop optimizer

Scope

Budget clamping works, opt-in via config. Adds _apply_power_budget() to the state machine, wired into both load- and throughput-scaling paths. Includes the decode-no-upscale clamp in _apply_global_budget() (3-line post-proportional_clamp_pair invariant — see plan §2.3 for the post-rebase mechanic note).

~1,200 lines · 4 files. Budget is only active when enable_power_awareness=True and total_gpu_power_limit is set.

  • core/state_machine.py — _apply_power_budget() method (66 LOC) + decode-no-upscale clamp in _apply_global_budget()
  • core/load_scaling.py / core/throughput_scaling.py — 1-line call sites
  • tests/unit/test_state_machine.py — TestApplyGlobalBudgetNoUpscale class (5 tests, 68 LOC)

Reviewer onboarding

  • Design context (PR 5): docs/design-docs/powerplanner-design.md §6.1 (budget clamping), §6.2 (decode-no-upscale invariant)
  • Plan section: §2.3 (this PR)

Tests at this tip (projection per plan §4.4 — will re-measure on dev pod before marking Ready for Review)

  • All PR 1a + 1b tests still pass
  • TestApplyGlobalBudgetNoUpscale — 5 passed
  • Plan projection: ~559 passed, 1 skipped (planner) + 43 (power_agent) = ~602 total

Merge strategy

Rebase-and-merge (no squash). Mark Ready for Review only after both PR 1a and PR 1b have approvals, and rebase onto whichever predecessor lands first.

@copy-pr-bot

copy-pr-bot Bot commented May 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Adds the Power Agent DaemonSet (privileged, hostPID) that watches pods
for the dynamo.nvidia.com/gpu-power-limit annotation, parses
/proc/{pid}/cgroup to recover pod UIDs (handles all K8s QoS x cgroup
driver x CRI runtime variants), and calls
nvmlDeviceSetPowerManagementLimit per physical GPU.

Includes NVML cap clamping to SKU-specific [min_w, max_w] bounds,
UUID-gated orphan-cap restoration on startup, SIGTERM-handler default-
TGP restore, and a multi-pod-per-GPU policy that falls back to
power_agent_safe_default_watts on conflict.

43 unit tests covering apply_cap, cgroup_parser, multi_pod_policy,
shutdown. Standalone component - no coupling to planner internals.

CI filter (.github/filters.yaml) extends the planner group to cover the
new component + deploy paths so changes here trip the planner job set.

Part of the PR #9369 split (PR 1a of 6). See docs/design-docs/pr9369-split-plan.md.

Signed-off-by: Kai Ma <[email protected]>
@kaim-eng
kaim-eng force-pushed the pr1b/planner-infra branch from 1d7b243 to 8126b1a Compare May 19, 2026 12:57
@kaim-eng
kaim-eng force-pushed the pr2/power-budget branch from 739bed9 to 7be3a27 Compare May 19, 2026 12:58
kaim-eng added 4 commits May 19, 2026 11:17
Folds deploy/power_agent/{daemonset,rbac,dev-pod}.yaml into a single
Helm chart at deploy/helm/charts/power-agent/, resolving the three
CodeRabbit findings on PR #9682:

  * hardcoded metadata.namespace=default -> {{ .Release.Namespace }}
  * mutable image :latest -> required image.tag with fail-fast validator
  * `${POWER_AGENT_NAMESPACE}` envsubst placeholder -> native Helm templating

The chart supports three deployment shapes selectable via values:
production DaemonSet (default, cluster-wide RBAC), namespace-restricted
production (Role+RoleBinding), and an in-cluster dev-iteration Pod
mounting power_agent.py from a ConfigMap. Three template-time validators
reject foot-guns at install time: empty image.tag, mutex violations
between daemonset.enabled and dev.enabled, and dev mode without a
pinned dev.nodeName. Dev mode also automatically forces namespace-scoped
RBAC (least privilege), leveraging power_agent.py's --namespace flag.

Design rationale, scope decisions, and review-feedback responses are
captured in docs/design-docs/power-agent-helm-chart-plan.md, committed
alongside the chart.

components/power_agent/README.md flips its install recipe to
``helm install``, and the planner CI filter (.github/filters.yaml) is
retargeted from deploy/power_agent/** to deploy/helm/charts/power-agent/**.
Two examples/deployments/powerplanner/*.yaml header references live on
PR #9687 and will be updated during that PR's cascade rebase per plan
section 5.3.

Validated locally:
  helm lint                                -> 0 errors
  helm template (3 positive exercises)     -> expected resources
  helm template (3 negative exercises)     -> expected fail-fast errors
  components/power_agent/tests/            -> 43/43 passed
  .github/scripts/test-filters.js          -> 20/20 passed
  pre-commit (cross-cutting hooks)         -> all applicable passed

Signed-off-by: Kai Ma <[email protected]>
…S.txt

copyright-checks (regex requiring `#`-prefixed SPDX lines) rejected the
Go-template-comment header in _helpers.tpl and the missing header in
NOTES.txt on commit 8e490a7. Switch both to the same 2-line
`#`-prefixed form already used by the other 9 chart files, aligning
with @grahamking's PR review preference (minimal SPDX, no Apache
boilerplate).

For NOTES.txt this adds two visible lines to the post-`helm install`
banner, matching the project convention established by
deploy/helm/charts/platform/templates/NOTES.txt.

For _helpers.tpl the header sits outside any `{{- define -}}` block, so
it is never invoked at render time and is invisible to consumers
despite not being inside a Go template comment.

Re-validated locally:
  helm lint                              -> 0 errors
  helm template (default mode)           -> 4 expected kinds
  pre-commit on the two touched files    -> all applicable hooks pass

Signed-off-by: Kai Ma <[email protected]>
…rometheus

Adds the planner-side mechanism for power-aware operation:
- 5 PlannerConfig fields (enable_power_awareness defaults False) with
  required-when-enabled validator for total_gpu_power_limit and
  power_agent_safe_default_watts
- _apply_power_annotations() reconciliation loop on every tick,
  gated on the feature flag, with POWER_ANNOTATION_KEY constant
- _publish_power_budget_metrics() dashboard gauges (static config,
  not DCGM, so it remains valid when attribution drops)
- CoreV1Api + patch_pod_annotation + list_pods_by_label on KubernetesAPI
- get_component_pods + list_frontend_pods + resolve_frontend_http_port
  on KubernetesConnector
- get_total_dgd_power DCGM Prometheus query + NaN-filter fix on the
  frontend-source path
- 3 planner_metrics gauges: power_budget_total_watts,
  power_projected_watts, power_budget_utilization
- Operator Helm chart bump 1.2.0 -> 1.2.1 with planner pod-RBAC patch
  (pods: get/list/watch/patch) plus deploy/planner-pod-rbac-dev.yaml
  for non-operator development clusters
- repo-shared components/src/conftest.py (planner pkg conftest)
- 623-line unit suite (test_actuation_knobs.py) + 567-line live
  integration suite (test_actuation_knobs_live.py) covering every
  actuation knob this PR adds
- Unit test additions on test_kubernetes_connector.py (~119 lines)
  and test_prometheus.py (NaN tests + TestPowerAwareDcgmQueries
  get_total_dgd_power subset, ~100 lines)
- CI filter (.github/filters.yaml) extends the planner group with
  components/src/conftest.py

Power awareness is off by default. Budget enforcement
(_apply_power_budget) and the AIC closed loop arrive in PR 2 and PR 3.

Part of the PR #9369 split (PR 1b of 6). Predecessor PR 1a (power-agent
component) must merge first or land in parallel. See
docs/design-docs/pr9369-split-plan.md.

Signed-off-by: Kai Ma <[email protected]>
Adds _apply_power_budget() to PlannerStateMachine, wired into both
load-scaling and throughput-scaling paths (one-line call site each).
Budget enforcement runs only when enable_power_awareness=True and
total_gpu_power_limit is set, so it is a no-op on existing deployments.

Includes a no-upscale-decode invariant in _apply_global_budget: when
proportional_clamp_pair (from main's budget helper, see PR #9296) would
allocate decode beyond original demand because prefill is the binding
constraint, decode is clamped back to min(num_d, min_endpoint). This
preserves the original behavioural contract from the pre-rebase inline
formula while delegating to main's shared clamp.

68-line TestApplyGlobalBudgetNoUpscale suite (5 tests) pins the
no-upscale invariant.

Part of the PR #9369 split (PR 2 of 6). See docs/design-docs/pr9369-split-plan.md.

Signed-off-by: Kai Ma <[email protected]>
@kaim-eng
kaim-eng force-pushed the pr1b/planner-infra branch from 8126b1a to f7f3226 Compare May 19, 2026 15:54
@kaim-eng
kaim-eng force-pushed the pr2/power-budget branch from 7be3a27 to 0c9050c Compare May 19, 2026 15:55
@kaim-eng
kaim-eng force-pushed the pr1b/planner-infra branch from 7696f3f to 8f47413 Compare May 25, 2026 14:17
@kaim-eng
kaim-eng force-pushed the pr1b/planner-infra branch 2 times, most recently from 35716ac to b1ebd8b Compare June 8, 2026 16:41
@kaim-eng
kaim-eng force-pushed the pr1b/planner-infra branch 9 times, most recently from b9c0068 to f0d4475 Compare July 14, 2026 20:04
kaim-eng added a commit that referenced this pull request Jul 24, 2026
Summary
-------
Rework the power feature so the Planner READS per-GPU caps from DGD worker
podTemplate annotations (dynamo.nvidia.com/gpu-power-limit) and clamps replica
scaling against a total power budget, instead of owning/PATCHing per-Pod caps.
Supersedes the Planner-owned Pod-PATCH stack (#9683-#9685).

- Caps are authored on worker podTemplate annotations, applied to Pods by the
  operator, and enforced by the Power Agent; the Planner only reads them.
- DGD parsing: Service.get_gpu_power_limit_watts, ComponentPowerConfig,
  resolve_component_power_configs (disagg + agg via the generic type:worker
  fallback), positive-int GPU/nodeCount validation.
- Config: remove Planner-owned per-GPU write fields (rejected via a migration
  validator); require environment=kubernetes when awareness is on.
- Deployment state/capabilities carry resolved per-replica watts and a
  deployment-scoped scale-up-blocked flag. Init is strict/fail-closed; runtime
  is conservative (keep last-good, hold the per-role max, block scale-up on a
  changed/malformed cap or a transient apiserver error).
- Projection gauges read cached state; final budget boundary applies GPU budget
  then power budget (ceiling-only clamp, decode-no-upscale, partial-proposal
  masks; power wins over the GPU floor), plus a startup min-footprint gate.
  While ANY power-relevant role is mid-rollout the Kubernetes environment marks
  BOTH roles' settled target unknown (one deployment-wide stability flag), so
  every role's scale-up is held at its ready count -- keyed off rollout state,
  not None targets, since the merge fills every role. The projection then masks
  any target equal to its ready count back to None, so a held scale-up emits
  nothing and a scale-down of one role does not drag the other role's echoed
  ready count along (DisaggPlanner applies every non-None target as the new DGD
  desired); the in-flight rollout's desired is left untouched and a proposal
  cannot admit an over-budget settled state.
- Remove the Pod sweep/PATCH machinery, pods/patch RBAC, and superseded frontend
  scaffolding (get_component_pods / list_frontend_pods / post_busy_threshold);
  the baseline get_frontend_metrics_url is retained. Correct Power Agent
  ownership docstrings. Add example + docs.

The budget is a projected ceiling over the requested caps, not a proven hardware
limit; effective-cap feedback is deferred to a dynamic-control design.

Validation
----------
- 555 planner tests pass (unit suite + mocked no-mutation integration gate);
  black/isort/ruff/flake8 clean. (The broader plugins/offline test trees need
  grpc/aiconfigurator, absent in this env, and are unaffected by this change.)
- Cut fresh from origin/main; power-only diff -- no aggregate name-plumbing (the
  generic type:worker fallback and the power resolver are kept).

Refs #9683, #9684, #9685

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Kai Ma <[email protected]>
kaim-eng added a commit that referenced this pull request Jul 28, 2026
Summary
-------
Rework the power feature so the Planner READS per-GPU caps from DGD worker
podTemplate annotations (dynamo.nvidia.com/gpu-power-limit) and clamps replica
scaling against a total power budget, instead of owning/PATCHing per-Pod caps.
Supersedes the Planner-owned Pod-PATCH stack (#9683-#9685).

- Caps are authored on worker podTemplate annotations, applied to Pods by the
  operator, and enforced by the Power Agent; the Planner only reads them.
- DGD parsing: Service.get_gpu_power_limit_watts, ComponentPowerConfig,
  resolve_component_power_configs (disagg + agg via the generic type:worker
  fallback), positive-int GPU/nodeCount validation.
- Config: remove Planner-owned per-GPU write fields (rejected via a migration
  validator); require environment=kubernetes when awareness is on.
- Deployment state/capabilities carry resolved per-replica watts and a
  deployment-scoped scale-up-blocked flag. Init is strict/fail-closed; runtime
  is conservative (keep last-good, hold the per-role max, block scale-up on a
  changed/malformed cap or a transient apiserver error).
- Projection gauges read cached state; final budget boundary applies GPU budget
  then power budget (ceiling-only clamp, decode-no-upscale, partial-proposal
  masks; power wins over the GPU floor), plus a startup min-footprint gate.
  While ANY power-relevant role is mid-rollout the Kubernetes environment marks
  BOTH roles' settled target unknown (one deployment-wide stability flag), so
  every role's scale-up is held at its ready count -- keyed off rollout state,
  not None targets, since the merge fills every role. The projection then masks
  any target equal to its ready count back to None, so a held scale-up emits
  nothing and a scale-down of one role does not drag the other role's echoed
  ready count along (DisaggPlanner applies every non-None target as the new DGD
  desired); the in-flight rollout's desired is left untouched and a proposal
  cannot admit an over-budget settled state.
- Remove the Pod sweep/PATCH machinery, pods/patch RBAC, and superseded frontend
  scaffolding (get_component_pods / list_frontend_pods / post_busy_threshold);
  the baseline get_frontend_metrics_url is retained. Correct Power Agent
  ownership docstrings. Add example + docs.

The budget is a projected ceiling over the requested caps, not a proven hardware
limit; effective-cap feedback is deferred to a dynamic-control design.

Validation
----------
- 555 planner tests pass (unit suite + mocked no-mutation integration gate);
  black/isort/ruff/flake8 clean. (The broader plugins/offline test trees need
  grpc/aiconfigurator, absent in this env, and are unaffected by this change.)
- Cut fresh from origin/main; power-only diff -- no aggregate name-plumbing (the
  generic type:worker fallback and the power resolver are kept).

Refs #9683, #9684, #9685

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Kai Ma <[email protected]>
kaim-eng added a commit that referenced this pull request Jul 30, 2026
Summary
-------
Rework the power feature so the Planner READS per-GPU caps from DGD worker
podTemplate annotations (dynamo.nvidia.com/gpu-power-limit) and clamps replica
scaling against a total power budget, instead of owning/PATCHing per-Pod caps.
Supersedes the Planner-owned Pod-PATCH stack (#9683-#9685).

- Caps are authored on worker podTemplate annotations, applied to Pods by the
  operator, and enforced by the Power Agent; the Planner only reads them.
- DGD parsing: Service.get_gpu_power_limit_watts, ComponentPowerConfig,
  resolve_component_power_configs (disagg + agg via the generic type:worker
  fallback), positive-int GPU/nodeCount validation.
- Config: remove Planner-owned per-GPU write fields (rejected via a migration
  validator); require environment=kubernetes when awareness is on.
- Deployment state/capabilities carry resolved per-replica watts and a
  deployment-scoped scale-up-blocked flag. Init is strict/fail-closed; runtime
  is conservative (keep last-good, hold the per-role max, block scale-up on a
  changed/malformed cap or a transient apiserver error).
- Projection gauges read cached state; final budget boundary applies GPU budget
  then power budget (ceiling-only clamp, decode-no-upscale, partial-proposal
  masks; power wins over the GPU floor), plus a startup min-footprint gate.
  While ANY power-relevant role is mid-rollout the Kubernetes environment marks
  BOTH roles' settled target unknown (one deployment-wide stability flag), so
  every role's scale-up is held at its ready count -- keyed off rollout state,
  not None targets, since the merge fills every role. The projection then masks
  any target equal to its ready count back to None, so a held scale-up emits
  nothing and a scale-down of one role does not drag the other role's echoed
  ready count along (DisaggPlanner applies every non-None target as the new DGD
  desired); the in-flight rollout's desired is left untouched and a proposal
  cannot admit an over-budget settled state.
- Remove the Pod sweep/PATCH machinery, pods/patch RBAC, and superseded frontend
  scaffolding (get_component_pods / list_frontend_pods / post_busy_threshold);
  the baseline get_frontend_metrics_url is retained. Correct Power Agent
  ownership docstrings. Add example + docs.

The budget is a projected ceiling over the requested caps, not a proven hardware
limit; effective-cap feedback is deferred to a dynamic-control design.

Validation
----------
- 555 planner tests pass (unit suite + mocked no-mutation integration gate);
  black/isort/ruff/flake8 clean. (The broader plugins/offline test trees need
  grpc/aiconfigurator, absent in this env, and are unaffected by this change.)
- Cut fresh from origin/main; power-only diff -- no aggregate name-plumbing (the
  generic type:worker fallback and the power resolver are kept).

Refs #9683, #9684, #9685

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Kai Ma <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the Stale label Nov 5, 2026
@github-actions
github-actions Bot deleted the branch pr1b/planner-infra November 10, 2026 09:35
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed due to inactivity. If you believe this PR is still relevant, please feel free to reopen it with additional context or information.

@github-actions github-actions Bot closed this Nov 10, 2026
@github-actions
github-actions Bot deleted the pr2/power-budget branch November 10, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant