Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

conftest.py 1.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  1. # Copyright (c) Meta Platforms, Inc. and affiliates
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the
  5. # MIT_LICENSE file in the root directory of this source tree.
  6. import tempfile
  7. from argparse import ArgumentTypeError
  8. from typing import cast
  9. from urllib.request import urlretrieve
  10. import pytest
  11. import torch
  12. from fairseq2.data.audio import AudioDecoder, AudioDecoderOutput
  13. from fairseq2.memory import MemoryBlock
  14. from fairseq2.typing import Device
  15. import tests.common
  16. def parse_device_arg(value: str) -> Device:
  17. try:
  18. return Device(value)
  19. except RuntimeError:
  20. raise ArgumentTypeError(f"'{value}' is not a valid device name.")
  21. def pytest_addoption(parser: pytest.Parser) -> None:
  22. # fmt: off
  23. parser.addoption(
  24. "--device", default="cpu", type=parse_device_arg,
  25. help="device on which to run tests (default: %(default)s)",
  26. )
  27. # fmt: on
  28. def pytest_sessionstart(session: pytest.Session) -> None:
  29. tests.common.device = cast(Device, session.config.getoption("device"))
  30. @pytest.fixture(scope="module")
  31. def example_rate16k_audio() -> AudioDecoderOutput:
  32. url = "https://dl.fbaipublicfiles.com/seamlessM4T/LJ037-0171_sr16k.wav"
  33. audio_decoder = AudioDecoder(dtype=torch.float32, device=tests.common.device)
  34. with tempfile.NamedTemporaryFile() as f:
  35. urlretrieve(url, f.name)
  36. with open(f.name, "rb") as fb:
  37. block = MemoryBlock(fb.read())
  38. decoded_audio = audio_decoder(block)
  39. return decoded_audio
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...