← Back to Pull requests

Support Transformers 5.20 cache query offsets in DeepSpeedStaticCache #8852

Closed
unknown closed this pull request without merging on Nov 05, 2026 02:01 UTC
View on GitHub
unknown unknown commented on Oct 18, 2026 01:31 UTC
Author

Background

Native Llama continuous rollout on Transformers 5.20.1 failed because DeepSpeedStaticCache lacked get_query_offset(layer_idx). The query offset must exclude the current write; using get_seq_length() would be off by one.

Changes

Implemented and validated on fix/static-cache-query-offset:

  • Added layer and cache query-offset methods: zero when unset, the scalar write position otherwise, or the maximum per-row position with row validity handled by attention masks.

  • Preserved cache-length and KV-write behavior without capture-time host synchronization.

  • Added independent masking and CUDA replay regressions, plus native Llama generation comparisons covering eager / SDPA attention, padding, slot refill, and graph reuse.
  • Validation

    RTX A4500 (20 GiB), PyTorch 2.9.1+cu128 / CUDA 12.8, FP16:

    | Transformers | Results |
    | --- | --- |
    | 5.20.1 | 76 passed, 1 skipped |
    | 4.57.6 | 73 passed, 4 skipped |

    Actual CUDA capture/replay passed. Randomly initialized tiny Llama rollouts matched native generate() tokens, attention masks, and response offsets. Both versions skipped the optional pretrained-model test; 4.57.6 also skipped three tests requiring the newer masking API. Modified-file pre-commit checks passed.

    Run in each Transformers environment:

    python -m pytest \
        tests/unit/utils/test_static_cache.py \
        tests/unit/runtime/rollout/test_hybrid_engine_rollout.py \
        tests/unit/runtime/rollout/test_continuous_batching.py \
        tests/unit/v1/test_hybrid_engine_rollout_v1.py -q
    

    Scope and dependencies

    Depends on the cache code from deepspeedai/DeepSpeed#8732, not the benchmark. Changes are limited to compatibility, tests, and documentation; this does not claim full Transformers 5.20 cache API support. Issue 1 depends on this fix in the tested 5.20.1 environment.

    CC @delock

    Diff: 237 lines (+177 / -60) across 2 files Reviewer: delock Review duration: 25949m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 237 lines diff across 2 files
    0.37
    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%
    56%
    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.327
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8852"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 37.2% (MEDIUM) · Higher = larger blast radius
    37.2%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 16.1% · Safe to merge
    16.1%