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

Add SELU activation function #2559

Merged
merged 1 commit into from
May 1, 2024

Conversation

kimhan0515
Copy link
Contributor

  • Now, user can use SELU activation function like torch or tensor flow.

Self evaluation:

  1. Build test: [X]Passed [ ]Failed [ ]Skipped
  2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: kimhan0515 [email protected]

@taos-ci
Copy link

taos-ci commented Apr 27, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2559. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

Copy link

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@kimhan0515, 💯 All CI checkers are successfully verified. Thanks.

template <typename T = float> static T selu(T x) {
return x > static_cast<T>(0.0)
? selu_scale * x
: selu_scale * static_cast<T>(selu_alpha * (exp(x) - 1));
Copy link
Member

Choose a reason for hiding this comment

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

This code would emit error like below when built with -Denable-fp16=true option:
Needs some trivial fixing.

../nntrainer/layers/acti_func.h:498:69: error: converting to ‘_Float16’ from ‘float’ with greater conversion rank [-Werror]
  498 |              : selu_scale * static_cast<T>(selu_alpha * (exp(x) - 1));
      |                                                                     ^
cc1plus: all warnings being treated as errors

Try below to reproduce above:

cd ~/nntrainer
meson build -Denable-fp16=true
cd ./build
ninja

The same issue was pointed at #2545 and fixed with #2557
Please refer to them and reconsider afterwards.

Copy link
Contributor

@heka1024 heka1024 Apr 29, 2024

Choose a reason for hiding this comment

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

I think adding enable-fp16 could be an option to eliminate this kind of error. #2560 Let's talk about it!

- Now, user can use SELU activation function like torch or tensor flow.

**Self evaluation:**
1. Build test:     [X]Passed [ ]Failed [ ]Skipped
2. Run test:     [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: kimhan0515 <[email protected]>
Copy link
Member

@skykongkong8 skykongkong8 left a comment

Choose a reason for hiding this comment

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

Overall, lgtm

EXPECT_NEAR(data[i], answer[i], tolerance);
}
}

Copy link
Member

@skykongkong8 skykongkong8 Apr 29, 2024

Choose a reason for hiding this comment

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

Along with this, I would like to personally recommend implementing a half-precision TC as well.
You might need to add a new file like : unittest_nntrainer_activations_fp16.cpp

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 agree with the point!
Maybe it would be better to implement half-precision TCs for other types of activations as well as SELU, in separate PR!

Copy link

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@kimhan0515, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Contributor

@baek2sm baek2sm left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -667,6 +694,8 @@ class ActiFunc {
private:
constexpr static inline float alpha = 1.0f; /**< alpha for elu */
constexpr static inline float beta = 1.0f; /**< beta for Softplus */
constexpr static inline float selu_alpha = 1.67326324f; /**< alpha for selu */
constexpr static inline float selu_scale = 1.05070098f; /**< scale for selu */
Copy link
Contributor

Choose a reason for hiding this comment

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

As you may already know, setting the parameters of the activation function in this way is not a good direction. I understand that existing codes, especially Leaky ReLU, have already been implemented in this manner. So I know why you implemented it this way and I understand you. As for the next task, rather than adding an activation function, how about improving the structure so that the parameters of the activation function can be processed by receiving the property as input? It is optional but not essential for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your opinion! I think that the task will be quite worthwhile.

@jijoongmoon jijoongmoon merged commit 2060051 into nnstreamer:main May 1, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants