← Back to Pull requests

Fix pin-memory offload-route test after ZeRO-1/2 optim-state relink #9148

Closed
unknown closed this pull request without merging on Nov 23, 2026 08:57 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 10:21 UTC
Author

Fixes #9140 (nightly regression, modal-torch-latest full suite at 7681845b3).

Root cause

PR #9016 (40a9f40b3) added a _relink_hp_params_optimizer_state() call to the end of DeepSpeedZeroOptimizer.reload_states(), which now runs whenever any of hp params / lp params / optim states is offloaded. tests/unit/v1/pin_memory/test_offload_route.py::test_reload_states_holds_pin_buffers_until_sync borrowed the real reload_states for a minimal fake optimizer that only stubbed _link_all_hp_params, so reloading hp params raised:

AttributeError: '_FakeZeroOptimizer' object has no attribute '_relink_hp_params_optimizer_state'

and the nightly full suite failed on this file.

Change

Test-only. Instead of adding another private-method stub to the fake (which would break again on the next internal refactor of reload_states), the test now exercises the contract on a real engine through the public API:

  • _FakeZeroOptimizer is removed; the test is now TestReloadStatesHoldsPinBuffers(DistributedTest) (world size 1) on a SimpleModel with ZeRO-2 and a client torch.optim.Adam (no FusedAdam JIT dependency).

  • With DS_PIN_MEMORY_BACKEND=native, engine.offload_states(include=[hp_params], pin_memory=True) creates pinned host buffers registered with the native pin manager.

  • engine.reload_states(non_blocking=True) is run while recording, at each accelerator.synchronize(), that those buffers are still registered; after the call and gc.collect() the ranges must be released.

  • Skips when the native pin manager is unavailable or the accelerator is CPU.
  • The pinned-buffer hold-until-sync contract under test is unchanged.

    Validation (on-device)

  • Original fix-up (fake + stub), 8x NVIDIA H20, torch 2.9.1+cu129: unpatched nightly commit -> 1 failed (the AttributeError above), 5 passed; patched -> 6 passed, tests/unit/v1/pin_memory/ 50 passed, 1 skipped.

  • Real-engine rewrite, NVIDIA L20 (1 GPU used):

  • - -k TestReloadStatesHoldsPinBuffers -> 1 passed.
    - Negative check: with pending_host_buffers.append(self.hp_params_pin_buffers) removed from reload_states, the test fails as expected.
    - Note: the L20 GPUs are in Exclusive_Process compute mode, so running the whole file there makes this DistributedTest subprocess hit "device busy" after the module-level tests have initialized CUDA in the pytest parent; the other 5 tests pass. This is a local-environment limitation, not related to the change (CI uses default compute mode).
  • pre-commit clean on the modified file.
  • AI assistance: GitHub Copilot was used to diagnose the regression and prepare the change; the change was reviewed line-by-line and re-validated on device as above.

    Diff: 338 lines (+253 / -85) across 4 files Reviewer: jinyouzhi Review duration: 1356m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 338 lines diff across 4 files
    0.42
    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.349
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9148"
    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: 42.2% (MEDIUM) · Higher = larger blast radius
    42.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: 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: 16.7% · Safe to merge
    16.7%