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 #2633

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

gn64
Copy link
Contributor

@gn64 gn64 commented Dec 16, 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

Note:
This PR is a focused version of #2604, containing only the Vulkan shader fix. The original PR has been closed in favor of this more targeted change to address the specific issue at hand.

This change prevents a division by zero error when p.KY is 0.
@ggerganov ggerganov merged commit c4aed68 into ggerganov:master Dec 16, 2024
43 of 44 checks passed
bygreencn added a commit to bygreencn/whisper.cpp that referenced this pull request Dec 18, 2024
# By Georgi Gerganov (4) and others
# Via GitHub
* ggerganov/master:
  stream : improve consistency in README (ggerganov#2642)
  whisper : support no_speech_thold (ggerganov#2625)
  whisper : add single-timestamp logic (ggerganov#2629)
  readme : fix typo (ggerganov#2637)
  cmake : fix "amd64" processor string (ggerganov#2638)
  vulkan : fix soft_max.comp division by zero (ggerganov#2633)
  common : add cstdio header
  stream : update build instructions
  android : fix build and ci (ggerganov#2624)
  models : fix typo in download-ggml-model.sh (ggerganov#2623)
  ruby : Sync whisper.cpp and model download feature (ggerganov#2617)
  scripts : update to new build system

# Conflicts:
#	src/whisper.cpp
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
3 participants