DALL-E icon indicating copy to clipboard operation
DALL-E copied to clipboard

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

Open balakreshnan opened this issue 2 years ago • 6 comments

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

balakreshnan avatar Apr 08 '22 11:04 balakreshnan

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 https://github.com/openai/DALL-E/issues/53#issuecomment-1090168903 for more details.

thk-cheng avatar Apr 08 '22 12:04 thk-cheng

or see https://github.com/openai/DALL-E/issues/53#issuecomment-1090168903

tobiaswuerth avatar Apr 09 '22 06:04 tobiaswuerth

You need to select the appropriate pytorch version number according to your own graphics card driver and CUDA version,that's all

------------------ 原始邮件 ------------------ 发件人: "openai/DALL-E" @.>; 发送时间: 2022年4月8日(星期五) 晚上7:29 @.>; @.***>; 主题: [openai/DALL-E] AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' (Issue #54)

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

mooooooood avatar Apr 10 '22 05:04 mooooooood

Google Colab default environment throws that error as of May 2022

pzarzycki avatar May 24 '22 15:05 pzarzycki

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

Lexaul avatar Jun 30 '22 08:06 Lexaul

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!

digitalShaman avatar Aug 27 '22 13:08 digitalShaman