[New] [Offload] [1/2] Disambiguate synchronous __setitem__/offload from update_offload - #768
[New] [Offload] [1/2] Disambiguate synchronous __setitem__/offload from update_offload#768kylesayrs wants to merge 5 commits into
__setitem__/offload from update_offload#768Conversation
d94df2d to
1509629
Compare
📝 WalkthroughWalkthroughThis PR changes offload update paths to validate stored tensors explicitly, delete existing cache entries before replacement, and handle missing disk-index entries by skipping updates. Tests were updated for local, GPU, and distributed update flows. ChangesOffload update behavior
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
This pull request has merge conflicts that must be resolved before it can be |
1509629 to
f05c0c9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_offload/test_interface.py`:
- Around line 98-111: The assertion in test_update_offload_parameter_only is
using value inequality on tensors, which can succeed for the wrong reason if
both tensors contain the same value. Update the checks around
offloaded_linear.weight and the local offload variable to assert they are
distinct by identity or by comparing device/state, using the existing test
helpers disable_offloading and disable_onloading to verify the onloaded and
offloaded tensors are not the same object.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 219c97bf-7825-4727-9f61-43365bbb801e
📒 Files selected for processing (5)
src/compressed_tensors/offload/__init__.pysrc/compressed_tensors/offload/cache/base.pytests/test_offload/cache/test_disk.pytests/test_offload/test_interface.pytests/test_offload/test_module.py
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
vllm-project/llm-compressor(manual)
| @pytest.mark.unit | ||
| @requires_gpu | ||
| def test_update_offload_parameter_only(offloaded_linear: torch.nn.Linear): | ||
| offloaded_linear.weight = torch.nn.Parameter(torch.tensor(0.0)) | ||
|
|
||
| with disable_offloading(): | ||
| _ = offloaded_linear.weight | ||
| update_offload_parameter(offloaded_linear, "weight", torch.tensor(1)) | ||
|
|
||
| # updating offload does not update onload | ||
| with disable_onloading(): | ||
| offload = offloaded_linear.weight | ||
| assert offload == 1 | ||
| assert offloaded_linear.weight != offload |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 1. Check device constants in test_interface.py
rg -n 'ONLOAD_DEVICE|OFFLOAD_DEVICE' tests/test_offload/test_interface.py | head -10
# 2. Check CPUCache.update_offload implementation
ast-grep outline src/compressed_tensors/offload/cache/cpu.py --match update_offload --view expanded
# 3. If outline doesn't show the body, read the method directly
rg -n -A 15 'def update_offload' src/compressed_tensors/offload/cache/cpu.pyRepository: vllm-project/compressed-tensors
Length of output: 1085
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== tests/test_offload/test_interface.py =="
sed -n '1,180p' tests/test_offload/test_interface.py
echo
echo "== src/compressed_tensors/offload/cache/cpu.py =="
sed -n '1,220p' src/compressed_tensors/offload/cache/cpu.py
echo
echo "== src/compressed_tensors/offload/interface.py =="
sed -n '1,260p' src/compressed_tensors/offload/interface.pyRepository: vllm-project/compressed-tensors
Length of output: 7714
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -A 80 'def update_offload_parameter|keep_onloaded_values|disable_offloading|disable_onloading' src/compressed_tensors/offload tests/test_offloadRepository: vllm-project/compressed-tensors
Length of output: 50390
Use identity or device comparison here
!= compares tensor values, so this can pass/fail for the wrong reason once both tensors contain 1. Use is not (or compare .device) to assert the onloaded and offloaded tensors are distinct.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_offload/test_interface.py` around lines 98 - 111, The assertion in
test_update_offload_parameter_only is using value inequality on tensors, which
can succeed for the wrong reason if both tensors contain the same value. Update
the checks around offloaded_linear.weight and the local offload variable to
assert they are distinct by identity or by comparing device/state, using the
existing test helpers disable_offloading and disable_onloading to verify the
onloaded and offloaded tensors are not the same object.
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
f9e5240 to
0e8f1e0
Compare
1d6a264 to
205d730
Compare
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews
🔴 Require one maintainer reviewWaiting for any of
This rule is failing.All PRs must have at least one approving review from a maintainer before merging.
|
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Background
The ability to update offloaded values is something that can be done asynchronously across ranks.
The ability to create new offloaded values is something that must be done synchronously across ranks.
Currently on main, we do both through the same interface:
This is bad because it's very unclear to users when parameters are being updated vs created, which has serious implications for rank synchronization. It's better to make it very explicit: assignment is synchronous, while
update_offload_parameteris always asynchronous.Summary
update_offload_parameterto callupdate_offloadexplicitlyonloading_disabledcontiguousbefore writing to disk, as required bysafetensorstorch.no_graddecorator forupdate_offload_parameteroffload_folderfixture for easy testingtest_distributed_compression_with_disk_offloadfor better coverageTesting