openai / DALL-E

PyTorch package for the discrete VAE used for DALL·E.
Other
10.77k stars 1.94k forks source link

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

Open balakreshnan opened 2 years ago

balakreshnan commented 2 years ago

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 commented 2 years ago

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.

tobiaswuerth commented 2 years ago

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

mooooooood commented 2 years ago

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: @.***>

pzarzycki commented 2 years ago

Google Colab default environment throws that error as of May 2022

Lexaul commented 2 years ago

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 commented 2 years ago

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!