Forward free_data through partition() instead of hardcoding True - #8305
Forward free_data through partition() instead of hardcoding True#8305vineethsaivs wants to merge 2 commits into
Conversation
PR deepspeedai#6694 added a free_data flag so the ZeRO-3 leaf-module fast-sharding path could partition a parameter without calling free_param() on it, and release the buffer itself once the whole submodule was done. The flag was added to all three signatures, but the two intermediate call sites pass the literal True rather than the value they received, so free_data=False never reaches the check that uses it: param.partition(free_data=False) -> free_param(param) runs anyway That makes the "if free_data" guard in _partition_param() unreachable as False, and the fast path in PartitionedParameterCoordinator.release_sub_module() a no-op: it computes free_data from fast_sharding_for_leaf_module, passes it down, and the buffer is freed regardless, so the empty_buffer assignment that follows just overwrites an already-freed tensor. Pass free_data down at both hops. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b22deacfa
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if param_list is None: | ||
| param_list = [cls] | ||
| self._partition(param_list, has_been_updated=has_been_updated, free_data=True) | ||
| self._partition(param_list, has_been_updated=has_been_updated, free_data=free_data) |
There was a problem hiding this comment.
Add the missing sign-off trailer
This is a non-merge commit, but its commit message has no Signed-off-by: trailer. The repository requires every non-merge commit to be signed off, so compliance checks can reject this until the commit is recreated with git commit --signoff using the configured name and email.
AGENTS.md reference: AGENTS.md:L8-L8
Useful? React with 👍 / 👎.
|
This one is a false positive: the commit does carry the trailer. The DCO check on this PR passes, which is the same thing measured independently. No change needed. |
Problem
#6694 added a
free_dataflag so the ZeRO-3 leaf-module fast-sharding path could partition a parameter without callingfree_param()on it, and then release the buffer itself after the whole submodule was done (param.data = empty_buffer), avoiding a per-parameter synchronisation.The flag was added to all three signatures, but the two intermediate hops pass the literal
Trueinstead of the value they were given:So
free_data=Falsenever reaches the only place that reads it:Consequences:
if free_data:guard is unreachable asFalse;free_param()always runs.PartitionedParameterCoordinator.release_sub_module()computesfree_data = not z3_leaf_module(submodule) or not self.fast_sharding_for_leaf_moduleand threads it through__release_param()->param.partition(free_data=free_data), but the buffer is freed anyway. The fast path enabled bystage3_module_granularity_threshold > 0is a no-op, and theparam.data = empty_bufferthat follows just overwrites an already-freed tensor.Reproducible directly on the parameter API (single process, CPU):
Fix
Pass
free_datadown at both hops. Two lines; no signature or default changes, so the default path (free_data=True) is byte-for-byte the same as before.Test
Added
TestPartitionWithoutFreeingDatatotests/unit/runtime/zero/test_zero_context.py(world_size=1), next to the existingTestZeroGatheredParametersFree. It gathers a parameter, callspartition(free_data=False)and assertsparam.datasurvives, then gathers again and calls plainpartition()to assert the default still frees.Whole-file and feature-path controls, clean tree vs patched:
The one failure is the same on both sides,
test_zero_nesting_init.py::TestNestedParallelInit::test_nested_parallel_init, and is unrelated to this change.yapf --style .style.yapf -dis clean on both files.flake8 --config .flake8reports the same two pre-existingF824 global reuse_bufferswarnings before and after; nothing new.