← Back to Pull requests

[Attention] Size FlashInfer workspace from scheduler-owned bounds #130

Closed
unknown closed this pull request without merging on Sep 22, 2026 15:02 UTC
View on GitHub
unknown unknown commented on Sep 15, 2026 09:56 UTC
Author

Purpose

The reservation this stacks on takes FlashInfer's default workspace arena, because it has no way to ask for less. FlashInfer's workspace_size() answers for one plan(), which is not enough here: the scheduler picks its tile from the average packed query length and its split from the per-request KV lengths, so probing a set of shapes says nothing about the shapes that were not probed.

This consumes FlashInfer's workspace_size_upper_bound() instead, which takes plan-level bounds and returns sizes no plan inside them can exceed.

AI assistance: Codex, Claude

What this changes

Every causal prefill and decode wrapper this reservation materializes is asked what no plan of its can exceed, with the shape bounds the scheduler config implies and the split settings the plans will use. The shared arena is then held at the largest float bound, and each wrapper gets the int workspace its own bound allows.

A wrapper is built against a minimal arena so that a bound still has room to settle it below the default; the arena is sized once afterwards and every registered wrapper is rebound onto it. Nothing after that can grow it.

One wrapper that cannot be bounded takes the whole arena back to the default: a backend without the helper, a helper that refuses or raises, a result that is malformed, negative, or not a pair of integers. The arena is shared and grow-only, so a bound covering only part of it would leave the rest to grow after the lock. The wrappers are materialized either way, so the fallback only has to size the arena.

An answer is taken only when it is a pair of non-negative int. A float or a string is refused rather than coerced: reading (1.9, 8) as (1, 8) would turn a wrong answer into a plausible one and size the arena too small with nothing to say so.

Two configurations reach a wrapper this does not reserve. A cascade wrapper is built on the first batch with a common prefix, and a mm-prefix model has a second prefill wrapper for its mask; both ask for the default arena when they are built, so a smaller one would be grown by them after the lock. In either configuration the bound is not applied and the default arena is kept, so the saving described above does not apply to them. That question is asked after the wrappers exist, so standing down costs the bound and nothing else.

Test Plan

Static checks:

  • py_compile on the 2 changed Python files

  • ruff check

  • ruff format --check

  • git diff --check

  • pre-commit run mypy-3.10
  • Focused test:

    python -m pytest \
      tests/v1/worker/test_cudagraph_memory_profiling.py \
      tests/v1/worker/test_gpu_worker.py -q
    

    Test Result

    Static checks passed. The focused CPU run is 94 passed, 0 failed, 2 skipped; the 2 skips are the GPU tests, which pass separately as 2 passed on one SM80 device against the FlashInfer branch that carries the bound.

    The CPU cases cover a bound that shrinks both the arena and each wrapper's int workspace, the query carrying plan-level bounds only, the whole batched-token budget reaching the query rather than one request's length, the output dtype the bound is asked about including NVFP4 KV, a fixed split and a disabled split each reaching the query on their own, ten fallback paths (helper missing, unsupported backend, helper raising, negative, malformed, float, string, bool, prefill bounded but decode not, float bounded but int unusable), cascade and mm-prefix each standing down -- with both wrappers still materialized, both bounds still asked for and discarded, and both int workspaces kept -- while an ordinary model still applies the bound, a bound per CUDA graph decode wrapper, arena size and pointer stability across the lock, and no query at all when no native route is enabled.

    The GPU tests drive the real wrappers and the real WorkspaceManager through reserve, rebind, lock and several real plans, and check that a bounded arena and both int workspaces are unmoved afterwards. On a mm-prefix configuration, run against the branch that adds that wrapper, the arena is the default 413138944 bytes before the lock and the same size and address after the wrapper is built and planned twice.

    Notes

    Removing this change leaves the profiling lifecycle it sits on unchanged: it touches two files, no worker or contract file, and the tests of the branch below it pass unmodified with it reverted.

    This change is stacked on the persistent-workspace lifecycle branch, and it needs the workspace_size_upper_bound() API added by FlashInfer upstream PR 5236. Against a FlashInfer without that API every wrapper reports no bound, so the default arena is kept and nothing here takes effect.

    The late-created wrapper's int workspace is 8 MiB and stays outside this reservation. In the compatibility probe, allocator usage rose by 8,519,680 bytes when that wrapper was created and by a further 2,560 bytes on its first plan; both are reported as observed allocations, not as memory this reserves or recovers.

    Not run here: serving, and therefore the real KV capacity this recovers.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

  • Bug Fixes

  • - Improved FlashInfer workspace memory sizing using workload-specific limits, reducing unnecessary memory reservation.
    - Added safer fallback behavior when workspace requirements cannot be determined.
    - Improved reliability for CUDA graph capture and memory profiling across prefill, decode, cascade, and multimodal-prefix workloads.
    - Ensured attention wrappers remain stable after workspace reservation and continue functioning across supported execution paths.
  • Tests

  • - Added comprehensive coverage for workspace limits, data types, batching, CUDA graphs, and real GPU execution scenarios.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: lesj0610 Review duration: 10385m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    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
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #130"
    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: 57% (MEDIUM) · Higher = larger blast radius
    57%
    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: 22.5% · Safe to merge
    22.5%
    Repository