Skip to content

[dist] refactor: inject the async-offload host buffer pool - #1175

Merged
Coach257 merged 3 commits into
mainfrom
szl.async-offload-host-buffer-pool
Sep 10, 2026
Merged

Coach257 merged 3 commits into
mainfrom
szl.async-offload-host-buffer-pool

Conversation

@Coach257

@Coach257 Coach257 commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Split out of #1090: OffloadManager no longer owns its PinnedBufferPool. The manager stays per offload schedule (block_idx is “position within this schedule”), while the host pool is process-wide and keyed only by tensor layout, so a composed model can apply offload per module without multiplying activation_offload_host_cache_limit_gb by the module count.

Single-model callers keep passing host_cache_limit_bytes and are unchanged. A caller that applies offload more than once (omni per-module, DPO reference, …) passes one shared host_buffer_pool.

Checklist Before Starting

  • Search for relative PRs/issues and link here: split from #1090; builds on #965
  • PR title follows [{modules}] {type}: {description} format (enforced by check_pr_title.yml)
    • Allowed modules: agent, ci, ckpt, config, data, dist, docker, docs, logging, lora, misc, model, omni, optim, ops, parallel, perf, release, task, trainer
    • Allowed types: feat, fix, refactor, chore, test
    • Breaking changes: prepend [BREAKING] — e.g. [BREAKING][parallel, model] feat: dynamic batching

Test

Extended the existing CI-enumerated file tests/distributed/test_async_offload_unit.py (gpu_unit_tests.yml already lists it). Added cases for: a shared pool reused across two apply_async_activation_offload calls, building a pool from host_cache_limit_bytes, rejecting a non-pool OffloadManager argument, and rejecting limit+pool together.

CPU path: pytest tests/distributed/test_async_offload_unit.py -k "not accelerator_gradient_parity and not fsdp2_gc" — 27 passed, 2 skipped (device tests). The GPU integration tests in that file are unchanged and still run in GPU CI.

API and Usage Example

Single-model (unchanged):

apply_async_activation_offload(
    model,
    activation_offload_modules=["model.layers.*"],
    host_cache_limit_bytes=4 * 1024**3,
)

Several schedules sharing one host budget:

pool = PinnedBufferPool(max_cached_bytes=4 * 1024**3)
apply_async_activation_offload(thinker, ["layers.*"], host_buffer_pool=pool)
apply_async_activation_offload(talker, ["layers.*"], host_buffer_pool=pool)
# reset each root separately
reset_async_activation_offload(thinker)
reset_async_activation_offload(talker)

host_cache_limit_bytes and host_buffer_pool are mutually exclusive. YAML activation_offload_host_cache_limit_gb is still the process-wide idle-cache cap; only the help text clarifies that.

Design & Code Changes

  • OffloadManager now takes a PinnedBufferPool instead of creating one from a byte limit.
  • async_offload_modules(..., *, host_buffer_pool=...) is keyword-only for the pool.
  • apply_async_activation_offload builds a pool when given a limit, or uses a caller-supplied pool. Passing both raises ValueError.
  • Docs / OffloadConfig help: the GB limit is counted once per process, not per offloaded module.
  • reset_async_activation_offload still walks one root; a multi-root caller must reset each root.

Checklist Before Submitting

  • Read the Contribute Guide
  • Applied pre-commit checks
  • Added/updated documentation
  • If tasks/ training scripts were moved or renamed: updated docs/ examples and verified python3 scripts/ci/check_doc_task_paths.py passes (also enforced by the Check doc task paths CI workflow)
  • Tests: extended an existing CI-enumerated test (tests/distributed/test_async_offload_unit.py, already listed in gpu_unit_tests.yml).

Summary by CodeRabbit

  • New Features

    • Async activation offload supports caller-supplied shared pinned host-buffer pools for reuse across repeated module applications.
    • A default host-buffer cache limit is used when no custom pool or limit is provided.
    • Pool and cache-limit settings are validated to prevent incompatible combinations.
    • Reset operations preserve shared pools while clearing temporary scheduling state.
  • Documentation

    • Clarified per-call pool limits, shared-pool behavior, and cache eviction rules.

Coach257 and others added 2 commits September 10, 2026 11:46
OffloadManager owned its PinnedBufferPool, which tied a process-wide
memory budget to a per-schedule object. A manager has to stay per
schedule -- block_idx means "position within this schedule", so two sets
numbering from 0 would prefetch and wait on each other's tensors -- but
the pool does not: its buffers are keyed by layout alone and are fungible
across schedules.

Injecting the pool lets a composed model apply offload per module without
multiplying activation_offload_host_cache_limit_gb by the module count.
Single-model callers keep passing host_cache_limit_bytes and are
unaffected.

Also folds in the f-string conversions the pyupgrade hook applies to this
file.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Coach257
Coach257 requested a review from FoolPlayer September 10, 2026 04:19
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: eb0d2173-c117-44d4-b347-4f3b32eea41a

📥 Commits

Reviewing files that changed from the base of the PR and between 0213149 and 227afc9.

📒 Files selected for processing (4)
  • docs/usage/arguments.md
  • tests/distributed/test_async_offload_unit.py
  • veomni/arguments/arguments_types.py
  • veomni/distributed/async_offload.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/distributed/test_async_offload_unit.py
  • veomni/arguments/arguments_types.py
  • veomni/distributed/async_offload.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Async activation offload now supports shared PinnedBufferPool instances. Entry points resolve or inject one pool, managers retain it across schedules, and tests and documentation cover the updated API and cache semantics.

Changes

Activation offload pool lifecycle

Layer / File(s) Summary
Pool contract and manager ownership
veomni/distributed/async_offload.py
PinnedBufferPool uses a shared 4 GiB default. OffloadManager requires a validated pool and preserves it when clearing schedule state.
Offload entry-point pool wiring
veomni/distributed/async_offload.py
async_offload_modules accepts a keyword-only pool. apply_async_activation_offload resolves injected, limit-based, or default pools and rejects conflicting arguments.
Validation and configuration documentation
tests/distributed/test_async_offload_unit.py, veomni/arguments/arguments_types.py, docs/usage/arguments.md, docs/requirements.txt
Tests cover pool reuse and invalid configurations. Documentation describes per-pool cache limits and pooled buffer eviction.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant apply_async_activation_offload
  participant PinnedBufferPool
  participant async_offload_modules
  participant OffloadManager
  Caller->>apply_async_activation_offload: configure offload
  apply_async_activation_offload->>PinnedBufferPool: resolve or create shared pool
  apply_async_activation_offload->>async_offload_modules: pass resolved pool
  async_offload_modules->>OffloadManager: construct manager with pool
  OffloadManager->>PinnedBufferPool: reuse pool for offload schedules
Loading

Merge Risk: ⚪ Minimal · up to 227af

Activation offload can now use an injected shared pinned-buffer pool or construct an independent pool per call, with conflicting options rejected and cache limits applied at the pool level. The documented behavior is covered by unit tests, and no current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: injecting the async-offload host buffer pool.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch szl.async-offload-host-buffer-pool

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Coach257

Copy link
Copy Markdown
Collaborator Author

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: eb0d2173-c117-44d4-b347-4f3b32eea41a

📥 Commits
Reviewing files that changed from the base of the PR and between 0213149 and 227afc9.

📒 Files selected for processing (4)

  • docs/usage/arguments.md
  • tests/distributed/test_async_offload_unit.py
  • veomni/arguments/arguments_types.py
  • veomni/distributed/async_offload.py
 ___________________________
< Clippy has nothing on me. >
 ---------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 1d02a0ac-06a4-4006-8cc3-b3c13bbff986

📥 Commits
Reviewing files that changed from the base of the PR and between 97a6e07 and 0213149.

📒 Files selected for processing (5)

  • docs/requirements.txt
  • docs/usage/arguments.md
  • tests/distributed/test_async_offload_unit.py
  • veomni/arguments/arguments_types.py
  • veomni/distributed/async_offload.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Walkthrough

Async activation offload now supports shared PinnedBufferPool instances. Entry points resolve or inject one pool, managers retain it across schedules, and tests and documentation cover the updated API and cache semantics.

Changes

Activation offload pool lifecycle

Layer / File(s) Summary
Pool contract and manager ownership
veomni/distributed/async_offload.py PinnedBufferPool uses a shared 4 GiB default. OffloadManager requires a validated pool and preserves it when clearing schedule state.
Offload entry-point pool wiring
veomni/distributed/async_offload.py async_offload_modules accepts a keyword-only pool. apply_async_activation_offload resolves injected, limit-based, or default pools and rejects conflicting arguments.
Validation and configuration documentation
tests/distributed/test_async_offload_unit.py, veomni/arguments/arguments_types.py, docs/usage/arguments.md, docs/requirements.txt Tests cover pool reuse and invalid configurations. Documentation describes process-wide idle-cache limits and pooled buffer eviction.
Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant apply_async_activation_offload
  participant PinnedBufferPool
  participant async_offload_modules
  participant OffloadManager
  Caller->>apply_async_activation_offload: configure offload
  apply_async_activation_offload->>PinnedBufferPool: resolve or create shared pool
  apply_async_activation_offload->>async_offload_modules: pass resolved pool
  async_offload_modules->>OffloadManager: construct manager with pool
  OffloadManager->>PinnedBufferPool: reuse pool for offload schedules
Loading

Loading
Suggested reviewers: yllllllllllll, foolplayer

Merge Risk: 🟡 Moderate · up to 02131

Separate activation-offload applications using only the cache-limit setting may retain more pinned host memory than the documented process-wide budget, risking unexpected host-memory pressure. Resolve the default-pool ownership semantics or correct the documented contract before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: refactoring async offload to inject a shared host buffer pool.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation

Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI

✨ Finishing Touches
📝 Generate docstrings

  • Create stacked PR
  • Commit on current branch

🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Commit unit tests in branch szl.async-offload-host-buffer-pool

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CodeRabbit
docs updated

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Your plan includes PR reviews subject to rate limits. Reviews are available now.

@Coach257
Coach257 merged commit 427b971 into main Sep 10, 2026
22 checks passed
@Coach257
Coach257 deleted the szl.async-offload-host-buffer-pool branch September 10, 2026 07:24
LionG1001 pushed a commit to arcing-mt/VeOmni that referenced this pull request Sep 22, 2026
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