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

ORTModule memory improvement #18924

Merged
merged 17 commits into from
Jan 16, 2024
Prev Previous commit
Next Next commit
enable when auto grad function is enabled
  • Loading branch information
pengwa committed Dec 26, 2023
commit 633129385819d61a92c07d4ee4679988c3b91553
11 changes: 9 additions & 2 deletions orttraining/orttraining/python/training/ortmodule/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def __init__(self, logger: Logger):
# Experimental features.
self.enable_zero_stage3_support = False # Once enabled, cannot be disabled.

self.enable_mem_efficient_grad_management = False
# If auto grad function support is enabled, we will enable memory efficient grad management by default.
self.enable_mem_efficient_grad_management = self.enable_custom_autograd_function

self.deepcopy_before_model_export = True

Expand Down Expand Up @@ -403,7 +404,13 @@ def _override_from_env_vars(self):
"ORTMODULE_ENABLE_MEM_EFFICIENT_GRAD_MGMT" in os.environ
and int(os.getenv("ORTMODULE_ENABLE_MEM_EFFICIENT_GRAD_MGMT")) == 1
):
self.enable_mem_efficient_grad_management = True
if self.enable_custom_autograd_function:
self.enable_mem_efficient_grad_management = True
else:
self._logger.warning(
"ORTModule optimization for memory efficient gradient management cannot be enabled "
"because PyTorch custom autograd function support is disabled."
)

if "ORTMODULE_DEEPCOPY_BEFORE_MODEL_EXPORT" in os.environ:
self.deepcopy_before_model_export = int(os.getenv("ORTMODULE_DEEPCOPY_BEFORE_MODEL_EXPORT")) == 1
Loading