jiangjiajun commented on code in PR #14160:
URL: https://github.com/apache/tvm/pull/14160#discussion_r1125835333
##########
python/tvm/relay/frontend/paddlepaddle.py:
##########
@@ -1950,6 +1958,30 @@ def convert_softsign(g, op, block):
g.add_node(op.output("Out")[0], out)
+def convert_softshrink(g, op, block):
+ """Operator converter for softshrink."""
+
+ threshold = op.attr("lambda")
+ x = g.get_node(op.input("X")[0])
+ dtype = infer_type(x).checked_type.dtype
+ threshold_right = _expr.const(threshold, dtype)
+ threshold_left = _expr.const(-1.0 * threshold, dtype)
+ middle = _expr.const(0.0, dtype)
+ condition_0 = tvm.relay.logical_and(
+ tvm.relay.less_equal(x, threshold_right), tvm.relay.greater_equal(x,
threshold_left)
+ )
+ calc_middle = tvm.relay.where(condition_0, middle, x)
+
+ sub_threshold = _op.subtract(x, threshold_right)
+ condition_1 = tvm.relay.greater(calc_middle, threshold_right)
+ calc_right = tvm.relay.where(condition_1, sub_threshold, calc_middle)
+
+ add_threshold = _op.add(x, threshold_right)
+ condition_2 = tvm.relay.less(calc_right, threshold_left)
+ calc_left = tvm.relay.where(condition_2, add_threshold, calc_right)
+ g.add_node(op.output("Out")[0], calc_left)
Review Comment:
Can you refer the following code to optimize this implementation
https://github.com/apache/tvm/blob/befdc4e63100bdf25b10ae7a54b40408e2e1805a/python/tvm/relay/frontend/onnx.py#L2280-L2291
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]