Repository navigation
Conversation
matrix72c
marked this pull request as ready for review
November 9, 2026 09:46
matrix72c
force-pushed
the
fix/pooled-pinned-storage
branch
from
November 23, 2026 03:54
bd23f5d to
df94de9
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CPU checks complete; CUDA/FSDP multi-rank and performance validation remain outstanding.
Root Cause
Allocating one pinned host tensor per optimizer moment or offloaded model tensor amplifies host allocator rounding. Pooling these destinations exposes two additional contracts: FSDP owns padded backing storage (which can be stale after HF leaf materialization), and PyTorch 2.10 DTensor wrappers with nonzero local offsets cannot be serialized normally even though their ordinary local views are valid.
Fix
This is one logical PR, combining the shared storage implementation and its consumers rather than stacking allocator/Adam/model PRs.
torch.savededuplicates shared storages; DCP compacts individual views. Rawtorch.saveof a single view still writes its entire slab unless the caller explicitly clones it.self.state, step path, and in-place loader helpers. Do not restore the old parameter/group or CPU-state maps. Checkpoint dictionaries are copied before wrapping offset DTensors so runtime state identity remains unchanged.Module._apply, preserving move/FSDP hooks and fallback behavior for unsupported layouts/subclasses. Refresh FSDP sharded backing before planning, including HF-load-before-first-forward cases, and allocate the full padded backing rather than just a visible shard.keep_vars=Truebehavior.No HF-loader closure-lifetime fix, dependency changes, production pins, topic lists, integration history, or unrelated refactors are included.
Code Reference
d841a3feeba4565054ad773fce5335a4734def88fix/pooled-pinned-storagebd23f5d27d6a51f550bf8cfd4ebed8485c3e14e0a9e9c9ac,3a03d9a0, and4f3ad4fe; their historical merge chains were not cherry-picked.Test Plan — Completed
Environment: existing
sandbox-rl-dev, Python 3.12.12 at/opt/venv/bin/python, Torch 2.10.0, Ray 2.56.1, Transformers 5.17.0, FLA 0.5.2, LMDeploy 0.18.0. The actual XTuner import was verified as/workspace/.tools/worktrees/pr-pooled-20261109/xtuner/__init__.py. No environment installation or persistent PYTHONPATH change was made. Ray 2.56.1 differs from main's all-extra Ray 2.58.0 requirement; these tests do not initialize Ray and do not establish full environment compatibility.All CPU invocations used the following call-local settings:
sudo -n -u jc -g docker docker exec \ -e PYTHONPATH=/workspace/.tools/worktrees/pr-pooled-20261109 \ -e OMP_NUM_THREADS=1 -e MKL_NUM_THREADS=1 -e OPENBLAS_NUM_THREADS=1 \ -w /workspace/.tools/worktrees/pr-pooled-20261109 sandbox-rl-dev \ /opt/venv/bin/python -m pytest -ra \ -o cache_dir=/tmp/xtuner-unit-test/pr-pooled-20261109/pytest-cache \ --junitxml=/workspace/.tools/pr-pooled-20261109-cpu-final.xml \ tests/utils/test_pinned_memory.py \ tests/utils/test_dtensor.py \ tests/optim/test_swap_adamw_storage.py::TestPinnedSlabPlan \ tests/optim/test_swap_adamw_storage.py::TestSwapAdamWStorageCPU \ tests/model/test_pinned_model_offload.py::TestModelOffloadCPUtests/files are outside the pre-commit filter: explicitpython -m ruff checkandpython -m ruff format --checkpassed for all four changed test files.432 source files) and pydantic-extra-check. Non-applicable YAML/requirements/Markdown hooks skipped. The cached mypy hook uses Torch 2.6.0 stubs, not the runtime Torch 2.10.0 environment.git diff --check d841a3fepassed; final topic worktree is clean.Full-hook failure disclosure
pre-commit run --all-fileswas executed and returned exit 1. It exposed:autotest/files. These automatic edits were inspected and reverted to the clean topic commit; they are not included in this PR._make_wrapper_subclass); documented and narrowly annotated withtype: ignore[attr-defined]. Runtime checkpoint tests exercise the builtin directly.The final relevant-file hook run passes, but this is not a claim that the full repository hook baseline is clean. No unrelated formatting or dependency repair was folded into the PR.
Outstanding Validation
TestSwapAdamWStorageGPUandTestModelOffloadGPU, including real pinning, nondefault streams/event lifetime, uneven/empty FSDP shards, HF loading before first offload, and PrecisionPolicy CPU↔CUDA/checkpoint/HF-export behavior: not run.tests/engine/test_swap_adamw_engine_resume.pyGPU/DCP resume tests: not run; require target GPU resources and model assets. The file remains upstream's implementation, not replaced with an older copy.Target CUDA/multi-rank checkpoint/continued-training checks and representative performance measurements remain outstanding.