Skip to content

Commit

Permalink
add _deepspeed_no_cast attribute (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyschoelkopf authored Mar 8, 2024
1 parent 02e2ebf commit 6d097be
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions deepspeed/runtime/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,25 @@ def _configure_distributed_model(self, model):
if self.fp16_enabled():
if is_zero_init_model:
self.__check_params(self.module, torch.half)
self.module.half()
# selectively avoid casting specially
# marked parameters to 16-bit
self.module._apply(
lambda t: t.half() if (
t.is_floating_point() and
not getattr(t, "_deepspeed_no_cast", False)
) else t
)
elif self.bfloat16_enabled():
if is_zero_init_model:
self.__check_params(self.module, torch.bfloat16)
self.module.bfloat16()
# selectively avoid casting specially
# marked parameters to 16-bit
self.module._apply(
lambda t: t.bfloat16() if (
t.is_floating_point() and
not getattr(t, "_deepspeed_no_cast", False)
) else t
)
else:
self.__check_params(self.module, torch.float)

Expand Down

0 comments on commit 6d097be

Please sign in to comment.