Add float16 and bfloat16 support in sinusoidal encodings.#82
Open
gdewael wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 96.62% 96.69% +0.06%
==========================================
Files 24 24
Lines 1008 1029 +21
==========================================
+ Hits 974 995 +21
Misses 34 34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, the transformers in
depthchargeshould not be trained with float16 or bfloat16 precision, which has become semi-standard in transformer training.The issue is two-fold:
self.sin_termandself.cos_termhave large numbers which cannot be accurately represented with lower precision, distorting the positional encodings (PositionalEncoder(1024).sin_term.max()returnstensor(15915.4941)), and the mz resolution of MS experiments can not be faithfully represented using bfloat16 and float16 inputs (i.e.,mz_arrayinputs toSpectrumTransformerEncoder, see #76 (comment)).This PR does the following:
FloatEncoder'slearnable_wavelengths=False, it fixesself.sin_termandself.cos_termtofloat32precision.FloatEncoderis passed lower thanfloat32precision values, it raises a warning.PositionalEncoder, where this line would otherwise give inaccurate positions for large sequences in combination with bfloat16 model dtypes.