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

fix: prevent division by zero in soft_max vulkan shader #2604

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

Conversation

gn64
Copy link

@gn64 gn64 commented Dec 2, 2024

Fix division by zero error in soft_max vulkan shader

This PR fixes #2596 by adding a check for p.KY being zero in the soft_max compute shader.

Changes:

  • Modified the calculation of rowy in soft_max.comp to handle the case where p.KY is 0
  • Changed const uint rowy = rowx % p.KY; to const uint rowy = (p.KY > 0) ? (rowx % p.KY) : 0;

The original code would cause a division by zero error when p.KY is 0. This fix ensures that rowy is set to 0 in such cases, preventing the crash while maintaining the expected behavior in normal scenarios.

Testing:

  • Confirmed the fix resolves the crash in my environment
  • Existing functionality remains unchanged when p.KY > 0

This change prevents a division by zero error when p.KY is 0.
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.

Invalid probability vector error with AMD iGPU on Vulkan backend Environment
1 participant