Repository navigation
fix(train): remove the local-mode code dir with the root-aware _rmtree - #6427
Open
AkshayShah03 wants to merge 1 commit into
Open
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
In Mode.LOCAL_CONTAINER, ModelTrainer copies the SDK drivers (and source code) into a TemporaryDirectory under local_container_root and mounts it into the training container. The container runs as root and writes files there (e.g. common/__pycache__), so the TemporaryDirectory.cleanup() after training failed with PermissionError: Operation not permitted. _LocalContainer already removes its own directories with _rmtree, which falls back to chmod-ing the tree from a short-lived container; use it for the code dir as well before the regular cleanup. Fixes aws#5542
AkshayShah03
requested a deployment
to
manual-approval
October 10, 2026 15:29 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 10, 2026 15:29 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 10, 2026 15:29 — with
GitHub Actions
Waiting
This branch is waiting to be deployed
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.
Issue #, if available: Fixes #5542
Description of changes:
In
Mode.LOCAL_CONTAINER,ModelTrainercopies the SDK drivers and the source code into aTemporaryDirectoryunderlocal_container_root(self._temp_code_dir) and mounts it into the training container. The container runs as root and writes into that directory, for examplecommon/__pycache__. The plainself._temp_code_dir.cleanup()after training then fails.This is the traceback the reporter posted on 3.21.
dj_thcjiis the temporary directory's random name:The 3.21 fix made
_LocalContainerremove its own directories (input,shared, the host dirs) through_rmtree. On aPermissionError,_rmtreechmods the tree from a short-lived container and retries. The code directory owned byModelTrainerwasn't covered.This change removes the code directory with the same
_rmtree(path, image, is_studio)after local training, before the regularTemporaryDirectory.cleanup(). That cleanup and__del__are then no-ops on the already-removed path; I checked this on Python 3.10–3.13.Testing:
test_local_container_train_removes_temp_code_dir_with_root_owned_files. It checks that_rmtreegets the code directory and the container's image and Studio flag. It fails before this change.sagemaker-train/tests/unit/train: no new failures. Master and this branch have the same 5 failures, which need AWS credentials or depend on test order.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.