-
Notifications
You must be signed in to change notification settings - Fork 950
Made tf.abs underflow-safe on CPU & GPU and added test for it. #1391
Conversation
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.
Thank you for the fix, really nice work! I sent some minor styling comments just so you get familiar with our style for the future :)
Reviewable status: 0 of 1 approvals obtained (waiting on @DirkToewe)
src/kernels/webgl/complex_abs_gpu.ts, line 29 at r1 (raw file):
this.userCode = ` void main() { float re = abs( getRealAtOutCoords() );
could you remove the extra white space? after and before the parens (here and below)
src/kernels/webgl/complex_abs_gpu.ts, line 31 at r1 (raw file):
float re = abs( getRealAtOutCoords() ); float im = abs( getImagAtOutCoords() ); float mx = max(re,im);
there should be an extra space between re, im
src/kernels/webgl/complex_abs_gpu.ts, line 34 at r1 (raw file):
// sadly the length function in glsl is not underflow-safe // (at least not on Integl GPUs). So the safe solution is
Intel
src/kernels/webgl/complex_abs_gpu.ts, line 37 at r1 (raw file):
// to ensure underflow-safety in all cases. setOutput( mx * length( vec2(1, min(re,im)/mx) )
remove the extra spaces inside of length()
src/ops/unary_ops_test.ts, line 173 at r1 (raw file):
it('is underflow-safe for complex64', () => { const a = tf.complex( /*re=*/[ 1e-30, 0 ],
no need for these comments :)
Done, hope I didn't forget anything. |
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.
LGTM -- I will merge after one small change which will fix the travis build
Reviewable status: 0 of 1 approvals obtained (waiting on @DirkToewe)
src/ops/unary_ops_test.ts, line 173 at r2 (raw file):
it('is underflow-safe for complex64', () => { const a = tf.complex( [1e-30, 0 ],
One last comment, instead of 1e-30 can you use tf.ENV.get('EPSILON')
which is the smallest representable value larger than zero (works on all devices, this is why travis is failing for iOS which is float16 which has a larger epsilon).
There was a 0/0 bug that caused the NaN and which should now be fixed. |
Hm, I know what the issue is (we're uploading this as a uniform) so I'll merge this change and then fix it :) |
Really nice work! |
Thank You! Take float64 for example: |
Description
Fixes part of #895. The CPU backend now uses
Math.hypot
and the WebGL backend useslength
albeit with some workaround to ensure underflow-safety (which is otherwise not given, at least on Intel GPUs).For repository owners only:
Please remember to apply all applicable tags to your pull request.
Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY
For more info see: /~https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md
This change is