Skip to content

Count examples in structured DataAnalyzer batches - #8505

Open
vineethsaivs wants to merge 2 commits into
deepspeedai:masterfrom
vineethsaivs:fix-data-analyzer-batch-count
Open

vineethsaivs wants to merge 2 commits into
deepspeedai:masterfrom
vineethsaivs:fix-data-analyzer-batch-count

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

DataAnalyzer writes incorrect sample IDs after the first dictionary or tuple batch, corrupting the metric-to-sample mapping used by curriculum learning.

Cause: len(data) counts batch fields instead of examples.
Fix: Advance by the fixed batch sampler size, capped by the remaining samples.
Test: Four regressions fail before; all six pass afterward through real run_map output files. Covers tensor/dict/tuple batches, two worker partitions, a partial batch and remapped IDs. Related data-efficiency tests: 20 passed, 2 skipped. Apple M2 Pro CPU, torch 2.11.0. Changed-file pre-commit passes; distributed training was not run.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The equivalent DistributedDataAnalyzer path retains the same structured-batch corruption bug.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes incorrect sample-ID advancement for structured DataAnalyzer batches.

Changes:

  • Advances offsets using sampler batch size, capped for partial batches.
  • Adds tensor, dictionary, tuple, partition, and remapping regressions.
File Description
data_analyzer.py Corrects file-backed analyzer offsets.
test_data_efficiency.py Adds output-based regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +185 to +186
# The batch sampler counts examples; len(data) can count dict keys or tuple fields.
processed_sample += min(self.batch_size, total_sample - processed_sample)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same bug, fixed in 72bb53e with the same step and a single-process test for DistributedDataAnalyzer.run_map_helper.

banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Oct 9, 2026
…peedai#8758)

`DataAnalyzer.run_map` fills the process list in the order of
`threads_to_run` but starts and joins with `p[thread]`, so
`specific_threads` only works when it is `[0, 1, ..., k]`. Anything
else, like `[2, 3]` to rerun two failed threads, raises `IndexError:
list index out of range`.

Fix: start the process that was just appended (`p[-1]`) and join over
`p` directly. Two lines.

Test: `test_data_analyzer_runs_only_the_specific_threads` runs `run_map`
with `num_threads=4, specific_threads=[2, 3]` and checks that only
`worker0_thread2` and `worker0_thread3` are written, holding samples 10
to 14 and 15 to 19. It fails on master with the IndexError and passes
with the fix. `pytest tests/unit/runtime/test_data_efficiency.py`: 15
passed, 2 skipped (the two-GPU curriculum tests). Run on an M-series
Mac, CPU only, torch 2.14.0. pre-commit passes on both changed files.

This doesn't touch the `len(data)` sample counting in the same file,
which deepspeedai#8505 already covers.

Fixes deepspeedai#8757

Signed-off-by: rakshit-gen <sisodiarakshit456@gmail.com>
Co-authored-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
run_map_helper advanced batch_start_idx by len(data), which counts dict
keys or tuple fields. Advance by the sampler batch size instead, capped
at the thread end, like the file-backed analyzer.

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
@vineethsaivs
vineethsaivs force-pushed the fix-data-analyzer-batch-count branch from 72bb53e to d4e63c8 Compare November 29, 2026 08:08
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants