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

AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' #54

Open
balakreshnan opened this issue Apr 8, 2022 · 6 comments

Comments

@balakreshnan
Copy link

When i install and ran the sample i am getting this error - AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
python 3.8

@thk-cheng
Copy link

thk-cheng commented Apr 8, 2022

Just found out a quick fix for this

Assuming you are working inside a virtual environment with python3.8 installed

  1. Head to ./lib/python3.8/site-packages/torch/nn/modules/upsampling.py
  2. Amend the forward method of the Upsample class as follows:
    def forward(self, input: Tensor) -> Tensor:
        return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
    
        # return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
        #                      recompute_scale_factor=self.recompute_scale_factor)
  3. Restart the ipykernel and the code should work again

Alternatively, downgrading Pytorch back to <= 1.10.0 would also do the trick. Check out #53 (comment) for more details.

@tobiaswuerth
Copy link

or see #53 (comment)

@mooooooood
Copy link

mooooooood commented Apr 10, 2022 via email

@pzarzycki
Copy link

Google Colab default environment throws that error as of May 2022

@Lexaul
Copy link

Lexaul commented Jun 30, 2022

Just found out a quick fix for this

Assuming you are working inside a virtual environment with python3.8 installed

  1. Head to ./lib/python3.8/site-packages/torch/nn/modules/upsampling.py
  2. Amend the forward method of the Upsample class as follows:
    def forward(self, input: Tensor) -> Tensor:
        return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
    
        # return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
        #                      recompute_scale_factor=self.recompute_scale_factor)
  3. Restart the ipykernel and the code should work again

Alternatively, downgrading Pytorch back to <= 1.10.0 would also do the trick. Check out #53 (comment) for more details.

This helps, ty

@digitalShaman
Copy link

The error
'Upsample' object has no attribute 'recompute_scale_factor'

is related to a change in the torch Upscale class from 1.10 to 1.11.

It appears that 'old' Upscale objects are saved within the model after this line of code:
model = load_model("https://cdn.openai.com/dall-e/decoder.pkl", 'cuda')
i used the following code immediatly after the load_model call to patch this:

# Patch for torch 1.11 and higher: replace the old Upsample object by the new version
# that exposes recompute_scale_factor
_ = model.blocks.group_1.upsample
model.blocks.group_1.upsample = torch.nn.Upsample(scale_factor = _.scale_factor, mode= _.mode)
_ = model.blocks.group_2.upsample
model.blocks.group_2.upsample = torch.nn.Upsample(scale_factor = _.scale_factor, mode= _.mode)
_ = model.blocks.group_3.upsample
model.blocks.group_3.upsample = torch.nn.Upsample(scale_factor = _.scale_factor, mode= _.mode)

and it's running fine with torch 1.12.1!

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