Skip to content

[Fix] Avoid waiting for failed training batch cleanup - #2282

Open
matrix72c wants to merge 1 commit into
InternLM:mainfrom
matrix72c:fix/failed-batch-cleanup-upstream
Open

matrix72c wants to merge 1 commit into
InternLM:mainfrom
matrix72c:fix/failed-batch-cleanup-upstream

Conversation

@matrix72c

@matrix72c matrix72c commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

ProduceBatchResult impact: no fields, reward accounting, rollout statuses or producer counters are changed. This affects trainer failure unwinding after batch installation, not batch production; the primary failure is no longer delayed by queued cleanup on a blocked worker.
RoutedExperts impact: trainer/trace ownership remains unchanged. Controller-local batch object refs are cleared on every exit; pending workers may retain their installed batch until they can process release or are torn down. This is best-effort cleanup, not a claim of immediate remote release. Trace-owned routed-experts refs must not be freed by generic batch cleanup; LMDeploy→XTuner transfer is unchanged.
Ray concurrency impact: actor groups/dispatch remain unchanged. A synchronous worker blocked in a collective cannot execute its queued release RPC; failure cleanup now polls completed release refs without waiting. Successful cleanup still waits. This does not make a blocked actor recoverable or introduce a new concurrent control lane.

Root Cause

_loaded_batch always waited for every release_train_batch RPC, even while propagating a training/load failure. If a peer was blocked in a collective, its release RPC stayed queued and the controller waited for the long training timeout instead of surfacing the original exception.

Fix

Keep awaited cleanup on successful exit. On failure, submit best-effort releases independently, log submission errors, poll with ray.wait(..., timeout=0), and inspect only ready individual results with a zero timeout. Preserve the primary error and clear local batch refs on every path. Cover load submission/result failures, body failures, cleanup submission/result/wait failures, successful cleanup and trace-owned routed refs.

Independent branch: fix/failed-batch-cleanup-upstream, commit 4ab838dde6032b1a881f0398aa7236287986f942, based directly on d841a3feeba4565054ad773fce5335a4734def88; no dependency on another new topic.

Test Plan

Verified in sandbox-rl-dev: Python 3.12.12, Torch 2.10.0+cu128, Ray 2.56.1, Transformers 5.17.0, FLA 0.5.2. Existing LMDeploy /opt/src/lmdeploy remains at 3f99ed1502ce3f7cf9747afc2138ff624e5d5457; candidate source is selected by per-command PYTHONPATH only.

  • PASS: tests/rl/test_train_batch_contract.py::{TestFailedBatchCleanup,TestBatchLifecycle}: 18 passed, 0 skipped, exit 0.
  • The real-Ray test_real_ray_blocked_synchronous_peer executed and passed, not skipped (JUnit duration 12.966s). It started its own local two-CPU runtime, blocked one synchronous actor, raised the primary error on its peer and confirmed cleanup used only zero-timeout polling. Finally it killed only its own actors and called ray.shutdown() for its own runtime; no global ray stop was used.
  • PASS: explicit Ruff check and format check on both changed files.
  • Required pre-commit run --all-files executed: exit 1 from existing formatting/import-order/docformatter problems in seven autotest/ files. Hook-only edits were restored. Full mypy passed on 430 source files; other applicable hooks passed. Full hooks/CI are not green.
  • Not run: Ray 2.58.0 (declared by latest main's all extra), GPU/NCCL collective failures, cluster-scale actor failures or training throughput. The real Ray test uses a local blocking method, not a hung NCCL collective.
  • A throughput benchmark is unnecessary for this failure-unwinding change: the successful wait path is preserved, and the regression proves no blocking cleanup get is issued after failure. No cluster latency improvement is quantified.

Reproduction (container):

PYTHONPATH=/workspace/.tools/worktrees/pr-failed-cleanup-20261109:/opt/src/lmdeploy \
  bash /workspace/.tools/xtuner-regression-20261105.sh \
  /workspace/.tools/worktrees/pr-failed-cleanup-20261109 \
  tests/rl/test_train_batch_contract.py::TestFailedBatchCleanup \
  tests/rl/test_train_batch_contract.py::TestBatchLifecycle -v

Outstanding verification is listed above.

@matrix72c
matrix72c marked this pull request as ready for review November 9, 2026 09:46
@matrix72c
matrix72c force-pushed the fix/failed-batch-cleanup-upstream branch from 4ab838d to 9a917a7 Compare November 23, 2026 03:56

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant