Skip to content

Commit acc421e

Browse files
ebsmothersfacebook-github-bot
authored andcommitted
Remaining fixes to unblock nightly build (#504)
Summary: Two more changes to fix our nightly builds: 1) Add \_\_init\_\_.py to `torchmultimodal/models/video_gpt/` to fix import failures. 2) Define a new test util to skip unit tests if ffmpeg is not installed. Per discussions with mthrok torchaudio does not come with ffmpeg installed, though when we use conda install it will be included with torchvision. As a result, the pip install command in our nightly builds does not have ffmpeg, which causes some of our audio MAE transform tests to fail. We also do not want to install it directly with our library due to licensing. As a result, we add a test utility to skip these tests if ffmpeg is not installed. Pull Request resolved: #504 Test Plan: Create a new conda env and follow the steps in nightly_build.yaml to install our deps with pip (so no ffmpeg). ``` conda create -n tmm-10-24-23-no-ffmpeg python=3.8 conda activate tmm-10-24-23-no-ffmpeg python -m pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu python -m pip install -r requirements.txt python -m pip install pytest pytest-mock pytest-cov python -m pytest -v tests/transforms ... ============ 58 passed, 7 skipped in 2.79s ========= ``` Also confirmed that by removing one of the `skip_if_no_mmpeg` decorator from one of the tests in the same environment causes it to fail. Reviewed By: rohan-varma Differential Revision: D50613602 Pulled By: ebsmothers fbshipit-source-id: e4d5c96911c7b2204f62318c0737c1cdfb3bd0fd
1 parent 2155161 commit acc421e

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

tests/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,10 @@ def fixed_init_model(
286286
dtype=param.dtype,
287287
)
288288
)
289+
290+
291+
def skip_if_no_ffmpeg(message="Requires ffmpeg"):
292+
import importlib
293+
294+
ffmpeg_spec = importlib.util.find_spec("ffmpeg")
295+
return pytest.mark.skipif(ffmpeg_spec is None, reason=message)

tests/transforms/test_mae_transform.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import pytest
1111
import torch
1212
from PIL import Image
13-
from tests.test_utils import assert_expected, get_asset_path, set_rng_seed
13+
from tests.test_utils import (
14+
assert_expected,
15+
get_asset_path,
16+
set_rng_seed,
17+
skip_if_no_ffmpeg,
18+
)
1419
from torchmultimodal.transforms.mae_transform import (
1520
AudioEvalTransform,
1621
AudioFineTuneTransform,
@@ -275,11 +280,13 @@ class TestAudioEvalTransform:
275280
def transform(self):
276281
return AudioEvalTransform()
277282

283+
@skip_if_no_ffmpeg()
278284
def test_transform(self, transform, wav):
279285
actual = transform(wav)
280286
assert_expected(actual.size(), (1, 1024, 128))
281287
assert_expected(actual.sum().item(), 52000.8828, atol=0.0001, rtol=0.0)
282288

289+
@skip_if_no_ffmpeg()
283290
def test_transform_list(self, transform, wav):
284291
actual = transform([wav])
285292
assert_expected(actual.size(), (1, 1, 1024, 128))
@@ -295,11 +302,13 @@ def set_seed(self):
295302
def transform(self):
296303
return AudioPretrainTransform()
297304

305+
@skip_if_no_ffmpeg()
298306
def test_transform(self, transform, wav):
299307
actual = transform(wav)
300308
assert_expected(actual.size(), (1, 1024, 128))
301309
assert_expected(actual.sum().item(), 52072.4531, atol=0.0001, rtol=0.0001)
302310

311+
@skip_if_no_ffmpeg()
303312
def test_transform_list(self, transform, wav):
304313
actual = transform([wav])
305314
assert_expected(actual.size(), (1, 1, 1024, 128))
@@ -316,16 +325,19 @@ def set_seed(self):
316325
def transform(self):
317326
return AudioFineTuneTransform()
318327

328+
@skip_if_no_ffmpeg()
319329
def test_transform(self, transform, wav):
320330
actual = transform(wav)
321331
assert_expected(actual.size(), (1, 1024, 128))
322332
assert_expected(actual.sum().item(), 53656.75, atol=0.0001, rtol=0.0001)
323333

334+
@skip_if_no_ffmpeg()
324335
def test_transform_list(self, transform, wav):
325336
actual = transform([wav])
326337
assert_expected(actual.size(), (1, 1, 1024, 128))
327338
assert_expected(actual.sum().item(), 53656.75, atol=0.0001, rtol=0.0001)
328339

340+
@skip_if_no_ffmpeg()
329341
def test_transform_with_mixup(self, transform, wav):
330342
with open(get_asset_path("sinewave.wav"), "rb") as f:
331343
bfr = f.read()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.

0 commit comments

Comments
 (0)