Use gather to replace gather nd when the bool index is one-dimensional #72625
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 Category
Performance Optimization
PR Types
Performance
Description
case:
bool index是一维的时候使用gather替换gather nd有更好的性能
测试机器V100
对纯False的情况进行了测试,index为单值False的情况下比torch慢,其他情况下均有提升。
case:index = False
get_item paddle_gpu: 82.50 us, torch_gpu: 34.36 us, Paddle/Torch GPU score: 2.40)
get_item paddle_cpu: 100.40 us, torch_cpu: 47.92 us, Paddle/Torch CPU score: 2.10)
纯False:index = [False,False,False,...]
get_item paddle_gpu: 80.36 us, torch_gpu: 95.80 us, Paddle/Torch GPU score: 0.84)
get_item paddle_cpu: 100.39 us, torch_cpu: 113.18 us, Paddle/Torch CPU score: 0.89)
混合:index = [False,True,False,False,Ture,....]
get_item paddle_gpu: 479.26 us, torch_gpu: 587.41 us, Paddle/Torch GPU score: 0.82)
get_item paddle_cpu: 497.92 us, torch_cpu: 598.02 us, Paddle/Torch CPU score: 0.83)
Pcard-67164