Fix ZeRO++ secondary shard copy for small params - #8210
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb6daa6efc
ℹ️ 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".
| # make sure param.ds_secondary_tensor requires_grad always be false | ||
| param.ds_secondary_tensor.narrow(0, 0, | ||
| sec_numel).copy_(one_dim_param.narrow(0, secondary_start, sec_numel)) | ||
| if sec_numel > 0: |
There was a problem hiding this comment.
Zero-fill skipped secondary shards
In HPZ runs with zero_quantized_weights enabled, partitioned_param_coordinator.py:580 passes quantize=True and _all_gather_coalesced quantizes a torch.cat of every ds_secondary_tensor (partition_parameters.py:1406-1409). When sec_numel == 0, this branch skips the only write into the newly allocated torch.empty secondary tensor, so a small no-overlap parameter can feed arbitrary padding values into the shared quantization group for neighboring parameters instead of deterministic zeros. Please initialize the skipped shard before it can be gathered or quantized.
Useful? React with 👍 / 👎.
|
This looks like a solid, focused change. |
Signed-off-by: zengyong <2595650269@qq.com>
a19fb4d to
45d5422
Compare
Summary
This PR fixes a ZeRO++ edge case where
_partition_param_sec()can calltorch.narrow()with an out-of-range start index when a very small parameter does not overlap with the computed secondary shard.When
secondary_start > param.ds_numel,sec_numelbecomes0, but the old code still attempted to execute:PyTorch raises
IndexErrorfor this case even whensec_numel == 0.The fix is to skip the secondary copy when
sec_numel == 0. This preserves the existing behavior for overlapping shards and avoids the invalid emptynarrow()call for non-overlapping shards.This PR also adds a focused regression test covering the small-parameter, no-overlap secondary shard case.
Testing
python3 -m pytest -q tests/unit/runtime/zero/test_zeropp.py -k 'test_zero_hpz_partition_size_config or test_zero_hpz_small_param_secondary_shard_without_overlap'Observed locally:
2 passed