Skip to content

Share DeepNVMe pinned-tensor manager and route swap buffers through I/O handles - #8212

Open
sfc-gh-truwase wants to merge 2 commits into
masterfrom
tjruwase/deepnvme-shared-pin-manager
Open

Share DeepNVMe pinned-tensor manager and route swap buffers through I/O handles#8212
sfc-gh-truwase wants to merge 2 commits into
masterfrom
tjruwase/deepnvme-shared-pin-manager

Conversation

@sfc-gh-truwase

Copy link
Copy Markdown
Collaborator

Summary

DeepNVMe skips the bounce-buffer copy only when a buffer is torch-pinned or managed by the handle's pinned-tensor manager. That manager was per-handle and recognized only exact base pointers, so buffers allocated by one handle — or narrows/views of a shared pool submitted through a different read/write handle — were not recognized and always bounced.

This PR makes the pinned-tensor manager a process-wide shared instance with range-based recognition, and switches the swap subsystem to obtain pinned memory and query pinned status through its I/O handles.

Changes

  • C++
    • deepspeed_pin_tensor_t is now a process-wide shared() singleton guarded by a std::mutex; is_managed is range-based so slices/views of a locked buffer are recognized.
    • deepspeed_io_handle_t and cpu_op_desc_t hold the manager via std::shared_ptr.
    • Added handle.is_pinned(buffer) with bindings in py_ds_aio.cpp and py_ds_gds.cpp (GDS inherits the base).
  • Python (swap subsystem only)
    • SwapBufferManager/SwapBufferPool and the optimizer swappers take an aio_handle; buffers are allocated via new_cpu_locked_tensor and pinned status is queried via handle.is_pinned.
    • Optimizer-swapper subclasses create their handle before super().__init__ so it can be threaded through.
  • Test: tests/unit/v1/nvme/test_pinned_manager.py covers narrow/view recognition and cross-handle sharing.

Test plan

  • pre-commit (yapf/flake8/clang-format/check-license) on all touched files.
  • tests/unit/v1/nvme/test_pinned_manager.py — 3/3 pass (narrow recognition, cross-handle sharing, unmanaged buffer).
  • tests/unit/v1/nvme/ + tests/unit/utils/test_pin_memory.py + tests/unit/v1/accelerator/test_accelerator.py — 146 pass.
  • Swap smoke test (tests/unit/runtime/zero/test_nvme_checkpointing.py): reproduces the pre-existing baseline exactly (no regression; the failing optimizer-on-NVMe configs fail identically on master).

Made with Cursor

…/O handles

DeepNVMe skips the bounce-buffer copy only when a buffer is torch-pinned or
managed by the handle's pinned-tensor manager. That manager was per-handle and
recognized only exact base pointers, so buffers allocated by one handle (or
narrows/views of a shared pool submitted through a different read/write handle)
were not recognized and always bounced.

- C++: make deepspeed_pin_tensor_t a process-wide shared() singleton guarded by
  a mutex, and make is_managed range-based so slices/views of a locked buffer
  are recognized. Switch deepspeed_io_handle_t and cpu_op_desc_t to hold the
  manager via shared_ptr, and add handle.is_pinned() with aio/gds bindings.
- Python: the swap subsystem now obtains pinned host memory via
  new_cpu_locked_tensor and queries pinned status via handle.is_pinned instead
  of the accelerator. SwapBufferManager/SwapBufferPool and the optimizer
  swappers take an aio_handle; optimizer-swapper subclasses create the handle
  before super().__init__ so it can be threaded through.
- Add a focused nvme test for narrow recognition and cross-handle sharing.

Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd2d494965

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread deepspeed/runtime/swap_tensor/partitioned_param_swapper.py
Comment thread deepspeed/runtime/swap_tensor/utils.py
- handle.is_pinned() now returns is_pinned() || is_managed(), mirroring
  cpu_op_desc_t's direct-I/O eligibility check. Reporting only is_managed()
  misclassified torch-pinned destinations (e.g. ZeRO-3 fp16 flat CPU memory) as
  unpinned, needlessly forcing the swap-buffer path and risking pool exhaustion.
- SwapBufferManager now releases its page-locked buffers via
  free_cpu_locked_tensor() on destruction. With the process-wide pinned-tensor
  manager, dropping a manager no longer reclaims its buffers, so repeatedly
  building NVMe swappers would otherwise accumulate locked memory.

Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@sfc-gh-truwase
sfc-gh-truwase requested review from delock and removed request for loadams and tohtana August 4, 2026 21:32
const char* ptr = (char*)buffer.data_ptr();
for (const auto& iter : _locked_tensors) {
const char* base = (char*)iter.first;
if (base <= ptr && ptr < base + iter.second) { return true; }

@delock delock Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check whether the end of buffer is smaller than iter.second? This could be stronger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants