Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ConvTranspose1d' object has no attribute 'padding_mode' #182

Closed
sandipjedhe opened this issue Apr 10, 2019 · 9 comments
Closed

'ConvTranspose1d' object has no attribute 'padding_mode' #182

sandipjedhe opened this issue Apr 10, 2019 · 9 comments

Comments

@sandipjedhe
Copy link

I cloned latest repo, while trying inference.ipynb I got following error.


AttributeError Traceback (most recent call last)
in
1 with torch.no_grad():
----> 2 audio = waveglow.infer(mel_outputs_postnet, sigma=0.666)
3 ipd.Audio(audio[0].data.cpu().numpy(), rate=hparams.sampling_rate)

~/fabelizer/tacotron2/waveglow/glow_old.py in infer(self, spect, sigma)
171
172 def infer(self, spect, sigma=1.0):
--> 173 spect = self.upsample(spect)
174 # trim conv artifacts. maybe pad spec to kernel multiple
175 time_cutoff = self.upsample.kernel_size[0] - self.upsample.stride[0]

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
492 result = self._slow_forward(*input, **kwargs)
493 else:
--> 494 result = self.forward(*input, **kwargs)
495 for hook in self._forward_hooks.values():
496 hook_result = hook(self, input, result)

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/conv.py in forward(self, input, output_size)
640 def forward(self, input, output_size=None):
641 # type: (Tensor, Optional[List[int]]) -> Tensor
--> 642 if self.padding_mode != 'zeros':
643 raise ValueError('Only zeros padding mode is supported for ConvTranspose1d')
644

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in getattr(self, name)
538 return modules[name]
539 raise AttributeError("'{}' object has no attribute '{}'".format(
--> 540 type(self).name, name))
541
542 def setattr(self, name, value):

AttributeError: 'ConvTranspose1d' object has no attribute 'padding_mode'

@apsears
Copy link

apsears commented Apr 13, 2019

This must be a pytorch bug. I am currently using torch 1.1.0.dev20190411

It appears that Conv1d inherits from _ConvNd, and that _ConvNd is the source of the padding_mode property. But I don't know why the inherited value doesn't show up.

I commented out two sanity checks (looking for non 'zeroes') in ~/.local/lib/python3.6/site-packages/torch/nn/modules/conv.py

Then I forced the branch which concluded that the other checks for circular must be False on two others.

At that point, the code ran.

[Edit] Inference is all nan for the waveglow_old.pt file provided in this repo, but the waveglow_256channels.pt linked in the waveglow repo works!

@rafaelvalle
Copy link
Contributor

Closing due to inactivity.

@williamluke4
Copy link

williamluke4 commented May 13, 2019

Using torch 1.1.0.dev20190512 and waveglow_256channels.pt I was still getting this error. Following @apsears I managed to get it working. Here are the locations and changes required

site-packages/torch/nn/modules/conv.py line 190

 def forward(self, input):
        if False: # self.padding_mode == 'circular'
            expanded_padding = ((self.padding[0] + 1) // 2, self.padding[0] // 2)
            return F.conv1d(F.pad(input, expanded_padding, mode='circular'),
                            self.weight, self.bias, self.stride,
                            _single(0), self.dilation, self.groups)
        return F.conv1d(input, self.weight, self.bias, self.stride,
                        self.padding, self.dilation, self.groups)

site-packages/torch/nn/modules/conv.py line 641

    @weak_script_method
    def forward(self, input, output_size=None):
        # type: (Tensor, Optional[List[int]]) -> Tensor
        #if self.padding_mode != 'zeros':
        #    raise ValueError('Only `zeros` padding mode is supported for ConvTranspose1d')

        output_padding = self._output_padding(input, output_size, self.stride, self.padding, self.kernel_size)
        return F.conv_transpose1d(
            input, self.weight, self.bias, self.stride, self.padding,
            output_padding, self.groups, self.dilation)

@vitaly-zdanevich
Copy link

@rafaelvalle please reopen this issue, problem still exists, checked on Ubuntu 19.04 installing current versions of the packages from the pip.

@rafaelvalle
Copy link
Contributor

rafaelvalle commented May 18, 2019

iirc, this happens because the after some version pytorch adds 'padding_mode' to the attributes of Conv2d.

It can be fixed by getting the saved weights and setting them on a clean model:

model_state_dict = torch.load(model_path)['model'].state_dict()
model = WaveGlow(**waveglow_config)
model.load_state_dict(model_state_dict)
model.cuda()

@rafaelvalle
Copy link
Contributor

rafaelvalle commented May 28, 2019

This probably also works:

for m in model.modules():
    if 'Conv' in str(type(m)):
        setattr(m, 'padding_mode', 'zeros')

@engmubarak48
Copy link

This probably also works:

for m in model.modules():
    if 'Conv' in str(type(m)):
        setattr(m, 'padding_mode', 'zeros')

Where to put this text of code.

@engmubarak48
Copy link

following @apsears and running this script from the terminal under tacotron2 folder helped me solve my problem.

cd waveglow/
git pull origin master

@ABexit
Copy link

ABexit commented Jul 21, 2020

This probably also works:
for m in model.modules():
if 'Conv' in str(type(m)):
setattr(m, 'padding_mode', 'zeros')

Where to put this text of code.

Which can be added under:

        for k in waveglow.convinv:
                   k.float()

It will work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants