SourceChangeWarning: source code of class ‘torch.nn.modules.loss.CrossEntropyLoss’ has changed

Hi everybody. Question regarding fast.ai and render.com

  1. I trained a model using crestle
  2. I exported the model to .pkl
  3. I put the .pkl file on dropbox
  4. I have a server load the pkl as per the instructions
  5. When I try to build the dockerfile, I get this error

/usr/local/lib/python3.7/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class ‘torch.nn.modules.loss.CrossEntropyLoss’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.7/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class ‘torch.nn.modules.conv.Conv2d’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.7/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class ‘torch.nn.modules.batchnorm.BatchNorm2d’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
/usr/local/lib/python3.7/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class ‘torch.nn.modules.activation.ReLU’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)

I have tried clicking export twice in crestle, as someone suggested ‘re-exporting.’ Did I misinterpret what ‘re-exporting’ means? Any ideas what is happening? My requirements.txt file looks like this:

aiofiles==0.4.0
aiohttp==3.5.4
asyncio==3.4.3
fastai==1.0.52
https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp37-cp37m-linux_x86_64.whl
numpy==1.16.3
starlette==0.12.0
uvicorn==0.7.1
python-multipart==0.0.5

1 Like

@alien35 - Were you able to solve this? I think it is due to the model being created with a different version of PyTorch…

Any update on solving this? I am experiencing a similar thing on Render. The app had been working since April when I originally deployed, now no longer working and getting similar errors.

I am also getting similar problems now … Has anyone above found a way to fix this issue?

Hey guys, yes I resolved this issue by making sure the package versions of my jupyter notebook used to generate the .pkl file match the package versions of the server used to read the .pkl file.

I am getting same error trying to run server.py in my local Mac machine. I am new to coding, can you give me steps to resolve above error