Skip to content

Commit

Permalink
feat: add tests for MacOS whisper MPS functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Feb 1, 2025
1 parent e0d56f3 commit f9fb85d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transcribe_anything/insanely_fast_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def run_insanely_fast_whisper(
if sys.platform == "darwin":
# Attempts fixed recommended for the mps machines. This seems
# to be necessary since a recent update.
env["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "1.9"
env["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "7"
env["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
device_id = get_device_id()
cmd_list = []
Expand Down
42 changes: 42 additions & 0 deletions tests/test_insanely_fast_whisper_mps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Tests transcribe_anything
"""

# pylint: disable=bad-option-value,useless-option-value,no-self-use,protected-access,R0801
# flake8: noqa E501

import os
import shutil
import unittest
from pathlib import Path


from transcribe_anything.util import is_mac_arm
from transcribe_anything.whisper_mac import run_whisper_mac_english

HERE = Path(os.path.abspath(os.path.dirname(__file__)))
LOCALFILE_DIR = HERE / "localfile"
TESTS_DATA_DIR = LOCALFILE_DIR / "text_video_insane" / "en"
TEST_WAV = LOCALFILE_DIR / "video.wav"

CAN_RUN_TEST = is_mac_arm()


class MacOsWhisperMpsTester(unittest.TestCase):
"""Tester for transcribe anything."""

@unittest.skipUnless(CAN_RUN_TEST, "Not mac")
def test_local_file(self) -> None:
"""Check that the command works on a local file."""
shutil.rmtree(TESTS_DATA_DIR, ignore_errors=True)
run_whisper_mac_english(
input_wav=TEST_WAV,
model="small",
output_dir=TESTS_DATA_DIR,
)




if __name__ == "__main__":
unittest.main()

0 comments on commit f9fb85d

Please sign in to comment.