Repository: pytorch/audio

Issue #121: Cannot import torchaudio with torch 1.1
Created: 2019-06-07T15:53:10Z
I am trying to use torchaudio with torch 1.1.
It compiled successfully with Python 3.6, but when I want to import the torchaudio package, I get this error:
>>> import torchaudio
Traceback (most recent call last):
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/annotations.py", line 95, in parse_type_line
    arg_ann = eval(arg_ann_str, _eval_env)
  File "<string>", line 1, in <module>
NameError: name 'Optional' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/__init__.py", line 7, in <module>
    from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/transforms.py", line 6, in <module>
    from . import functional as F
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/functional.py", line 108, in <module>
    @torch.jit.script
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/__init__.py", line 824, in script
    fn = torch._C._jit_script_compile(ast, _rcb, get_default_args(obj))
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/annotations.py", line 55, in get_signature
    return parse_type_line(type_line)
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/annotations.py", line 97, in parse_type_line
    raise RuntimeError("Failed to parse the argument list of a type annotation: {}".format(str(e)))
RuntimeError: Failed to parse the argument list of a type annotation: name 'Optional' is not defined

It ran fine on torch 1.0 - maybe some problem with differing source code between torch 1.0 and 1.1?

Duplicate issue #123: torch.jit.frontend.UnsupportedNodeError: ListComp aren't supported
Created: 2019-06-11T09:47:12Z
Hi, I’m trying to use torchaudio with Python 3.6, torch 1.0.0 and CUDA-10.0.
I followed the README, but I get the error below:
>>> import torchaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/asc/audio/torchaudio/__init__.py", line 7, in <module>
    from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy
  File "/root/asc/audio/torchaudio/transforms.py", line 6, in <module>
    from . import functional as F
  File "/root/asc/audio/torchaudio/functional.py", line 40, in <module>
    @torch.jit.script
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/__init__.py", line 689, in script
    ast = get_jit_ast(fn, is_method=False)
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 147, in get_jit_ast
    return build_def(ctx, py_ast.body[0], type_line, is_method)
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 182, in build_def
    build_stmts(ctx, body))
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 124, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 124, in <listcomp>
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 163, in __call__
    return method(ctx, node)
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 312, in build_If
    build_stmts(ctx, stmt.body),
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 124, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 124, in <listcomp>
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 163, in __call__
    return method(ctx, node)
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 245, in build_Assign
    rhs = build_expr(ctx, stmt.value)
  File "/opt/conda/lib/python3.6/site-packages/torch/jit/frontend.py", line 162, in __call__
    raise UnsupportedNodeError(ctx, node)
torch.jit.frontend.UnsupportedNodeError: ListComp aren't supported
        fill_value (float): Value to fill in

    Outputs:
        Tensor: Padded/trimmed tensor
    """
    if max_len > tensor.size(len_dim):
        # array of [padding_left, padding_right, padding_top, padding_bottom]
        # so pad similar to append (aka only right/bottom) and do not pad
        # the length dimension. assumes equal sizes of padding.
        padding = [max_len - tensor.size(len_dim)
                   ~ <--- HERE
                   if (i % 2 == 1) and (i // 2 != len_dim)
                   else 0
                   for i in [0, 1, 2, 3]]
        # TODO add "with torch.no_grad():" back when JIT supports it
        tensor = torch.nn.functional.pad(tensor, padding, "constant", fill_value)
    elif max_len < tensor.size(len_dim):
        tensor = tensor.narrow(len_dim, 0, max_len)
    return tensor


How can I work it?

Closing comment (2019-06-12T23:52:09Z): @siida36
First of all, I was experiencing an error related to #121, not the error you mentioned.
My environment is basically based on Deep Learning AMI for AWS EC2.
Specifically PyTorch 1.1, Cuda 10.0, Python 3.6.5, and Ubuntu 18.04 (LTS).
If there are any differences from the commands you provided, I used git checkout, uninstalled torchaudio and then reinstalled.
I hope this helps you.