DeepSpeed
101d83e2 - Fix pin-memory offload-route test after ZeRO-1/2 optim-state relink (#9148)

Commit
9 hours ago
Fix pin-memory offload-route test after ZeRO-1/2 optim-state relink (#9148) 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. --------- Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Author
Parents
Loading