Allow Softplus activation in ONNX surrogate parser#1743
Allow Softplus activation in ONNX surrogate parser#1743karllindvall wants to merge 2 commits intoIDAES:mainfrom
Conversation
avdudchenko
left a comment
There was a problem hiding this comment.
I suggest we try removing the line of code that modifies _activation_op_types as it should be redundant with the newer version of OMLT. We can consider adding an option to modify this list if user supplies their own list of supported activation functions, but that might be problematic and unnecessary.
There was a problem hiding this comment.
@karllindvall So I added that line at the time because OMLT did not expose tanh (as OMLT was only released on pipy for version of 1.1, which excluded tanh,, with current version being 1.22. I believe now all of the functions (including softplus) should be included in _ACTIVATION_OP_TYPES out of the box.
We probably can remove this line of code entirely, as it is now redundant.
|
Agreed! In OMLT’s I have also added a pull-request to OMLT’s repository with the logic for adding softplus as an accepted activation function, as well as to accept activation function nodes as stand-alone nodes and not only attached to another layer. Hopefully these changes will go through as well, after which softplus will be an accepted activation function. |
Do you need any changes to IDAES onnx surrogate models to support the soft plus stand alone nodes? or is it purely just OMLT issue? I guess we are in agreement on removing the _ACTIVATION_OP_TYPE line from the onnx_surrogate, (can you make the change and I can probably approve the workflow runs and hopefully after it can be merged). |
|
I have completely removed the line now, so any activation functions that are passed from OMLT to IDAES should now go through. Regarding the standalone node edit, it is purely on the OMLT-side, so there is nothing you need to change. Let me know if any problems arise. |
Summary
Add Softplus to the list of allowed activation functions when loading ONNX neural network surrogates.
Motivation
Softplus is a commonly used smooth activation function and is already supported by OMLT. However, when loading ONNX surrogates through IDAES, idaes.core.surrogate.onnx_surrogate currently overwrites the OMLT activation allowlist with:
["Relu", "Sigmoid", "LogSoftmax", "Tanh"]This prevents ONNX networks using Softplus from being parsed and results in:
ValueError: Unhandled node type SoftplusChange
Add "Softplus" to the activation allowlist:
["Relu", "Sigmoid", "LogSoftmax", "Tanh", "Softplus"]Result
ONNX networks exported with Softplus activation functions can now be loaded successfully through the IDAES ONNX surrogate interface.
Notes
OMLT already includes support for Softplus, so this change simply removes an unnecessary restriction in the IDAES wrapper.