Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytorch_lightning/plugins/training_type/deepspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def model_sharded_context(self) -> Generator[None, None, None]:
else:
model_parallel_context = super().model_sharded_context()

with model_parallel_context:
with torch.cuda.amp.autocast(), model_parallel_context:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for ZeRO 2/3, autocast isn't used as we rely on a custom DeepSpeed FP16Optimizer to handle this, which converts the entire model to half iirc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With newer DeepSpeed version, they check the weights are created in half precision and currently fails in CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh very interesting! i'll check myself when I get time, do they throw an error if the weights are in half precision or not in half precision?

yield

def _set_deepspeed_activation_checkpointing(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/test_deepspeed_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class ModelParallelBoringModel(BoringModel):

def __init__(self):
super().__init__()
self.linear = None
self.layer = None

def configure_sharded_model(self) -> None:
self.linear = torch.nn.Linear(32, 2)
self.layer = torch.nn.Linear(32, 2)

def on_load_checkpoint(self, checkpoint: Dict[str, Any]) -> None:
self.configure_sharded_model()
Expand Down