"docs/git@developer.sourcefind.cn:OpenDAS/torchaudio.git" did not exist on "ef1ba56ff7177868df588636bf994526444eca64"
Unverified Commit 533c2d47 authored by moto's avatar moto Committed by GitHub
Browse files

Remove unused stuff (#1588)

parent 3f0febc4
# note dist: 'trusty' does not work here
dist: xenial
language: python
# cache miniconda installer and similar files
cache:
directories:
- /home/travis/download
# This matrix tests that the code works on Python 3.5, 3.6, 3.7, passes
# lint and example tests.
matrix:
fast_finish: true
include:
- env: PYTHON_VERSION="3.6" RUN_EXAMPLE_TESTS="true" SKIP_TESTS="true"
allow_failures:
- env: PYTHON_VERSION="3.6" RUN_EXAMPLE_TESTS="true" SKIP_TESTS="true"
addons:
apt:
packages:
sox
libsox-dev
libsox-fmt-all
portaudio19-dev
notifications:
email: false
install: source build_tools/travis/install.sh
script: bash build_tools/travis/test_script.sh
# Torchscript Backward Compatibility Test Suite
This directory contains tools to generate Torchscript object of a specific torchaudio version (given that you have the corresponding environments setup correctly) and validate it in the current version.
## Usage
### Generate torchscript object
```
./main.py --mode generate --version 0.6.0
```
will generate Torchscript dump files in [`assets`](./assets/) directory. This requries your Python runtime to have torchaudio `0.6.0`.
### Validate torchscript object
```
./main.py --mode validate --version 0.6.0
```
will validate if the Torchscript files created in the previous step are compatible with the version of torchaudio available in your environment (master).
#!/usr/bin/env python3
"""Generate torchscript object of specific torhcaudio version.
This requires that the corresponding torchaudio (and torch) is installed.
"""
import os
import sys
import argparse
_BASE_OBJ_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'assets')
def _parse_args():
parser = argparse.ArgumentParser(
description=__doc__
)
parser.add_argument(
'--mode', choices=['generate', 'validate'], required=True,
help=(
'"generate" generates Torchscript objects of the specific torchaudio '
'in the given directory. '
'"validate" validates if the objects in the givcen directory are compatible '
'with the current torhcaudio.'
)
)
parser.add_argument(
'--version', choices=['0.6.0'], required=True,
help='torchaudio version.'
)
parser.add_argument(
'--base-obj-dir', default=_BASE_OBJ_DIR,
help='Directory where objects are saved/loaded.'
)
return parser.parse_args()
def _generate(version, output_dir):
if version == '0.6.0':
import ver_060
ver_060.generate(output_dir)
else:
raise ValueError(f'Unexpected torchaudio version: {version}')
def _validate(version, input_dir):
if version == '0.6.0':
import ver_060
ver_060.validate(input_dir)
else:
raise ValueError(f'Unexpected torchaudio version: {version}')
def _get_obj_dir(base_dir, version):
py_version = f'{sys.version_info.major}.{sys.version_info.minor}'
return os.path.join(base_dir, f'{version}-py{py_version}')
def _main():
args = _parse_args()
obj_dir = _get_obj_dir(args.base_obj_dir, args.version)
if args.mode == 'generate':
_generate(args.version, obj_dir)
elif args.mode == 'validate':
_validate(args.version, obj_dir)
else:
raise ValueError(f'Unexpected mode: {args.mode}')
if __name__ == '__main__':
_main()
import os
import tempfile
from typing import Optional
from packaging import version
import torch
import torchaudio
_MIN_VER = version.parse('0.6.0a0')
_MAX_VER = version.parse('0.7.0')
_RUNTIME_VER = version.parse(torchaudio.__version__)
def info(filepath: str) -> torchaudio.backend.sox_io_backend.AudioMetaData:
return torchaudio.info(filepath)
def load(
filepath: str,
frame_offset: int,
num_frames: int,
normalize: bool,
channels_first: bool):
return torchaudio.load(filepath, frame_offset, num_frames, normalize, channels_first)
def save(
filepath: str,
tensor: torch.Tensor,
sample_rate: int,
channels_first: bool = True,
compression: Optional[float] = None,
):
torchaudio.save(filepath, tensor, sample_rate, channels_first, compression)
def generate(output_dir):
if not (_MIN_VER <= _RUNTIME_VER < _MAX_VER):
raise RuntimeError(f'Invalid torchaudio runtime version: {_RUNTIME_VER}')
torchaudio.set_audio_backend('sox_io')
funcs = [
info,
load,
save,
]
os.makedirs(output_dir, exist_ok=True)
for func in funcs:
torch.jit.script(func).save(os.path.join(output_dir, f'{func.__name__}.zip'))
def validate(input_dir):
torchaudio.set_audio_backend('sox_io')
# See https://github.com/pytorch/pytorch/issues/42258
# info_ = torch.jit.load(os.path.join(input_dir, 'info.zip'))
load_ = torch.jit.load(os.path.join(input_dir, 'load.zip'))
save_ = torch.jit.load(os.path.join(input_dir, 'save.zip'))
sample_rate = 44100
normalize = True
channels_first = True
with tempfile.TemporaryDirectory() as temp_dir:
temp_file = os.path.join(temp_dir, 'test.wav')
temp_data = torch.rand(2, sample_rate, dtype=torch.float32)
save_(temp_file, temp_data, sample_rate, channels_first, 0.)
# info_(temp_file)
load_(temp_file, 0, -1, normalize, channels_first)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment