Skip to content

modify data split to use HF api - #65

Merged
tianyu-l merged 2 commits into
gh/tianyu-l/1/basefrom
gh/tianyu-l/1/head
Feb 21, 2024
Merged

tianyu-l merged 2 commits into
gh/tianyu-l/1/basefrom
gh/tianyu-l/1/head

Conversation

@tianyu-l

@tianyu-l tianyu-l commented Feb 17, 2024 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Just found out that HF dataset has its own API to do data split (across DP ranks). Verified that it has the expected data behavior (same on SP ranks, different on DP ranks).

Note: This is still a map-style dataset, that has to be loaded in memory. Setting streaming=True for load_dataset returns an IterableDataset whose data doesn't have to fit in memory, but the data loading speed is significantly slower.

tianyu-l added a commit that referenced this pull request Feb 17, 2024
ghstack-source-id: 489d666
Pull Request resolved: #65
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 17, 2024

@wanchaol wanchaol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Just found out that HF dataset has its own [API](https://huggingface.co/docs/datasets/v2.17.0/en/package_reference/main_classes#datasets.distributed.split_dataset_by_node) to do data split (across DP ranks). Verified that it has the expected data behavior (same on SP ranks, different on DP ranks).

Note: This is still a map-style dataset, that has to be loaded in memory. Setting `streaming=True` for [load_dataset](https://huggingface.co/docs/datasets/v2.17.0/en/package_reference/loading_methods#datasets.load_dataset) returns an IterableDataset whose data doesn't have to fit in memory, but the data loading speed is significantly slower.


[ghstack-poisoned]
tianyu-l added a commit that referenced this pull request Feb 21, 2024
ghstack-source-id: e23d5e0
Pull Request resolved: #65
@tianyu-l
tianyu-l merged commit 5ebe2e7 into gh/tianyu-l/1/base Feb 21, 2024
tianyu-l added a commit that referenced this pull request Feb 21, 2024
ghstack-source-id: e23d5e0
Pull Request resolved: #65
@tianyu-l
tianyu-l deleted the gh/tianyu-l/1/head branch February 21, 2024 20:08
lessw2020 pushed a commit that referenced this pull request Apr 18, 2024
ghstack-source-id: e23d5e0
Pull Request resolved: #65
philippguevorguian pushed a commit to YerevaNN/YNNtitan that referenced this pull request Aug 17, 2024
ghstack-source-id: e23d5e0
Pull Request resolved: pytorch#65
payoto pushed a commit to graphcore-research/torchtitan-fork that referenced this pull request Feb 7, 2025
Adding FP8 version, removing multinode one.
weifengpy added a commit to weifengpy/torchtitan-flexshard that referenced this pull request Oct 9, 2026
The flex_shard backend rejected CUDA graphs (training.disable_cuda_graphs=False,
the recipes' default). Like FSDP2, FlexShard needs nothing capture-specific:
its training step is self-contained, finishing within the step everything it
starts (prefetches, all-gathers, reduce-scatters, finalization). The trainer's
wrapper can then run its eager warmup steps, capture the forward-backward once
and replay it. meta-pytorch/flex_shard#66 tests FlexShard under that capture
pattern; FlexShard needs no code change for it beyond pytorch#65.

This lifts the rejection and updates the README.

Tests:
- test_flex_shard.py: test_matches_fsdp2_with_cuda_graphs trains the DeepSeek
  V3 debug model through the trainer's wrapper (wrap_fwd_bwd_with_cuda_graph):
  two eager warmup steps, the captured step and two replays, with the chunked
  loss, 1 and 2 microbatches, and reshard after forward "default" and "never".
  Losses, grad norms, gradients and parameters are bitwise equal to FSDP2's
  with CUDA graphs. EP 1: with EP > 1, torchtitan supports CUDA graphs only
  with HybridEP, which CI doesn't install. _train now runs each step's
  microbatches in one forward-backward function, as the trainer does.
- test_config_validation.py: flex_shard accepts CUDA graphs; the rejection test
  uses CPU offload instead.

Gates (8 H100s, 10 steps, scripts/loss_compare.py --assert-equal on loss and
grad_norm, CUDA graphs on for both backends, FlexShard pytorch#65):
- DeepSeek V3 debug model, EP 1: equal at every step; both runs recorded a
  CUDA graph.
- The same with PP 2 Interleaved1F1B: equal; both runs recorded a CUDA graph.
- DeepSeek V3 16B, the README comparison's settings except EP 1 and CUDA
  graphs on: equal at every step.
  - Throughput, median over steps 4-10 (the replays): 11,248 tokens/s per GPU
    for FSDP2, 11,286 for FlexShard.
  - Step 7 on rank 0, a replay: GPU time 1,429.6 vs 1,402.5 ms; exposed
    communication 52.4 vs 44.3 ms (all-gathers 20.3 vs 14.0, reduce-scatters
    20.1 vs 18.9, all-reduces 12.0 vs 11.4). A collective is exposed while its
    NCCL kernels run and no compute kernel does.
  - Peak reserved memory 58.86 vs 59.24 GiB. Peak active memory 49.42 vs
    51.17 GiB, reached in the eager warmup steps; FlexShard is 1.75 GiB higher
    from step 1, with or without CUDA graphs. The cause: FlexShard kept two
    reduce-scatters pending by default, so a second 2,231 MiB packed input of
    a MoE block was alive at the backward peak. meta-pytorch/flex_shard#67
    makes the default one, as in FSDP2. With it, peak active memory is 49.42
    vs 49.42 GiB and peak reserved 58.86 vs 57.80 GiB, at 11,174 vs 11,397
    tokens/s per GPU and 41.8 vs 41.3 ms of exposed communication.
- DeepSeek V3 debug model, EP 4 with HybridEP (non_blocking_capacity_factor
  1.0; DeepEP's hybrid-ep branch at 10d4dd7), with and without PP 2
  Interleaved1F1B: equal; both runs recorded a CUDA graph. This covers
  FlexShard's explicit prefetch schedule under EP.
- DeepSeek V3 16B, EP 4 with HybridEP, 2 x 4,096 tokens per GPU (4 x 4,096
  ran out of memory on FSDP2: HybridEP sizes its buffers for the worst-case
  routing), FlexShard with pytorch#67: equal at every step.
  - Throughput, median over steps 4-10: 9,154 vs 9,344 tokens/s per GPU.
  - Step 7 on rank 0: GPU time 866.0 vs 852.5 ms; exposed communication
    32.9 vs 32.3 ms.
  - Peak active memory 57.46 vs 57.59 GiB; peak reserved 65.56 vs 66.36 GiB.

ghstack-source-id: c7887f3
ghstack-comment-id: 6075195472
Pull-Request: #18
weifengpy added a commit to weifengpy/torchtitan-flexshard that referenced this pull request Oct 20, 2026
The flex_shard PRs this fork uses have landed on meta-pytorch/flex_shard
main: pytorch#51 through pytorch#77, ending at 7cdaf16 (pytorch#48 to pytorch#62 were re-landed as pytorch#96
to pytorch#103). The DeepSeek V3 16B reproduction now installs FlexShard from main
instead of gh/weifengpy/55/head, the head of pytorch#65, which lacks pytorch#66 to pytorch#77:
torchtitan-flexshard#20's fake backend for a size-1 edp_shard needs pytorch#71, and
this fork's DistMuon (#22 to #27) needs pytorch#73 to pytorch#77.

Checked: pip resolves git+https://github.com/meta-pytorch/flex_shard.git@main,
and the fork's main (fa7a9b1) passes its 18 FlexShard and 9 DistMuon GPU
tests (tests/unit_tests/gpu/test_flex_shard.py,
tests/unit_tests/gpu/flex_shard/test_dist_muon.py) against flex_shard 7cdaf16.

ghstack-source-id: 09ed3f5
ghstack-comment-id: 6284173360
Pull-Request: #43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants