Skip to content

【npu】release gil lock when predictor run #72485

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

Merged
merged 3 commits into from
Apr 27, 2025
Merged
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
46 changes: 32 additions & 14 deletions paddle/fluid/pybind/inference_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void BindPaddlePredictor(py::module *m) {
paddle_predictor
.def("run",
[](PaddlePredictor &self, const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs;
Expand All @@ -755,9 +755,15 @@ void BindPaddlePredictor(py::module *m) {
.def("get_output_tensor", &PaddlePredictor::GetOutputTensor)
.def("get_input_names", &PaddlePredictor::GetInputNames)
.def("get_output_names", &PaddlePredictor::GetOutputNames)
.def("zero_copy_run",
&PaddlePredictor::ZeroCopyRun,
py::arg("switch_stream") = false)
.def(
"zero_copy_run",
[](PaddlePredictor &self, bool switch_stream) {
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
return self.ZeroCopyRun(switch_stream);
},
py::arg("switch_stream") = false)
.def("clone", [](PaddlePredictor &self) { return self.Clone(nullptr); })
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
.def("clone",
Expand Down Expand Up @@ -797,7 +803,7 @@ void BindNativePredictor(py::module *m) {
.def("run",
[](NativePaddlePredictor &self,
const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs;
Expand All @@ -806,9 +812,15 @@ void BindNativePredictor(py::module *m) {
})
.def("get_input_tensor", &NativePaddlePredictor::GetInputTensor)
.def("get_output_tensor", &NativePaddlePredictor::GetOutputTensor)
.def("zero_copy_run",
&NativePaddlePredictor::ZeroCopyRun,
py::arg("switch_stream") = false)
.def(
"zero_copy_run",
[](NativePaddlePredictor &self, bool switch_stream) {
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
return self.ZeroCopyRun(switch_stream);
},
py::arg("switch_stream") = false)
.def("clone",
[](NativePaddlePredictor &self) { return self.Clone(nullptr); })
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
Expand Down Expand Up @@ -1132,7 +1144,7 @@ void BindAnalysisPredictor(py::module *m) {
.def(
"run",
[](AnalysisPredictor &self, const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs;
Expand All @@ -1144,9 +1156,15 @@ void BindAnalysisPredictor(py::module *m) {
.def("get_input_names", &AnalysisPredictor::GetInputNames)
.def("get_output_names", &AnalysisPredictor::GetOutputNames)
.def("get_input_tensor_shape", &AnalysisPredictor::GetInputTensorShape)
.def("zero_copy_run",
&AnalysisPredictor::ZeroCopyRun,
py::arg("switch_stream") = false)
.def(
"zero_copy_run",
[](AnalysisPredictor &self, bool switch_stream) {
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
return self.ZeroCopyRun(switch_stream);
},
py::arg("switch_stream") = false)
.def("clear_intermediate_tensor",
&AnalysisPredictor::ClearIntermediateTensor)
.def("try_shrink_memory", &AnalysisPredictor::TryShrinkMemory)
Expand Down Expand Up @@ -1185,7 +1203,7 @@ void BindPaddleInferPredictor(py::module *m) {
"run",
[](paddle_infer::Predictor &self,
const std::vector<paddle::Tensor> &in_tensor_list) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<paddle::Tensor> outputs;
Expand All @@ -1195,7 +1213,7 @@ void BindPaddleInferPredictor(py::module *m) {
py::arg("inputs"))
.def("run",
[](paddle_infer::Predictor &self) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
#if !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
self.Run();
Expand Down
Loading