-
Notifications
You must be signed in to change notification settings - Fork 2k
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 support for GELU and approximate activation functions #8224
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f4ad2b1
add docker configs for isolated testing
Vectorrent d90d735
implement gelu and gelu_new as separate activations
Vectorrent f27de34
Update activations.ts
pyu10055 6352f8b
Update activations_test.ts
pyu10055 890182d
Update activations_test.ts
pyu10055 679a162
remove docker files
Vectorrent 7181b07
fix activation tests
Vectorrent f78d5d9
Merge branch 'master' into add-new-activations
pyu10055 742e19d
fix lint errors
Vectorrent 376ba19
remove extra blank line
Vectorrent ed02f32
fix gelu_new calc
Vectorrent bfaee9e
fix 1D test
Vectorrent 7b38dbc
Merge branch 'master' into add-new-activations
mattsoulanille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is failing on webgl
https://btx.cloud.google.com/invocations/e17bf0ae-be69-4c2c-ae42-898362837087/targets/%2F%2Ftfjs-layers:bs_chrome_mac_tfjs-layers_webgl2_test;config=558edca9061547b5089f0232d6a9290fa00acb52e12d7215b154805a33d24105/log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see the error, so I don't know what's failing. I can't imagine why webgl would fail while other backends would succeed, but maybe it's a difference in floating point precision between environments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how I screwed up so badly, but every single test value was wrong. I just went through and updated every one of them by-hand; tests should be fixed now. Sorry about that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries, thanks for fixing the test.
can you run following in the tfjs directory:
tslint -p tsconfig_tslint.json
and fix the lint errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I'll remember to check the linting in future commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'm back in office now, so I've taken a look.
I think this implementation of
gelu_new
might be computing justΦ(x)
instead ofx Φ(x)
According to
help(keras.activations.gelu)
in python,0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))
is the approximate form thatgelu_new
is computing, but I think the implementation is missing the* x
. That's why all the values were wrong.I tried adding a
* x
to the implementation and the values look closer: