fix amax/amin/max/min write overflow #47570
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
APIs
Describe
export FLAGS_use_system_allocator=1, 问题来源于 #47125
amax最小复现代码:
max最小复现代码:
定位说明
@veyron95 定位到的情况是:
Paddle/paddle/phi/kernels/funcs/reduce_functor.h
中AMaxOrAMinGradFunctor
内部一个计算发现了写越界:dx->device(place) = dy->broadcast(dim) * mask / equal_number;
Paddle/paddle/phi/kernels/funcs/reduce_functor.h
中MaxOrMinGradFunctor
内部一个计算发现了写越界:dx->device(place) = (dy->broadcast(dim) * equals.select(ones, zeros));
FLAGS_use_system_allocator=0
,内存管理使用的是 BestFitAllocator, 会申请一大块内存供 tensor 使用,即使在实际使用中写越界,由于越界的部分没人使用,也不会有什么太大的问题。@luotao1 定位到的情况是:
python/paddle/fluid/tests/unittests/test_max_min_amax_amin_op.py
115行def test_dygraph(self):
注释就可以过axis=None
的情况下,会出错。也就是TestMaxMinAmaxAminAPI2
和TestMaxMinAmaxAminAPI6
会出错。依次打印右边的变量,
dy->broadcast(dim)
是64数值,需要做一下reshape