Getting AttributeError: 'SGD' object has no attribute 'defaults' in SimSwap Colab

5.1k views Asked by At

I'm new to using python and code based programming language, but I'm trying to branch out by using Colab programs in an effort to understand a little of the application. I've been using this Colab for a little while (I don't have a GPU that can run it locally atm), but recently it began giving me this error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-46a887c84c9b> in <module>
     14 
     15 torch.nn.Module.dump_patches = True
---> 16 model = create_model(opt)
     17 model.eval()
     18 

5 frames
/usr/local/lib/python3.8/dist-packages/torch/optim/optimizer.py in __setstate__(self, state)
     82         self.__dict__.update(state)
     83         self._hook_for_profile()  # To support multiprocessing pickle/unpickle.
---> 84         self.defaults.setdefault('differentiable', False)
     85 
     86     def __repr__(self):

AttributeError: 'SGD' object has no attribute 'defaults'

I'm trying to understand if it's a matter of changing the code or a version issue. Is this fixable on my end or do I need to wait for a version update (or to run back to a previous version?)

I found someone here that was getting a similar error, but didn't really understand his fix. I tried erasing line 16 to the end of the cell, but those obviously need to be there to some extent. I researched "SGD", but didn't get very far before I realized there are a lot of "attributeError"s to choose from so came here hoping that I could get some insight into the problem with this code (or maybe myself. lol)

Thank you for helping out a newbie.

Guts

3

There are 3 answers

1
Nelson On

I am a new user. I found an answer that fixes the problem. I hope it helps.

https://github.com/neuralchen/SimSwap/issues/357

user name: amfapic

You should try previous pytorch versions (< 1.13):

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

0
orlandoMG On

EDIT: as of now feb 22 place this line of code first on the installation cell, run it

!pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 torchtext==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

then restart your runtime and its good to go

1
Monarch sung jin-woo On
!pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 torchtext==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
!pip install insightface==0.2.1 onnxruntime moviepy
!pip install googledrivedownloader
!pip install --upgrade "imageio>=2.5"

replace with these