Skip to content
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

【PaddlePaddle Hackathon 4】add paddle softshrink op #15845

Merged
merged 14 commits into from
May 4, 2023

Conversation

AndPuQing
Copy link
Contributor

Details:

add softshrink op in paddle front end

$$ softshrink(x)=\left{\begin{aligned} x-\text { threshold, } & \text { if } x>\text { threshold } \\ x+\text { threshold, } & \text { if } x<-\text { threshold } \\ 0, & \text { otherwise } \end{aligned}\right. $$

Tickets:

  • ticket-id

Reference

https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/nn/functional/softshrink_en.html

image

@AndPuQing AndPuQing requested a review from a team as a code owner February 21, 2023 12:07
@github-actions github-actions bot added the category: PDPD FE OpenVINO PaddlePaddle FrontEnd label Feb 21, 2023
std::shared_ptr<ngraph::Node> adjusted_inputs_above_pos_lambda =
std::make_shared<default_opset::Multiply>(std::make_shared<default_opset::Add>(data, negative_lambda),
values_above_pos_lambda);
adjusted_inputs = std::make_shared<default_opset::Add>(adjusted_inputs, adjusted_inputs_below_neg_lambda);
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.

Yes, it can be implemented using select, which looks more concise than the original implementation, but I wonder if matrix multiplication will be more efficient than select ?

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion is to use benchmark_app to test the performance of single node graph, and find out a best implementation ?

@AndPuQing AndPuQing requested review from a team as code owners March 19, 2023 07:32
@github-actions github-actions bot added category: dependency_changes Pull requests that update a dependency file category: GPU OpenVINO GPU plugin category: Python API OpenVINO Python bindings labels Mar 19, 2023
@github-actions github-actions bot removed category: dependency_changes Pull requests that update a dependency file category: GPU OpenVINO GPU plugin category: Python API OpenVINO Python bindings labels Mar 19, 2023
@liubo-intel liubo-intel removed request for a team March 20, 2023 08:19

output = std::make_shared<default_opset::Select>(zero_mask, output, zero_node);
} else {
// Passing -lambd to unsigned type constant will cause an overflow.
Copy link
Contributor

Choose a reason for hiding this comment

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

Refer to Paddle spec, input x could be float32 and float64 only. How can a test case trigger this else branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ceciliapeng2011 : the other Paddle 'softshrink' api defined here : https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Softshrink_cn.html#softshrink
looks like there is no such limitation for input x type. To cover this api, I think we may still need the branch to handle '-lambd to unsigned type' cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, @AndPuQing : about @ceciliapeng2011 's concern, could you please have a try to add such unsigned type test case by using paddle.nn.Softshrink() api?
if such test case is difficult to generate from paddle side, let's disable such unsigned input support(delete the else branch) this time, and add an input type check PADDLE_OP_CHECK(node, input_element_type.is_signed(), "softshrink only supports singed input data type"); for this op.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I test the unsighed tensor input on the paddlepaddle delelop version, there is the result:

>>>import paddle
>>>a = paddle.to_tensor([1],dtype='uint8')
>>>a
Out[3]:
Tensor(shape=[1], dtype=uint8, place=Place(gpu:0), stop_gradient=True,
       [1])
>>>paddle.nn.functional.softshrink(a)
RuntimeError: (NotFound) The kernel with key (GPU, Undefined(AnyLayout), uint8) of kernel `softshrink` is not registered and fail to fallback to CPU one. Selected wrong DataType `uint8`. Paddle support following DataTypes: float64, float16, float32, bfloat16.
  [Hint: Expected kernel_iter != iter->second.end(), but received kernel_iter == iter->second.end().] (at /paddle/paddle/phi/core/kernel_factory.cc:259)

So, I think just add dtype check currently.

@ilya-lavrenov ilya-lavrenov modified the milestones: 2023.0, 2023.1 Apr 24, 2023
@ceciliapeng2011 ceciliapeng2011 merged commit bc6402f into openvinotoolkit:master May 4, 2023
51 checks passed
@AndPuQing AndPuQing deleted the patch-softshrink branch May 18, 2023 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: PDPD FE OpenVINO PaddlePaddle FrontEnd ExternalPR External contributor PaddlePaddle Hackathon a Intel and Baidu joint Hackathon event
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants