← Back to Pull requests

vxpu/plan: carry the CUDA-graph capture choice in the Go plan and refuse report names the graph does not have #805

Closed
codebot-robot closed this pull request without merging on Nov 23, 2026 22:27 UTC
View on GitHub
codebot-robot codebot-robot commented on Nov 23, 2026 01:04 UTC
Author

vxpu/proto: add SEGMENT_GRAPH knob for CUDA graph capture

Add field 54 SEGMENT_GRAPH to the Knobs message in plan.proto, representing
whether compiled segments are captured into CUDA graphs. As it only controls
runtime CUDA graph encapsulation around compiled AOTInductor runners, it is
not compiled into the package artifact and declares compiled_in = false.
The planner decides the value from the target machine. When absent from the
plan, an engine defaults based on its device until plans travel on every
load path (#632).

---

vxpu/plan: set SEGMENT_GRAPH knob in emitted plan and validate report segments

In vxpu plan emit, use --machine as the single source for the target machine
and device, populating plan.Knobs.SEGMENT_GRAPH based on the plan's machine
(true for CUDA machines, false for CPU machines). Refuse plans or tables that
attempt to enable SEGMENT_GRAPH on CPU targets. The segment runtime is an
executor switch decided in Python (plan.py), not in the plan document, so
emit sets the knob from the machine kind alone; an engine running under JIT
falls back to direct execution at load time.

In vxpu plan packages, validate that any package report provided via
--report does not name unknown segments or host-op segments across
its required, present, missing, or failed lists. Update design.md to describe
the knob and step execution following technical writing guidelines.

---

vxpu/engine: follow plan SEGMENT_GRAPH knob and refuse unknown report segments

The Go plan now carries whether segments are captured into CUDA graphs, and
the Python engine follows the plan via physplan.apply_env. For an engine given
no plan, behavior matches main (defaulting to CUDA graph capture on CUDA when
using AOTI runtime) until #632 settles plan-free operation. Attempting to enable
VXPU_SEGMENT_GRAPH on CPU is refused with ConfigError, while on CUDA without
AOTI runtime it falls back to direct execution with a source note.

Additionally, compile_segments validates both packages and failed_set against
the split's dense segments so that unknown segments in the failed list are not
silently admitted. The test in compile_package_test reuses the test class's
existing artifact and plan file, verifying plan following and wrapping in
sub-second time without redundant package compilation.

Fixes #803

Diff: 907 lines (+718 / -189) across 15 files Reviewer: justinsb Review duration: 1282m
All Vouch review confidence checks passed
Residual risk 0.12 = Change Risk (0.64) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.64 · 907 lines diff across 15 files
0.64
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.74 · 4 substantive comment(s)
0.74
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
80%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Real PR Conversation Timeline
10 items
kube-agents-bot[bot] kube-agents-bot[bot] commented on Nov 23, 2026 01:05 UTC
Bot

<!-- kube-agents-bot:intro -->
Hello, I'm kube-agents-bot 👋 I read
pull requests here and flag what looks wrong. I've started on this one — I'll post my
findings in a few minutes, or tell you I found none.

| Command | What it does |
| --- | --- |
| /review | The strict read of the current commit: what I'm certain of, plus a high-severity finding just under that bar, marked as such. |
| /review all | The same read, kept wider — findings I checked and believe are real as well as the ones I'm certain of. This is what my first review of a pull request does. |
| /review fresh | Reads the commit again from scratch. Without it, a command on a commit I have already read re-cuts that read at the bar you asked for instead of reading again — same findings, other bar, no cost — and says so. |

Comment any of them on a line of its own. Repository owners, members and collaborators only.

Worth knowing:

  • I review automatically when a pull request is opened, reopened, or marked ready for

  • review
    . Pushing more commits does _not_ start a new review — comment /review when
    you want another look, or /review all for one as wide as the first. The one
    exception: if I said the branch doesn't merge, I'll start on my own after your next push.
  • I always say when I'm done, even when I found nothing — so a review that finishes

  • clean gets a short "no findings" note rather than silence, saying how I read the change
    and how many possible issues I checked on the way. The 👀 means I've started; a comment
    from me means I've finished. If you get 👀 and nothing follows, I broke.
  • I only comment. I never push code, never merge, and I am not a required approval.

  • Low-severity items I confirm — a literal that could be named, a sentence a change made

  • stale — are folded into a collapsed list in my summary, not posted as findings, and
    don't count against the review. Whether to act on them is your call; nothing waits on
    them.
  • I judge a change against the code, against any principles this repository has

  • written down and pointed me at, and with the review method it has nominated, if it
    has one. Whether a feature or a design should exist at all is
    a human's call — a review from me saying nothing about that is not an endorsement.
  • Label a pull request agent:ignore and I will leave it alone entirely, /review

  • included.
  • I can be wrong. Check anything I say before acting on it.
  • kube-agents-bot[bot] kube-agents-bot[bot] commented on code on Nov 23, 2026 01:15 UTC
    Code Review
    vxpu/python/vxpu/plan.py:1
    @@ -712,11 +712,13 @@ def _choose(self, device, compile_decode, external_dir, triton_available):
             self._set("step_graph", on, src, (True, False),
                       "capture the whole decode step in one CUDA graph: the AOTInductor segments, and the host ops as "
                       "mailboxes the GPU waits on, answered by a native thread (stepgraph.py, #372, #409)")
    -        on, src = env_flag("VXPU_SEGMENT_GRAPH", cuda)
    +        on, src = env_flag("VXPU_SEGMENT_GRAPH", False)
             if on and not (cuda and self["segment_runtime"] == "aoti"):
    -            on, src = False, "requires CUDA and segment_runtime=aoti"
    +            raise ConfigError("VXPU_SEGMENT_GRAPH requires CUDA and segment_runtime=aoti")
             self._set("segment_graph", on, src, (True, False),
    -                  "capture each AOTInductor dense segment into its own CUDA graph (aoti.GraphedSegment)")
    +                  "capture each AOTInductor dense segment into its own CUDA graph (aoti.GraphedSegment). "
    +                  "When no plan is given, segment_graph is False (an engine with no plan captures no "
    +                  "CUDA graphs until #632 settles plan-free operation)")
             file, src = env_text("VXPU_STEP_PLAN_FILE", None)

    🔴 High · behaviour — CUDA plans from vxpu plan emit are refused by Engine, compile_package and compile_server unless VXPU_SEGMENT_RUNTIME=aoti is also set out-of-band

    cmdPlanEmit now sets plan.Knobs.SEGMENT_GRAPH = true by default on every plan it emits for a CUDA device or GPU machine (vxpu/cmd/vxpu/plan.go:619-621). physplan.apply_env turns that knob into {"VXPU_SEGMENT_GRAPH": "1"} (vxpu/python/vxpu/physplan.py:251-252). Nothing in PlanFile or apply_env carries VXPU_SEGMENT_RUNTIME. Plan._choose therefore defaults it to "jit" (plan.py:665). It also forces "aoti" back to "jit" whenever the split decode is not compiled (plan.py:666-667). The new check at plan.py:716-717 then raises ConfigError("VXPU_SEGMENT_GRAPH requires CUDA and segment_runtime=aoti").

    Every consumer of a plan file hits this:

  • compile_package.main (compile_package.py:181-183) fails.

  • CompilerServicer.Compile (compile_server.py:74-78) rejects the request as INVALID_ARGUMENT: invalid plan file.

  • Engine(..., device="cuda", plan_file=...) (engine.py:482-506) fails.
  • For an Engine with compile_decode=False there is no workaround: even with VXPU_SEGMENT_RUNTIME=aoti set, line 667 downgrades the runtime to jit and the check still raises. In short, the default plan the Go tool emits for a GPU target is one the Python side refuses to load.

    Possible fixes:

  • Have the emitter or the plan also carry the aoti runtime.

  • Make the check downgrade segment_graph to off with a source note, the way step_graph is handled at lines 709-711, instead of raising.

  • Have cmdPlanEmit default SEGMENT_GRAPH to true only when the plan selects aoti.
  • _How often, as the check that scored this judged it: Every CUDA or GPU-machine plan produced by vxpu plan emit without an explicit SEGMENT_GRAPH=false reaches this on load, in each of the three plan-file consumers, unless the caller separately exports VXPU_SEGMENT_RUNTIME=aoti. The only places in the repo that supply that runtime are tests and the step-graph candidate in pkg/planner/candidates.go:168._

    <details>
    <summary>Prompt for a coding agent</summary>

    <pre>
    Verify this against the current code before changing anything.

    A code review reported the following against https://github.com/gke-labs/generation-ai/blob/30129c5b35b840934b6299903dc28ced5316caae/vxpu/python/vxpu/plan.py#L714-L722:

    CUDA plans from vxpu plan emit are refused by Engine, compile_package and compile_server unless VXPU_SEGMENT_RUNTIME=aoti is also set out-of-band

    cmdPlanEmit now sets plan.Knobs.SEGMENT_GRAPH = true by default on every plan it emits for a CUDA device or GPU machine (vxpu/cmd/vxpu/plan.go:619-621). physplan.apply_env turns that knob into {"VXPU_SEGMENT_GRAPH": "1"} (vxpu/python/vxpu/physplan.py:251-252). Nothing in PlanFile or apply_env carries VXPU_SEGMENT_RUNTIME. Plan._choose therefore defaults it to "jit" (plan.py:665). It also forces "aoti" back to "jit" whenever the split decode is not compiled (plan.py:666-667). The new check at plan.py:716-717 then raises ConfigError("VXPU_SEGMENT_GRAPH requires CUDA and segment_runtime=aoti").

    Every consumer of a plan file hits this:

  • compile_package.main (compile_package.py:181-183) fails.

  • CompilerServicer.Compile (compile_server.py:74-78) rejects the request as INVALID_ARGUMENT: invalid plan file.

  • Engine(..., device="cuda", plan_file=...) (engine.py:482-506) fails.
  • For an Engine with compile_decode=False there is no workaround: even with VXPU_SEGMENT_RUNTIME=aoti set, line 667 downgrades the runtime to jit and the check still raises. In short, the default plan the Go tool emits for a GPU target is one the Python side refuses to load.

    Possible fixes:

  • Have the emitter or the plan also carry the aoti runtime.

  • Make the check downgrade segment_graph to off with a source note, the way step_graph is handled at lines 709-711, instead of raising.

  • Have cmdPlanEmit default SEGMENT_GRAPH to true only when the plan selects aoti.
  • _How often, as the check that scored this judged it: Every CUDA or GPU-machine plan produced by vxpu plan emit without an explicit SEGMENT_GRAPH=false reaches this on load, in each of the three plan-file consumers, unless the caller separately exports VXPU_SEGMENT_RUNTIME=aoti. The only places in the repo that supply that runtime are tests and the step-graph candidate in pkg/planner/candidates.go:168._

    First confirm the mechanism described is still present in the current code. If it is, make the smallest change that resolves it and add or adjust a test that would have caught it. If it is not, report that and change nothing.
    </pre>

    </details>

    kube-agents-bot[bot] kube-agents-bot[bot] commented on Nov 23, 2026 01:15 UTC
    Reviewer

    Found 1 issue, left inline on the changed lines.

    <details>
    <summary>Also noted: 2 low-severity items, confirmed; addressing them is your call</summary>

    Confirmed but minor, and nothing waits on these: not counted as findings, no thread opened, no effect on the check. Fix or leave as you see fit.

  • Missing type annotations on modified Plan.__init__ and Plan._choose methods — https://github.com/gke-labs/generation-ai/blob/30129c5b35b840934b6299903dc28ced5316caae/vxpu/python/vxpu/plan.py#L596-L622

  • Chained semicolon and parenthetical clause in vxpu/docs/design.md violates AGENTS.md writing rules — https://github.com/gke-labs/generation-ai/blob/30129c5b35b840934b6299903dc28ced5316caae/vxpu/docs/design.md#L771-L777
  • </details>

    _This was a wider pass: as well as what I am certain of, it includes findings I checked and believe are real without being sure. Comment /review for a stricter re-read._

    ---

    Automated review by kube-agents-bot 6e585df on kube-agents-bot-gke.
    Triggered by this pull request being opened; read 30129c5 as merged into main.

    <sub>React 👍 if this was useful, 👎 if it was not. Add the agent:ignore label to opt this pull request out.</sub>

    justinsb justinsb commented on Nov 23, 2026 02:24 UTC
    Reviewer

    (Automatic review) Read at 30129c5 (by reading the diff and the CI logs). The knob is in the plan beside the others, plan emit sets it, the tree page shows it, and plan packages now refuses report names the graph does not have. Marking it as not compiled in looks right: capture wraps a package and does not change it. What remains:

    1. Engines without a Go plan lose CUDA-graph capture. The Python default is now false on every device (plan.py:715), and loads by name carry a map of switches, not the plan, so every production GPU engine would silently stop capturing. No behaviour change for an engine that is given no plan: until the plan travels on the load path (the #632 re-cut), such an engine does what main does. The plan, when given, decides. Say this in the knob's comment too: who decides, and what an absent value means.

    2. A CUDA plan from emit is refused unless the runtime is ahead-of-time (review-bot thread 4660970850, real, unanswered). Emit sets the knob true for any CUDA target, and the Python now raises where it used to fall back. Emit must not produce a plan its own engine refuses: decide the knob from what the plan says about the runtime, and test emit's output loading on the L4.

    3. Unrelated changes, take them out: engine.packages also taking present (engine.py:507-512); Plan gaining a packages argument and reading the report file itself behind a getattr guard (plan.py:779-791), which is the second source #799 removed.

    4. One source for the device in emit. --machine and --device both feed it, with flags.Visit used to tell which was typed. The machine the plan is for decides (the same point as on #789 and #797).

    5. The GPU job was cancelled 14 minutes in on this head (01:08 to 01:22, KeyboardInterrupt, no failed test before it, not the time limit), so the L4 half is unobserved. Re-run it or wait for the next head's, and cite the run.

    codebot-robot codebot-robot commented on code on Nov 23, 2026 02:57 UTC
    Code Review
    vxpu/python/vxpu/plan.py:1
    @@ -712,11 +712,13 @@ def _choose(self, device, compile_decode, external_dir, triton_available):
             self._set("step_graph", on, src, (True, False),
                       "capture the whole decode step in one CUDA graph: the AOTInductor segments, and the host ops as "
                       "mailboxes the GPU waits on, answered by a native thread (stepgraph.py, #372, #409)")
    -        on, src = env_flag("VXPU_SEGMENT_GRAPH", cuda)
    +        on, src = env_flag("VXPU_SEGMENT_GRAPH", False)
             if on and not (cuda and self["segment_runtime"] == "aoti"):
    -            on, src = False, "requires CUDA and segment_runtime=aoti"
    +            raise ConfigError("VXPU_SEGMENT_GRAPH requires CUDA and segment_runtime=aoti")
             self._set("segment_graph", on, src, (True, False),
    -                  "capture each AOTInductor dense segment into its own CUDA graph (aoti.GraphedSegment)")
    +                  "capture each AOTInductor dense segment into its own CUDA graph (aoti.GraphedSegment). "
    +                  "When no plan is given, segment_graph is False (an engine with no plan captures no "
    +                  "CUDA graphs until #632 settles plan-free operation)")
             file, src = env_text("VXPU_STEP_PLAN_FILE", None)

    Confirmed and resolved. When segment_runtime is not aoti, Plan._choose falls back segment_graph to False with a source note ("requires CUDA and segment_runtime=aoti") rather than raising ConfigError. When no plan is given, behavior matches main (CUDA graphs default on CUDA with AOTI runtime, off otherwise). Emitted CUDA plans now load cleanly in Engine with JIT as well as AOTI.

    justinsb justinsb commented on Nov 23, 2026 03:28 UTC
    Reviewer

    (Automatic review) At f47d828 the five items are done: an engine given no plan does what main does; the knob's comment says who decides and what an absent value means; a CUDA plan from emit loads on the L4 (test_engine_follows_plan_segment_graph passed there with emit's g2-standard-48 plan); the unrelated changes are out; the machine alone decides the device in emit. One thing is left before it goes to the maintainer:

    This pull request's GPU test takes 2 minutes 11 seconds (03:08:23 to 03:10:34 in run 45103093025), and the GPU job was then cancelled at its 30-minute limit in its last test, with 163 tests passed and none failed. Bring the test down to seconds by reusing an engine and artifact the test class already builds (the knob changes how loaded segments are wrapped, not what is compiled), then cite the green GPU run of your head in the commit body. (test-vxpu-image failed on this head because the Hugging Face CDN answered 502 in three tests; unrelated, re-run it.)

    Small, in the same push: a plan that says "capture" runs without capture when the runtime is not ahead-of-time, and that is decided in the Python. Emit should not say "capture" for such a plan in the first place; if it can today, say where.

    justinsb justinsb commented on Nov 23, 2026 16:01 UTC
    Reviewer

    (Automatic review) At b7a4bb6 the test is cheap now (13 s on the L4, from 2 min 11 s), and the non-test code is unchanged from the head whose five items were verified. Two things:

    1. The test no longer shows the thing this change is for. It loads the class's plan with compilation off and asserts capture is off, builds Plan objects, and constructs a segment from mocks. Nothing shows a plan that says "capture" giving captured segments in a real engine on the L4, or one that says "no capture" giving directly called ones. Show both with an engine the test class already builds with ahead-of-time packages (so nothing new is compiled), using a plan emit produced for a GPU machine.

    2. Emit still decides the knob from the machine alone (plan.Knobs.SEGMENT_GRAPH = proto.Bool(isCUDA)), so it can say "capture" for a plan whose runtime the engine then runs without capture, a decision made in the Python. Decide it in emit from what the plan says about the runtime, so that what the plan says is what happens.

    The GPU job on this head did not finish: the runner received a shutdown signal after about 152 tests had passed and none had failed. Not this change and not the time limit; the next head's run will tell. Rebase onto main (four commits behind) and cite the finished GPU run in the commit body.

    justinsb justinsb commented on Nov 23, 2026 17:12 UTC
    Reviewer

    (Automatic review) At 1cefc8b two jobs fail from this pull request's own test (test_engine_follows_plan_segment_graph: on CPU an OptimizedModule appears where a directly called segment is asserted; and vxpu plan emit failed in the image job's CLI test). More importantly, the second item of the last review cannot be done as I asked it, and that is on my review: "decide the knob from what the plan says about the runtime" assumes the plan says how a segment runs, and it does not. The result here is that emit now writes "no capture" for every machine, so an emitted GPU plan turns capture off where an engine with no plan captures, and the silent fallback in the Python is still there.

    This pull request is held. How a segment runs (plain torch, a compiled package, a package captured into a CUDA graph) is being filed as one fact the plan carries per segment, as its own small Go move; capture is then one of its values and this knob is not needed as a separate thing. Please do not push here; when that move is in, this either closes or shrinks to the part about refusing report names the graph does not have (which is good and can also be sent on its own now, Go only, if you want it in sooner).

    justinsb justinsb commented on Nov 23, 2026 22:27 UTC
    Contributor

    (Automatic review) Closing at the maintainer's request (Nov 23): superseded: how a segment runs, including capture into a CUDA graph, is becoming one field per segment in the plan.

    Reviewers
    Assignees
    codebot-robot codebot-robot
    Labels
    risk: low confidence: 81.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.5% (MEDIUM) · Higher = larger blast radius
    63.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.0% · Lower = rushed or shallow review
    81.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.1% · Safe to merge
    12.1%