-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[NPU] Support op kernel for Fill constant batch size like op #34721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NPU] Support op kernel for Fill constant batch size like op #34721
Conversation
|
Thanks for your contribution! |
| limitations under the License. */ | ||
|
|
||
| #include <memory> | ||
| #include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个头文件不需要,删掉。
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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的输入,可以把这里特殊处理去掉。
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要支持Lodtensor是吗,我默认是用的tensor,所以直接取得第0维
There was a problem hiding this comment.
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];
qili93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… fill_constant_batch_size_like_op_npu
PR types
Others
PR changes
OPs
Describe
[NPU] Support op kernel for Fill constant batch size like op
op unittest result:
GLOG: