Created
July 23, 2019 18:45
-
-
Save jerry73204/1fbd2f7a41a8eee1c47b163d40045454 to your computer and use it in GitHub Desktop.
The patch to fix pytorch-1.1 memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/torch/csrc/api/src/optim/adagrad.cpp b/torch/csrc/api/src/optim/adagrad.cpp | |
index 96b9af2bcd..e5da19b8d3 100644 | |
--- a/torch/csrc/api/src/optim/adagrad.cpp | |
+++ b/torch/csrc/api/src/optim/adagrad.cpp | |
@@ -24,6 +24,7 @@ void Adagrad::step() { | |
} | |
if (options.weight_decay_ > 0) { | |
+ NoGradGuard guard; | |
p.grad() = p.grad() + options.weight_decay_ * p; | |
} | |
diff --git a/torch/csrc/api/src/optim/adam.cpp b/torch/csrc/api/src/optim/adam.cpp | |
index d7c7bbaa26..6a6585a3e4 100644 | |
--- a/torch/csrc/api/src/optim/adam.cpp | |
+++ b/torch/csrc/api/src/optim/adam.cpp | |
@@ -23,6 +23,7 @@ void Adam::step() { | |
} | |
if (options.weight_decay_ > 0) { | |
+ NoGradGuard guard; | |
p.grad() = p.grad() + options.weight_decay_ * p; | |
} | |
diff --git a/torch/csrc/api/src/optim/rmsprop.cpp b/torch/csrc/api/src/optim/rmsprop.cpp | |
index e1715789ba..7018a16ce6 100644 | |
--- a/torch/csrc/api/src/optim/rmsprop.cpp | |
+++ b/torch/csrc/api/src/optim/rmsprop.cpp | |
@@ -24,6 +24,7 @@ void RMSprop::step() { | |
} | |
if (options.weight_decay_ > 0) { | |
+ NoGradGuard guard; | |
p.grad() = p.grad() + options.weight_decay_ * p; | |
} | |
diff --git a/torch/csrc/api/src/optim/sgd.cpp b/torch/csrc/api/src/optim/sgd.cpp | |
index 828acd3bf0..78a6fd847b 100644 | |
--- a/torch/csrc/api/src/optim/sgd.cpp | |
+++ b/torch/csrc/api/src/optim/sgd.cpp | |
@@ -26,6 +26,7 @@ void SGD::step() { | |
auto update = p.grad(); | |
if (options.weight_decay_ > 0) { | |
+ NoGradGuard guard; | |
update += options.weight_decay_ * p; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment