diff --git a/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc b/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc index 3d1be9196fdeacd8ff852dbb595473a687352ccf..4b0a9d9b1c48fcb0d5e44ec1b977c817f3c70b2e 100644 --- a/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc +++ b/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "paddle/fluid/framework/ir/graph_helper.h" @@ -168,7 +169,11 @@ bool FindSuitableTensorToReuse( if (!cluster->count(candidate)) continue; size_t space = space_table.at(candidate); - size_t space_diff = std::abs(space - space_required); + PADDLE_ENFORCE( + space <= std::numeric_limits::type>::max(), + "space overload"); + size_t space_diff = + std::abs((std::make_signed::type)space - space_required); if (space_diff < best_fit.second) { best_fit.first = candidate; best_fit.second = space_diff;