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

tfjs-backend-webgl: may be an error in floatPrecision() function #6980

Open
xhcao opened this issue Oct 27, 2022 · 1 comment · May be fixed by #6981
Open

tfjs-backend-webgl: may be an error in floatPrecision() function #6980

xhcao opened this issue Oct 27, 2022 · 1 comment · May be fixed by #6981

Comments

@xhcao
Copy link
Contributor

xhcao commented Oct 27, 2022

When I ran e2e benchmarks and tested correctness on Desktop on webgl backend with default parameters, I found the comparing between actual and expected float results used 0.1 as the epsilon.

e2e test chooses the value of epsilon according to the float precision, choose 0.1 for float16 and 0.001 for float32.
https://github.com/tensorflow/tfjs/blob/master/tfjs-core/src/test_util.ts#L37

The definition of floatPrecision() function on webgl backend is shown as below,

floatPrecision(): 16|32 {
    if (this.floatPrecisionValue == null) {
      this.floatPrecisionValue = tidy(() => {
        if (!env().get('WEBGL_RENDER_FLOAT32_ENABLED')) {
          // Momentarily switching DEBUG flag to false so we don't throw an
          // error trying to upload a small value.
          const debugFlag = env().getBool('DEBUG');
          env().set('DEBUG', false);
          const underflowCheckValue = this.abs(scalar(1e-8)).dataSync()[0];
          env().set('DEBUG', debugFlag);

          if (underflowCheckValue > 0) {
            return 32;
          }
        }
        return 16;
      });
    }
    return this.floatPrecisionValue;
  }

I debugged that the WEBGL_RENDER_FLOAT32_ENABLED flag is always true, so the function always returns 16.
Is there a conflict?

@xhcao xhcao added the type:bug Something isn't working label Oct 27, 2022
@Linchenn Linchenn linked a pull request Oct 27, 2022 that will close this issue
@Linchenn
Copy link
Collaborator

Thank you so much for reporting and locating this bug! I have sent a fix for it, but changing epsilon from 0.1 to 0.001 causes some WebGL test failures, so I may need to fix them before merging this fix.

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

Successfully merging a pull request may close this issue.

3 participants