Solved by tom in post #2 
              
              
                I think so, just do requires_grad_ on your input. In the end it goes through torchaudio.transforms.functional.spectrogram and uses the torch.stft function. This calls torch.fft (I think), which has a derivative defined. 
There are several texts about how the inner parts of PyTorch work, I wrote some…