-
Notifications
You must be signed in to change notification settings - Fork 743
Closed
Description
InverseMelScale uses SGD inside so it does not work when the global context is no_grad or inference_mode. Or even when requires_grad=False would make it fail. This gives bad UX for inference.
There are couple of possible workarounds
- Clone Tensor with
requires_grad=Trueinside ofInverseMelScale - Use other method such as SVD. (there was some discussion InverseMelScale Implementation #366)
import torch
import torchaudio
trans = torchaudio.transforms.InverseMelScale(n_stft=10)
spec = torch.randn(128, 256, requires_grad=True)
trans(spec) # pass
with torch.inference_mode():
trans(spec) # fail
spec = torch.randn(128, 256, requires_grad=False)
trans(spec) # fail
with torch.inference_mode():
trans(spec) # failTraceback (most recent call last):
File "foo.py", line 10, in <module>
trans(spec)
File "/miniconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/Development/torchaudio/torchaudio/transforms.py", line 472, in forward
new_loss.backward()
File "/miniconda3/lib/python3.8/site-packages/torch/_tensor.py", line 307, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "/miniconda3/lib/python3.8/site-packages/torch/autograd/__init__.py", line 154, in backward
Variable._execution_engine.run_backward(
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
Metadata
Metadata
Assignees
Labels
No labels