Skip to content

Conversation

@andyjiang1116
Copy link
Contributor

PR types

Others

PR changes

OPs

Describe

[NPU] Support op kernel for Fill constant batch size like op

op unittest result:

image

GLOG:

image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 9, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

MissPenguin
MissPenguin previously approved these changes Aug 10, 2021
limitations under the License. */

#include <memory>
#include <string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个头文件不需要,删掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,谢谢

out->mutable_data(platform::CPUPlace(), data_type);
functor(reinterpret_cast<const platform::CPUDeviceContext &>(dev_ctx),
out, static_cast<T>(value));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考fill_constant_batch_size_like_op.h,这里应该是以下两个条件同时成立的情况下才走CPU
bool cpu_place = force_cpu || ctx.GetPlace() == platform::CPUPlace();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,谢谢

} else if (str_value == "-inf") {
value = static_cast<T>(-std::numeric_limits<double>::infinity());
} else if (str_value == "nan") {
value = static_cast<T>(std::numeric_limits<double>::quiet_NaN());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考fill_constant_batch_size_like_op.h,不支持inf或者nan的输入,可以把这里特殊处理去掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,谢谢

auto odims = out->dims();
auto idims = input->dims();
int output_dim_idx = ctx.Attr<int>("output_dim_idx");
odims[output_dim_idx] = static_cast<int>(idims[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能解释一下为什么这里的计算公式与以下不一致呢?

odims[output_dim_idx] = static_cast(in->lod().back().size()) - 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要支持Lodtensor是吗,我默认是用的tensor,所以直接取得第0维

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是Tensor的情况下,那应该是 odims[output_dim_idx] = idims[input_dim_idx],参考 batch_size_like.h里面的OpMaker的定义。

output_dim[output_dim_idx] = ctx->GetInputDim("Input")[input_dim_idx];

Copy link
Contributor

@qili93 qili93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qili93 qili93 merged commit ed2641c into PaddlePaddle:develop Aug 10, 2021
@andyjiang1116 andyjiang1116 deleted the fill_constant_batch_size_like_op_npu branch May 15, 2023 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants