openai / DALL-E

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

When I run this code in Google Colab it showing the error. #75

Open imostafizur opened 2 years ago

imostafizur commented 2 years ago

AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'. Can you please tell me why this error occurs?

nimeshkasun commented 2 years ago

I have the same error. @adityaramesh please help with this.

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!