-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 5 commits
48be006
9cdf107
4ba4047
9c115fe
c242778
220ebef
f199f3c
492d9ae
3b43a94
4a6716e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# DeepSpeed Team | ||
|
||
import deepspeed | ||
from types import SimpleNamespace | ||
from deepspeed.ops.op_builder import CPUAdamBuilder | ||
from deepspeed.checkpoint.utils import clone_tensors_for_torch_save, get_model_ckpt_name_for_rank | ||
from deepspeed.accelerator import get_accelerator | ||
|
@@ -576,3 +577,33 @@ def test_save_tensor_clone(self, tmpdir, zero_stage, use_cpu_device): | |
torch.save(clone_state_dict, clone_ckpt_file) | ||
|
||
compare_state_dicts(torch.load(ref_ckpt_file), torch.load(clone_ckpt_file)) | ||
|
||
|
||
class TestZeRONonDistributed(DistributedTest): | ||
world_size = 1 | ||
init_distributed = False | ||
|
||
def test_chmod_exception_handling(self, monkeypatch): | ||
|
||
config_dict = {"train_batch_size": 1, "zero_optimization": {"stage": 0}} | ||
tjruwase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args = SimpleNamespace(local_rank=0) | ||
net = SimpleModel(hidden_dim=4) | ||
engine, _, _, _ = deepspeed.initialize(args=args, | ||
config=config_dict, | ||
model=net, | ||
model_parameters=net.parameters()) | ||
|
||
log_called = False | ||
def mock_logger_info(message, *args, **kwargs): | ||
nonlocal log_called | ||
log_called = True | ||
|
||
monkeypatch.setattr("deepspeed.utils.logger.info", mock_logger_info) | ||
""" | ||
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 simliar issue as not being able to chmod) | ||
""" | ||
fake_recovery_script_dst = os.path.join("tmp", "zero_to_fp32.py") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup caught it and pushed already - you were faster than my comment 😄 |
||
engine._change_recovery_script_permissions(fake_recovery_script_dst) | ||
|
||
assert log_called, "Expected deepspeed.utils.logger.info to be called." |
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@M-Chris, this should help with formatting: https://github.com/microsoft/DeepSpeed/blob/master/CONTRIBUTING.md#contributing
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool done & done