Skip to content

fix(pipeline): drain eval pipeline naturally to prevent batch leak - #314

Merged
shijieliu merged 1 commit into
NVIDIA:mainfrom
JacoCheung:junzhang/fix-eval-pipeline-drain
Mar 2, 2026
Merged

shijieliu merged 1 commit into
NVIDIA:mainfrom
JacoCheung:junzhang/fix-eval-pipeline-drain

Conversation

@JacoCheung

@JacoCheung JacoCheung commented Mar 2, 2026 •

Copy link
Copy Markdown
Collaborator

The prefetch pipeline (PrefetchTrainPipelineSparseDist) keeps 2 batches in its internal queue (_batch_i, _batch_ip1). When eval uses a truncated iterator (max_eval_iters < len(eval_loader)), the pipeline never drains, leaving stale eval batches that contaminate the first training iterations after eval.

Fix: limit the eval iterator to exactly max_eval_iters via islice and switch the eval loop to StopIteration-driven (while/try), so the pipeline exhausts its iterator and drains its batch queue naturally.

Also remove the now-unnecessary flush_pipeline() method from all pipeline classes.

Description

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

…tch contamination

The prefetch pipeline (PrefetchTrainPipelineSparseDist) keeps 2 batches
in its internal queue (_batch_i, _batch_ip1). When eval uses a truncated
iterator (max_eval_iters < len(eval_loader)), the pipeline never drains,
leaving stale eval batches that contaminate the first training iterations
after eval.

Fix: limit the eval iterator to exactly max_eval_iters via islice and
switch the eval loop to StopIteration-driven (while/try), so the
pipeline exhausts its iterator and drains its batch queue naturally.

Also remove the now-unnecessary flush_pipeline() method from all
pipeline classes.
@JacoCheung
JacoCheung requested a review from shijieliu March 2, 2026 09:19
@shijieliu
shijieliu merged commit a96b5d2 into NVIDIA:main Mar 2, 2026
@JacoCheung JacoCheung changed the title fix(pipeline): drain eval pipeline naturally to prevent train/eval ba… fix(pipeline): drain eval pipeline naturally to prevent batch leak Mar 2, 2026
@greptile-apps

greptile-apps Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixed a subtle but critical pipeline contamination bug where truncated eval iterations (max_eval_iters < len(eval_loader)) left stale eval batches in the prefetch pipeline's internal queue, causing them to leak into subsequent training iterations.

The fix has two key changes:

  • Changed islice(eval_loader, len(eval_loader)) to islice(eval_loader, max_eval_iters) to limit the iterator to exactly the desired number of eval iterations
  • Replaced the counted for i in range(max_eval_iters) loop with a StopIteration-driven while/try/except pattern that ensures the iterator is fully exhausted

This allows the pipeline to drain its internal batch queue (_batch_i, _batch_ip1) naturally via its _execute_all_batches mechanism, preventing contamination. The new eval loop structure now matches the training loop pattern for consistency.

Confidence Score: 5/5

  • This PR is safe to merge - it fixes a real contamination bug with a clean, well-documented solution
  • The fix correctly addresses the root cause by limiting the eval iterator to exactly max_eval_iters and using a StopIteration-driven loop that ensures the pipeline exhausts its iterator and drains its internal batch queue naturally. The approach matches the existing training loop pattern and includes clear explanatory comments. No edge cases or regressions were identified.
  • No files require special attention

Important Files Changed

Filename Overview
examples/hstu/training/trainer/training.py Fixed pipeline contamination bug by using islice(max_eval_iters) and StopIteration-driven loop to ensure pipeline drains naturally after eval

Last reviewed commit: cbb7e21

@greptile-apps greptile-apps Bot 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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants