Skip to content
Open
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
9 changes: 9 additions & 0 deletions paddlenlp/trainer/utils/offload_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os

import paddle
from paddle import _C_ops
Expand All @@ -37,6 +38,10 @@ def reload(tensor):
assert new_tensor is tensor, "to_device must be inplace operation"


def is_offload_opt_cache_master_weight():
return os.getenv("FLAGS_offload_opt_master_weight_cache", "0").lower() in ["true", "1"]


def hack_offload_optimizer():
# Step 1: mock _add_accumulator
origin_add_accumulator = getattr(Optimizer, "_add_accumulator")
Expand All @@ -60,6 +65,10 @@ def new_opt_op(*args):
ret = origin_op(*args)
is_offload_opt = getattr(args[0], "is_offload_opt", False)
for i, arg in enumerate(args):
# need_offload_arg = i >= 2 and isinstance(arg, paddle.Tensor) and is_offload_opt
# if is_offload_opt_cache_master_weight():
# need_offload_arg = need_offload_arg and i != 8
# if need_offload_arg: # do not offload parameter and gradient
if (
i >= 2 and isinstance(arg, paddle.Tensor) and is_offload_opt
): # do not offload parameter and gradient
Expand Down
Loading