Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle PermissionError in os.chmod Call - Update engine.py #4139

Merged
merged 10 commits into from
Aug 14, 2023

Conversation

M-Chris
Copy link
Contributor

@M-Chris M-Chris commented Aug 11, 2023

This Pull Request introduces a try-except block around the os.chmod call used to change file permissions in the DeepSpeed engine. The change ensures that a PermissionError (or any other unexpected exception) does not halt the program's execution but instead logs a warning message.

This is particularly relevant when working with read-only filesystems or shared storage where permission modification might not be allowed.

The new exception handling allows for greater robustness in various environments without compromising the overall functionality of the system. A detailed warning message has been added to inform the user of any issues encountered during the chmod operation, aiding in debugging and future refinement of the code.

This branch includes changes to handle potential exceptions that may occur when attempting to change file permissions using the os.chmod function within the DeepSpeed engine. The specific issue addressed is the PermissionError that may arise when working with certain filesystems or under restricted permissions.
@M-Chris M-Chris changed the title Update engine.py Handle PermissionError in os.chmod Call - Update engine.py Aug 11, 2023
@tjruwase
Copy link
Contributor

@M-Chris, thanks for this PR. Is it possible to create a unit test?

@M-Chris
Copy link
Contributor Author

M-Chris commented Aug 12, 2023

@tjruwase Yea sure ill add one into the PR do you have any preference to location? maybe unit/runtime/utils ?

@tjruwase
Copy link
Contributor

How about tests/unit/checkpoint/test_zero_optimizer.py?

@M-Chris M-Chris requested a review from mrwyattii as a code owner August 12, 2023 06:36
@M-Chris
Copy link
Contributor Author

M-Chris commented Aug 12, 2023

@microsoft-github-policy-service agree

@tjruwase Added the unit test, built it as a ZeRO Non Distributed since its not needed for the test. Maybe allows some expansion for other things to be applied in there.

Also split the original patch into its own method to allow the unit test, since non permissible file/folders only exist in certain circumstances (Azure Storage File Share, etc.), none of which are in Github Actions.

🍻

# make executable (safeguard for file shares - Azure as example)
try:
os.chmod(dst, os.stat(dst).st_mode | stat.S_IEXEC)
except Exception as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth making this specific to except PermissionsError as e?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can and initially I did.. then I thought maybe there's some other circumstance that could arise so it's a catch all.
Up to you guys, I'm happy to make the change.

  • looks like the formatter needs me to fix a typo and doesn't want the trailing white space on the file so an update is needed either way

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer more specific exceptions. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool done & done

@loadams loadams enabled auto-merge August 14, 2023 17:24
@loadams loadams disabled auto-merge August 14, 2023 17:53
This is presented for use-cases like Azure Storage File Share (where permissions are not allowed)
We use a fake file for this test (file not existing would present a similar issue as not being able to chmod)
"""
fake_recovery_script_dst = os.path.join("tmp", "zero_to_fp32.py")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess for the test we'd need to add FileNotFoundError in order for this test to pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup caught it and pushed already - you were faster than my comment 😄

@M-Chris
Copy link
Contributor Author

M-Chris commented Aug 14, 2023

@loadams Added (FileNotFoundError, PermissionError) I should have thought about that.. since the unit test requires a not found, since there's no way to validate file shares in Github Actions to my knowledge.

@loadams
Copy link
Collaborator

loadams commented Aug 14, 2023

@loadams Added (FileNotFoundError, PermissionError) I should have thought about that.. since the unit test requires a not found due, since there's no way to validate file shares in Github Actions to my knowledge.

I agree, I'm not aware of any way to do that, so catching both makes sense.

@loadams loadams enabled auto-merge August 14, 2023 18:04
@loadams loadams added this pull request to the merge queue Aug 14, 2023
Merged via the queue into deepspeedai:master with commit 629b203 Aug 14, 2023
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.

3 participants