Repository: pytorch/audio

Issue:
Use of deprecated `AutoNonVariableTypeMode`.
`AutoNonVariableTypeMode` is deprecated and will be removed in PyTorch 1.10.

https://github.com/pytorch/audio/search?q=AutoNonVariableTypeMode

Migration: https://github.com/pytorch/pytorch/blob/master/docs/cpp/source/notes/inference_mode.rst#migration-guide-from-autononvariabletypemode

cc @carolineechen 


Discussion:

Resolving patch:
diff --git a/torchaudio/__init__.py b/torchaudio/__init__.py
--- a/torchaudio/__init__.py
+++ b/torchaudio/__init__.py
@@ -32,12 +32,4 @@
     'list_audio_backends',
     'get_audio_backend',
     'set_audio_backend',
-    'save_encinfo',
-    'sox_signalinfo_t',
-    'sox_encodinginfo_t',
-    'get_sox_option_t',
-    'get_sox_encoding_t',
-    'get_sox_bool',
-    'SignalInfo',
-    'EncodingInfo',
 ]


Test patch:
diff --git a/test/torchaudio_unittest/models/wav2vec2/huggingface_intergration_test.py b/test/torchaudio_unittest/models/wav2vec2/huggingface_intergration_test.py
--- a/test/torchaudio_unittest/models/wav2vec2/huggingface_intergration_test.py
+++ b/test/torchaudio_unittest/models/wav2vec2/huggingface_intergration_test.py
@@ -86,7 +86,7 @@ def test_import(self, config):
         self.assertEqual(ref, hyp)
         # Feature projection
         x = torch.randn(3, 10, config['conv_dim'][-1])
-        ref = original.wav2vec2.feature_projection(x)
+        ref = original.wav2vec2.feature_projection(x)[0]
         hyp = imported.encoder.feature_projection(x)
         self.assertEqual(ref, hyp)
         # Convolutional Positional Encoder
diff --git a/test/torchscript_bc_test/README.md b/test/torchscript_bc_test/README.md
deleted file mode 100644
--- a/test/torchscript_bc_test/README.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# 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).
diff --git a/test/torchscript_bc_test/main.py b/test/torchscript_bc_test/main.py
deleted file mode 100755
--- a/test/torchscript_bc_test/main.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/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()
diff --git a/test/torchscript_bc_test/ver_060.py b/test/torchscript_bc_test/ver_060.py
deleted file mode 100644
--- a/test/torchscript_bc_test/ver_060.py
+++ /dev/null
@@ -1,71 +0,0 @@
-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)