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

Make FP16 code more reusable. @open sesame 03/07 10:42 #2417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

myungjoo
Copy link
Member

This allows writing FP16-independent code without
breaking the current code.

This is a non-invasive subset of #2403 to
address the concern of #2403 (comment)

I believe nntrainer can use this during the refactoring so that we do not introduce additional code divergences.

This allows writing FP16-independent code without
breaking the current code.

This is a non-invasive subset of nnstreamer#2403 to
address the concern of nnstreamer#2403 (comment)

I believe nntrainer can use this during the refactoring so that we
do not introduce additional code divergences.

Signed-off-by: MyungJoo Ham <[email protected]>
@taos-ci
Copy link
Collaborator

taos-ci commented Jan 19, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2417. 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
Collaborator

@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.

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

@@ -28,8 +30,56 @@
#else
#define _FP16 _Float16
#endif
#else /* !ENABLE_FP16 */
/* Keep the FP16 programming interface, but don't allow using it in run-time */
#define _FP16 uint16_t
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is great. It definitely can be used for refactoring the multi type handle in NNTrainer.

@@ -54,6 +54,9 @@ class ActiFunc {
template <typename T = float> void setActiFunc(ActivationType acti_type) {
activation_type = acti_type;

if (typeid(T) == typeid(_FP16))
THROW_UNLESS_FP16_ENABLED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this needs to be checked again. I don't think we need to throw an error here. These activation function type surely need to support FP16 datatype. To check, we have to enable the 'enable-fp16' option in meson_options.txt should be true.

Copy link
Member Author

@myungjoo myungjoo Jan 22, 2024

Choose a reason for hiding this comment

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

This ensures thorwing an exception when FP16 activation is called without FP16 support.

By calling (conditional) THROW at the point where FP16 op actually exists, we can skip writing FP16 conditions at the callers (where you update codes mostly). This further reduces dependencies on FP16 in the code, overall. (you don't need to write if-fp16-enable codes elsewhere)

Note that this is currently implemented as preprocessor macro, coming from meson's options.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is an exception for a situation where attempting to use FP16 even though FP16 is disabled in the Meson option, so it seems proper to handle the exception here.

Copy link
Member

@SeoHyungjun SeoHyungjun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jihochu jihochu left a comment

Choose a reason for hiding this comment

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

LGTM

@DonghakPark DonghakPark changed the title Make FP16 code more reusable. Make FP16 code more reusable. @open sesame 03/07 10:42 Mar 7, 2024
Copy link
Collaborator

@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.

@myungjoo, 💯 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants