Skip to content

Commit 603097b

Browse files
XiaobingSuperfacebook-github-bot
authored andcommitted
OneDNN MaxPooling: reduce memory use for inference path (#52728)
Summary: For OneDNN MaxPooling training, it will save indices as a workspace for backward, but for inference, indices are not necessary, this PR will make check to avoid saving indices to reduce memory use for inference path. Pull Request resolved: #52728 Reviewed By: jbschlosser Differential Revision: D27062435 Pulled By: VitalyFedyunin fbshipit-source-id: 9e70268a8ba491a7914b980079c0945d753cd4f3
1 parent 2c55797 commit 603097b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

aten/src/ATen/native/mkldnn/Pooling.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <ATen/ATen.h>
22
#include <ATen/Config.h>
33
#include <ATen/NativeFunctions.h>
4+
#include <ATen/core/grad_mode.h>
45
#include <ATen/native/utils/ParamUtils.h>
56
#include <tuple>
67

@@ -249,6 +250,15 @@ static Tensor _mkldnn_pooling(
249250
false /*ceil_mode */);
250251
}
251252

253+
auto aprop_kind = ideep::prop_kind::forward;
254+
// for max_pool, prop_kind::forward will save indices as workspace for backward use,
255+
// for inference, don't need the indices, set aprop_kind to prop_kind::forward_inference
256+
// can reduce the memory use.
257+
if (ideep::algorithm::pooling_max == algo
258+
&& !(input.requires_grad() && at::GradMode::is_enabled())) {
259+
aprop_kind = ideep::prop_kind::forward_inference;
260+
}
261+
252262
ideep::tensor y;
253263
ideep::pooling_forward::compute(
254264
x,
@@ -259,7 +269,7 @@ static Tensor _mkldnn_pooling(
259269
{padding_vec_l.cbegin(), padding_vec_l.cend()},
260270
{padding_vec_r.cbegin(), padding_vec_r.cend()},
261271
algo,
262-
ideep::prop_kind::forward);
272+
aprop_kind);
263273

264274
return new_with_itensor_mkldnn(std::move(y), optTypeMetaToScalarType(input.options().dtype_opt()), input.options().device_opt());
265275
}

0 commit comments

Comments
 (0)