← Back to Pull requests

vxpu/planner: choose speculative depth and wire separate draft model through CLI #972

Closed
unknown closed this pull request without merging on Nov 30, 2026 15:04 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 21:55 UTC
Author

vxpu/proto: add median draft and verify timings to PlanExecutionStats

Add optional median_draft_ms (field 12) and median_verify_ms (field 13) to PlanExecutionStats alongside the per-position draft/accepted counts from #954 (decode_steps = 9, drafted_by_position = 10, accepted_by_position = 11) so the executor reports draft and verify step latencies as facts for Go speculative depth selection.

Regenerated Go and Python protobuf bindings with ap generate //....

vxpu/planner: choose speculative depth from acceptance counts

Implement Go planner-chosen speculative decoding depth (#646 Move D) on top of #954's raw per-position count reporting:

  • Add vxpu/pkg/kernelplan/speculation_depth.go to read artifact speculation bounds (step_tokens, draft.block, vocab_size with text_config fallback, max_cache_len), validate separate draft artifacts (rejecting missing/non-positive bounds and deepseek_v41), derive empirical per-position survival probabilities and geometric acceptance parameter alpha from drafted_by_position / accepted_by_position (with accepted_drafts_a_step fallback), estimate or read draft/verify step latencies (resolving wrapper-prefixed binding.bound keys and num_local_experts / text_config), and choose the depth k in [0, maxDepth] minimizing net ms/token (returning 0 when speculation does not beat undrafted decode).

  • Integrate SpeculationOptions into kernelplan.PlanArtifact and omit PlanFile.segments when speculation is active so the emitted plan targets verify.pt2 and passes executor plan compatibility checks.

  • Update the Python executor (speculation.py, physplan.py, engine.py) to report median_draft_ms and median_verify_ms alongside #954's raw per-position counts while keeping all policy and depth selection in Go.

  • Add deterministic Go unit tests covering high, medium, and low acceptance, empirical cliffs, extrapolation, missing stats (requested vs unrequested), artifact bounds, cost estimation, and closed-loop depth selection from executor run records.
  • vxpu/cli: wire separate draft-model speculation through plan emit, ask, and router

    Wire separate draft-model speculative decoding and planner-chosen depth through the normal Go CLI and vxpu-router serving path:

  • Add --draft-artifact, --run-record, and --speculation-depth flags to vxpu plan emit and vxpu ask, plus --plan on vxpu ask; validate --speculation-depth bounds (-1 or [0, math.MaxInt32]), reject combining --model or --plan with conflicting plan/speculation flags, and leave LoadModelRequest.PlanFile nil when client-side speculation planning resolves to depth 0 so the router probes real executor hardware.

  • Ship optional verify.pt2 on LoadModelRequest.verify_graph from both vxpu ask and vxpu-router catalog loading (fetchCatalogArtifact), and preserve file:// manifests in local-agent mode when no weightstore is configured.

  • Update vxpu/docs/design.md and CI presubmit scripts (test-vxpu-python and test-vxpu-gpu) with end-to-end Go CLI + vxpu-router separate draft-model verification tests (including loading the planner-chosen run-record plan through vxpu-router and verifying token identity).
  • NVIDIA L4 GPU Verification

    Verified on NVIDIA L4 (driver 580.178.04, 23034 MiB, CUDA 13.0, torch 2.14.1+cu130):

    $ (cd vxpu && VXPU_TEST_DEVICE=cuda go test -v -count=1 -run "^TestSeparateDraftSpeculationOverGRPC$" ./pkg/kernelplan)
    === RUN   TestSeparateDraftSpeculationOverGRPC
    === RUN   TestSeparateDraftSpeculationOverGRPC/refuse_vocab_mismatch
    === RUN   TestSeparateDraftSpeculationOverGRPC/refuse_missing_verify_graph
    === RUN   TestSeparateDraftSpeculationOverGRPC/refuse_depth_exceeds_step_tokens
    === NAME  TestSeparateDraftSpeculationOverGRPC
        speculation_test.go:570: device=cuda exact_match=true generated=14 undrafted_steps=14 spec_steps=7 tokens_a_stream_a_step=1.857 accepted_drafts_a_step=0.857 chosen_depth=2
    --- PASS: TestSeparateDraftSpeculationOverGRPC (70.26s)
        --- PASS: TestSeparateDraftSpeculationOverGRPC/refuse_vocab_mismatch (0.03s)
        --- PASS: TestSeparateDraftSpeculationOverGRPC/refuse_missing_verify_graph (0.01s)
        --- PASS: TestSeparateDraftSpeculationOverGRPC/refuse_depth_exceeds_step_tokens (0.01s)
    PASS
    ok  	github.com/gke-labs/generation-ai/vxpu/pkg/kernelplan	70.290s
    
    $ (cd vxpu && go test -v -count=1 -run "^TestRouterSeparateDraftSpeculation_GPU$" ./cmd/vxpu)
    === RUN   TestRouterSeparateDraftSpeculation_GPU
        speculation_cli_test.go:787: device=cuda exact_match=true generated=14 tokens_a_stream_a_step=1.625 accepted_drafts_a_step=0.625 median_draft_ms=9.919 median_verify_ms=8.229 raw_chosen_depth=0 loaded_chosen_depth=1
    --- PASS: TestRouterSeparateDraftSpeculation_GPU (62.22s)
    PASS
    ok  	github.com/gke-labs/generation-ai/vxpu/cmd/vxpu	62.254s
    

    Also verified after rebasing onto main (#954 and #974): ap generate //..., ap lint ./..., Go unit & CPU end-to-end tests (TestSeparateDraftSpeculationOverGRPC, TestRouterSeparateDraftSpeculation_CPU, TestDeriveSpeculationMetrics, TestVerifySpeculativeRun_NegativeCases), Python vxpu.speculation_test + vxpu.physplan_test (28 tests), and pyright==1.1.414 (0 errors).

    Fixes #971

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: justinsb Review duration: 1029m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #972"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%