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
Request for Swish Op #5853
Comments
Swish can be expressed as a combination of ONNX operators and can be easily fused by the backend. Was there a motivation for including it in the spec? |
Hello @justinchuby I suppose the benefits of implementing such a Spec is smilar to all the existing Activation Function in ONNX like Gelu, HardSwish, HardSigmoid, Mish etc. |
@gramalingam @xadupre for more thoughts. I suggest creating a pull request if the op is desired. Additionally, it is possible to implement it as a model local function. You may then be able to use it like you mentioned above. |
Additionally, if you would like to see it as a single unit in the exported PyTorch models by |
@justinchuby, the same is true for other functions like Clip, HardSigmoid, HardSwish, etc What are the criteria to add these as a function to the spec? According to AddNewOp.md the operator needs to be implemented by at-least one (well-known) framework which is the case for Swish/SiLU. Is this not sufficient? |
I understand ONNX is trying to keep the set of operators tight. Although this should be less of a concern when an op can be expressed as a function like in this case. I would bring this up in operators-sig and allow members of the sig to chime in. |
My personal opinion is that adding this as a function-op to ONNX standard is reasonable: it can be easily supported by inline-expansion (if no fused implementation is available) or using a specialized kernel. (We can discuss this in the operator SIG meeting.) |
Swish/SiLU
Do you have any plans to implement the Swish Op in ONNX?
Describe the operator
Swish is a popular Activation fuction. Its mathematical definition could be found at https://en.wikipedia.org/wiki/Swish_function
TensorFLow has https://www.tensorflow.org/api_docs/python/tf/nn/silu
Keras has https://keras.io/api/layers/activations/ (also in https://www.tensorflow.org/api_docs/python/tf/keras/activations/swish)
Pytorch has https://pytorch.org/docs/stable/generated/torch.nn.SiLU.html
Can this operator be constructed using existing onnx operators?
Yes, it could be implemented as a combination of Mul and Sigmoid Ops:
x * Sigmoid (beta * x)
Is this operator used by any model currently? Which one?
Yes. Modern Yolo series like yolov5, yolov7, yolov8, yolop and EfficientNet all have such Swish Ops.
Yolov5: https://github.com/ultralytics/yolov5/blob/master/models/tf.py#L224
EfficientNet:
https://paperswithcode.com/method/efficientnet which has Swish in https://github.com/lukemelas/EfficientNet-PyTorch/blob/2eb7a7d264344ddf15d0a06ee99b0dca524c6a07/efficientnet_pytorch/model.py#L294
Are you willing to contribute it? (Y/N)
Possibly Yes.
Notes
The text was updated successfully, but these errors were encountered: