Skip to content

Accept negative-stride NumPy audio in log-Mel conversion - #2881

Open
ktz03 wants to merge 1 commit into
openai:mainfrom
ktz03:fix/negative-stride-audio-1246
Open

ktz03 wants to merge 1 commit into
openai:mainfrom
ktz03:fix/negative-stride-audio-1246

Conversation

@ktz03

@ktz03 ktz03 commented Oct 9, 2026

Copy link
Copy Markdown

log_mel_spectrogram accepts NumPy waveforms, but a reversed or negatively strided view currently fails in torch.from_numpy before computing the spectrogram. An equivalent contiguous array works:

import numpy as np
import whisper

time = np.arange(3200, dtype=np.float32) / 16000
audio = np.sin(2 * np.pi * 440 * time).astype(np.float32)[::-1]
whisper.log_mel_spectrogram(audio)

Copy the waveform only when it has a negative stride before converting it to a tensor. Contiguous and positive-stride arrays retain the existing conversion path. The added regressions compare positive and negative strides with the same waveform values for both 80 and 128 Mel filters, and check the input, output dtype, and CPU device.

Validation on Windows, Python 3.12.14, PyTorch 2.14.1+cpu, NumPy 2.5.3:

  • The new regressions fail 4 cases on unmodified main and pass all 8 with the fix; the 4 positive-stride controls pass on both.
  • pytest tests/test_audio.py -q: 9 passed, including the bundled audio file decoded with FFmpeg.
  • The CPU test selection from .github/workflows/test.yml: 27 passed, 20 deselected, with the expected 2 CPU FP16 fallback warnings. This includes real tiny and tiny.en transcription with word timestamps using the official weights, verified against their SHA256 hashes.
  • The repository's pinned pre-commit run --all-files: passed.

GPU execution, other model sizes, the complete Python/PyTorch CI matrix, and performance were not tested locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T13:54:56.335961Z af031cc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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