[RFC] Single-Device-Abstract DDP
@leonardo0lyj đang làm issue này rồi.
Từ ngày 30/8/2024.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Single-Device-Abstract DDP
Motivation
In current PyTorch DDP, when training a model with Dropout operations, the final results obtained from distributed training will not be consistent with those obtained from single-machine training. This is mainly because the RNG state offset is copied across DP workers, and the Dropout mask calculation results are the same for all DP workers. In contrast, on a single device, the Dropout mask results for sequentially input micro-batches do not share this dependency, leading to a misalignment between DP dropout operations and single-machine computation results. We resolve the issue in veScale via deep understanding of how GPUs generate random numbers parallelly and torch cuda random generation implementation patch.
We have validated the prototype on several open-source models, including Llama2, Llama3, GPT2, and Mixtual, and it successfully ensures that the loss curve remains consistent with single-device training when DP is enabled.
We welcome any and all feedback on this effort!
Design
To ensure consistency in random number generation between distributed and single-machine scenarios, veScale proposed the ThreadBasedRNGTracer, which regulates the thread ID used during CUDA random number generation. This ensures that the thread ID used are identical in both single-machine and parallel scenarios. However, the existing Random Op processing only considers thread ID adjustments in Tensor Parallel scenarios and overlooks the consistency issues in random number generation caused by Data Parallelism.
Following veScale's former approach to handling TP Random operations, we can inject additional DP-related information into the torch CUDA RNG state. During the CUDA random generation process, this DP information can be retrieved from the RNG state, enabling the generation of correct local random results.
For example, consider a scenario with 4 GPUs and a parallel setup of DP=2 and TP=2. In this case, veScale manually adjusts the thread ID on each GPU based on the corresponding parallel configuration to ensure consistency with the single-machine state.
RNGTracker API
To ensure the correct generation of single-device-abstracted random numbers when DP is enabled, users need to wrap the random number generation code with the _distribute_region context manager. The DTensorSpec provided to this context manager includes information related to TP, while the dp_size and dp_rank parameters specify the DP-related information.
import vescale.dtensor.random as random
with random._rng_tracker._distribute_region(DTensorSpec, dp_size, dp_rank):
# here to process random gen ops
Compared with the current master branch, the _distribute_region input now includes dp_size and dp_rank. When these two values are not provided, dp_size defaults to 1 and dp_rank defaults to 0, meaning that the DP-based random number generation adjustment is not enabled by default.
cc @leonardo0lyj @MackZackA @JsBlueCat
- Ngôn ngữ chính
- Python
- Star
- 1k
- Fork
- 65
- Merge trung bình
- 21 giờ 34 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc 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 volcengine/veScale
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 12/100
volcengine/veScale#75 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
volcengine/veScale#73 · 1 bình luận · 3 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
volcengine/veScale#72 · 5 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
volcengine/veScale#68 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
volcengine/veScale#65 ·
Tất cả issue của volcengine/veScale
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
docling-project/docling-pipelines#669 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked kind/enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
opendatahub-io/agent-eval-harness#329 · 2 bình luận · 1 reaction ·
-
cc_wrapper crashes with ValueError on Windows when a path is on another driveCó thể đã có người làm @TrapsterDK đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
tweag/rules_haskell#2492 ·
Maintainer thường phản hồi trong vòng 1 ngày