Skip to content

Fix division-by-zero #123

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

jay-tux
Copy link

@jay-tux jay-tux commented Nov 22, 2024

When quantizing the (input) activations to the bit-linear layer, NaNs may occur due to division by zero. This is a consequence of the formula in the original paper:
$Quant(x) = Clip(x \times \frac{Q_b}{||x||_\infty}, -Q_b + \epsilon, Q_b - \epsilon$

In the extreme case where all activations are zero, this will result in abs-max being zero, and thus a division by zero.

To fix this, I made sure to add 1e-10f to all maxes in the preset kernels. In 99.99% of cases, this will be a minor (or no) change, but in problematic cases, this avoids NaNs.

@jay-tux
Copy link
Author

jay-tux commented Nov 22, 2024

@microsoft-github-policy-service agree company="UGent"

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

Successfully merging this pull request may close these issues.

1 participant