[REQUEST] Index group offsets once when materializing lazy ZeRO-3 checkpoint tensors
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- data, performance
Hướng nghiên cứu
Start with deepspeed/utils/zero_to_fp32.py, especially GatheredTensor.contiguous, and read the boundary behavior around flat_groups_offset. Add focused coverage for duplicate offsets, exact group ends, empty parameters, and spans across groups; compare reconstructed tensors and aliases with the baseline in lazy and eager conversion paths. The work is done when correctness is preserved and realistic subgroup benchmarks show the lookup cost improvement.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem and affected use case
GatheredTensor.contiguous() linearly scans flat_groups_offset inside its rank loop. Every parameter repeats that same search for every rank, although all ranks use the same offsets. For checkpoints with many ZeRO-3 optimizer subgroups, lookup work is O(parameters × ranks × groups), in addition to the necessary tensor copies.
This proposes locating the parameter's group interval once per materialization with binary search (or precomputing it while assembling the lazy state dict). It preserves lazy/mmap loading and does not introduce workers, a new checkpoint format or a new conversion backend.
Evidence
Source: master b9100c541ac1b8e25148bc8000d1ad45c4c095db, deepspeed/utils/zero_to_fp32.py, GatheredTensor.contiguous.
Apple M5 CPU, 16 GB RAM, macOS arm64, Python 3.11.18, torch 2.15.0, one torch CPU thread, no GPU. Five samples, alternating order, generated ZeRO-3 checkpoint files with eight ranks. Timed the conversion's actual load/mmap, reconstruction and torch.save function bodies; checkpoint creation and output verification were outside timing. DeepSpeed package imports/CLI were excluded to avoid accelerator initialization on this host; conversion I/O and tensor operations were not mocked. These are synthetic checkpoints, not a distributed training run. Filesystem caches were warm.
| Groups | Parameters | Elements per rank/parameter | Baseline median | Indexed prototype median |
|---|---|---|---|---|
| 1 | 512 | 1024 | 33.67 ms | 33.66 ms |
| 256 | 2048 | 128 | 316.69 ms | 96.11 ms |
| 1024 | 4096 | 1024 | 2032.47 ms | 258.35 ms |
For the 1024-group fixture (~138 MB of input checkpoint files), sample ranges were 2008–2191 ms versus 256–272 ms. All reconstructed tensors matched bit-for-bit. Checks also preserved a tied-parameter alias, an int64 buffer above 2**24, per-parameter padding removal, and independently calculated values for first/middle/last parameters. The one-group control showed effectively no benefit. No production-model speedup or peak-RSS reduction is claimed.
Rough design
For nonempty partitions, calculate:
start_group_id = bisect_right(flat_groups_offset, offset) - 1
end_group_id = bisect_left(flat_groups_offset, offset + partitioned_numel) - 1
Do this outside the rank loop; keep the existing tensor slicing and concatenation. An alternative is recording the group interval at construction while offsets advance monotonically. Binary search is simpler for independently materialized lazy tensors and requires no new persistent state.
Boundary tests are essential: leading/interior duplicate offsets, exact group-end offsets, zero-sized parameters, and spans across multiple groups. The prototype only establishes the performance opportunity for nonempty parameters contained in groups; it is not a ready implementation of all these edge cases. Do not change cross-group or empty-parameter semantics as an incidental optimization.
Compatibility, tradeoffs and acceptance criteria
The target is the offline ZeRO-3 trainable-parameter reconstruction path. ZeRO-1/2 use _zero2_merge_trainable_params; frozen parameters use a separate merge; those paths do not use this search. No training convergence or collective communication behavior should change.
Before code submission:
- Run the public conversion API on real ZeRO-3 checkpoints with multiple subgroup sizes and compare every output tensor, dtype, shape and tied-weight behavior with baseline; exercise lazy and eager modes and sharded export.
- Add boundary-focused unit coverage and retain frozen/nonfloating-buffer and ZeRO-1/2 controls.
- Benchmark realistic subgroup layouts, large tensor copies and low-group controls, report wall time and peak RSS. Disk-bound exports may see little benefit.
- Validate through the package's normal import path; my local extraction bypassed it. No NVIDIA accelerator/driver, distributed training, CPU-offload training or GPU convergence was tested.
Related work and project fit
I reviewed #6658 (the current lazy/mmap converter), #6526 and open #6655 (parallel conversion through universal checkpoints). #6655 rewrites conversion through the universal checkpoint path; it does not index GatheredTensor's group lookup. This is a focused improvement to the existing serial/lazy path and can coexist with that proposal. Open/closed searches for GatheredTensor, zero_to_fp32, bisect, group/conversion terms, and the local commit history did not identify this change. It does not broaden the Q4 roadmap's checkpoint architecture work (#8672).
I am opening a proposal for maintainer feedback before a code PR. AI assistance was used for investigation and experiments. The repository's human review/DCO requirements still apply to any subsequent code submission.
Standalone baseline scaling reproduction
import time, statistics
import numpy as np
import torch
from deepspeed.utils.zero_to_fp32 import GatheredTensor
torch.set_num_threads(1)
for groups in (1, 128, 1024):
ranks, parameters, part = 8, 1024, 32
width = (parameters // groups) * part
flat = [[torch.arange(width, dtype=torch.float32)
for _ in range(groups)] for _ in range(ranks)]
offsets = [0] + list(np.cumsum([x.numel() for x in flat[0]]))
tensors = [GatheredTensor(flat, offsets, i * part, part,
torch.Size([part * ranks]))
for i in range(parameters)]
samples = []
for _ in range(5):
start = time.perf_counter()
for tensor in tensors:
tensor.contiguous()
samples.append(time.perf_counter() - start)
print(groups, statistics.median(samples))
# Baseline local medians: 8.76 ms, 70.85 ms, 546.14 ms.
# Same slicing/cat with one bisect interval lookup: 7.29, 7.89, 10.19 ms.
- Ngôn ngữ chính
- Python
- Star
- 43.3k
- Fork
- 5.1k
- Merge trung bình
- 5 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 85
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của deepspeedai/DeepSpeed
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()Có thể đã có người làm @its-amann đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
deepspeedai/DeepSpeed#9190 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exceptionCó thể đã có người làm @bantianyue đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#9183 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
deepspeedai/DeepSpeed#9019 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped foreverCó thể đã có người làm @damienen đã nhận 26 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
deepspeedai/DeepSpeed#8982 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] OneCycle applies the minimum momentum to the first Adam updateCó thể đã có người làm @ai-yang đã nhận 30 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#8951 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của deepspeedai/DeepSpeed
Issue tương tự
-
area/auth comp/agent P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#161417 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Dao-AILab/flash-attention#3251 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[New Check]: sqlserver_public_network_access_disabledCó thể đã có người làm @pouria-l đã nhận hôm nay. Đang mởfeature-request status/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prowler-cloud/prowler#13607 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
external langchain
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
langchain-ai/docs#8184 ·
Maintainer thường phản hồi trong vòng 1 ngày