Skip to content

Commit

Permalink
allow_pickle=False while loading of mel matrix IN audio.py (#1511)
Browse files Browse the repository at this point in the history
* Update audio.py

 The `mel_filters` function is using a `np.load` function to load a pre-computed mel filterbank matrix. This function is not thread-safe, which means that if it is called from multiple threads at the same time, it may corrupt the data.

To fix this, you can use the `torch.load` function instead. This function is thread-safe, so it will not corrupt the data if it is called from multiple threads at the same time.

* Update audio.py

updated the docstring

* allow_pickle=False

* newline

---------

Co-authored-by: Jong Wook Kim <[email protected]>
Co-authored-by: Jong Wook Kim <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent b7d277a commit 7dfcd56
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions whisper/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def mel_filters(device, n_mels: int = N_MELS) -> torch.Tensor:
)
"""
assert n_mels == 80, f"Unsupported n_mels: {n_mels}"
with np.load(
os.path.join(os.path.dirname(__file__), "assets", "mel_filters.npz")
) as f:

filters_path = os.path.join(os.path.dirname(__file__), "assets", "mel_filters.npz")
with np.load(filters_path, allow_pickle=False) as f:
return torch.from_numpy(f[f"mel_{n_mels}"]).to(device)


Expand Down

0 comments on commit 7dfcd56

Please sign in to comment.