Stop the training subprocess on every exit path#81
Open
jfrieli wants to merge 1 commit into
Open
Conversation
Move the executor cleanup in TrainerLogic._train from the `except TrainingError` block into a `finally`, so the training subprocess is terminated on every exit path - in particular abort(), where a CancelledError previously propagated past the cleanup and orphaned the executor process (leaving it holding the GPU). Add test_abort_during_training_kills_executor asserting the subprocess is no longer running after abort(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@denniswittich @NiklasNeugebauer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Aborting a training cancels the trainer task, but for executor-based trainers (e.g. classification, yolov5) the
python train.pysubprocess was left running — still holding the GPU. TheCancelledErrorfromabort()propagated past_train's only cleanup (except TrainingError), so nothing terminated the executor. This was surfaced by the loop's newabort_trainingflow (zauberzeug/loop#346 + #80): once a node is on 0.20.0 and extends the executor-basedTrainerLogic, abort orphans the process.Implementation
TrainerLogic._trainout of theexcept TrainingErrorblock into afinally, so the training subprocess is terminated on every exit path (normal return,TrainingError,CancelledError/abort, and any unexpected exception)asyncio.shield(self.executor.stop_and_wait())so the terminate+wait completes even while the task is being cancelledtest_abort_during_training_kills_executor: starts a real training subprocess, aborts mid-run, assertsexecutor.is_running()becomesFalse(no orphan)Notes / risks
stop()(graceful) andabort()remain distinct:finallyonly guarantees the subprocess is dead; whether_trainreturns normally (→ upload) or withCancelledError(→ReadyForCleanup, discard) is unchanged. Covered by the existingtest_stop_during_training_uploads_model/test_abort_during_training.TrainingErrorpath is behavior-preserving (executor still killed,previous_statestill reset) — only the internal ordering changed.⬛ claude-opus-4-8[1m]