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

Divide-by-zero outcome should be standardized #691

Open
huningxin opened this issue May 24, 2024 · 2 comments
Open

Divide-by-zero outcome should be standardized #691

huningxin opened this issue May 24, 2024 · 2 comments
Assignees
Labels

Comments

@huningxin
Copy link
Contributor

huningxin commented May 24, 2024

This issue was raised by @wacky6 and @a-sully in Chromium CL review 5064994 and 5541389.

The discussion was about MLBatchNormalizationOptions.epsilon

epsilon, of type float, defaulting to 1e-5
A small value to prevent computational error due to divide-by-zero.

epsilon would be used by batchNormalization according to its calculation

Output = Scale * ((Input - Mean) / sqrt(Variance + Epsilon)) + Bias.

WebNN spec doesn't put any restriction on epsilon. It means if both variance and epsilon are 0, there will be divide-by-zero error.

epsilon is also used by instanceNormalization and layerNormalization, they may have similar division-by-zero error. The generic element-wise binary div should also be considered.

The proposal is to standardize divide-by-zero outcome. For example, as @fdwr mentioned, DirectML would give NaN if variance and epsilon are 0.

Refer to Wikipedia Division by Zero page for more information.

@inexorabletash
Copy link
Member

WG telecon: @fdwr and @huningxin to investigate behavior across different backends, and get a concrete proposal.

Consider marking this as an interop issue if we see meaningful differences across backends

@fdwr
Copy link
Collaborator

fdwr commented Jun 13, 2024

The generic element-wise binary div should also be considered.

For ordinary div, I'd expect:

  • x / 0 -> inf
  • -x / 0 - > -inf
  • 0 / 0 -> indeterminate NaN

Investigation ongoing across hardware... ⏳.

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

No branches or pull requests

3 participants