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

Fix CPU memory leak due to external weights not getting memory unmapped when using non-CPU EP. #15040

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion onnxruntime/core/framework/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct OrtCallbackInvoker {
*/
class ScopedOrtCallbackInvoker {
public:
ScopedOrtCallbackInvoker() {}
explicit ScopedOrtCallbackInvoker(OrtCallback callback) noexcept
: callback_(callback) {}

Expand Down Expand Up @@ -69,6 +70,6 @@ class ScopedOrtCallbackInvoker {

private:
ORT_DISALLOW_COPY_AND_ASSIGNMENT(ScopedOrtCallbackInvoker);
OrtCallback callback_;
OrtCallback callback_{};
};
} // namespace onnxruntime
2 changes: 2 additions & 0 deletions onnxruntime/core/framework/session_state_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ static common::Status DeserializeTensorProto(const Env& env, const std::basic_st
}

OrtCallback ext_data_deleter;
ScopedOrtCallbackInvoker scoped_ort_callback_invoker;
if (utils::HasExternalData(tensor_proto)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use std::optional to avoid the changes to callback.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can, but in general RAII classes should also have a default constructor (like unique_ptr, shared_ptr, scoped_ptr) and a way to either reset its contents or copy/move them. Hence the change to callback.h.

ORT_RETURN_IF_ERROR(ExtDataTensorProtoToTensor(env, proto_path, tensor_proto, *p_deserialize_tensor,
ext_data_deleter));
scoped_ort_callback_invoker = ScopedOrtCallbackInvoker(ext_data_deleter);
} else {
ORT_RETURN_IF_ERROR(utils::TensorProtoToTensor(env, proto_path.c_str(), tensor_proto, *p_deserialize_tensor));
}
Expand Down