AttributeError: 'WeightDropout' object has no attribute '_do_nothing'

Hi, I’m trying to serve inference on a model trained by the current version of fastai.
Of course, I could try to update the version of the stack used on the docker image to serve inference, but changing just one version of a stack’s component would mean facing compatibility issues on another component and so on.

Any hint on the cause of this problem ?

/usr/local/lib/python3.7/site-packages/torch/serialization.py:453: 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:453: SourceChangeWarning: source code of class 'fastai.text.learner.MultiBatchEncoder' 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:453: SourceChangeWarning: source code of class 'fastai.text.models.awd_lstm.AWD_LSTM' 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:453: SourceChangeWarning: source code of class 'fastai.text.models.awd_lstm.EmbeddingDropout' 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:453: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' 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:453: SourceChangeWarning: source code of class 'fastai.text.models.awd_lstm.WeightDropout' 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:453: SourceChangeWarning: source code of class 'torch.nn.modules.rnn.LSTM' 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)
Traceback (most recent call last):
  File "app.py", line 148, in <module>
    load_model()  # load model at the beginning once only
  File "app.py", line 47, in load_model
    learn = load_learner(path, export_file_name)
  File "/usr/local/lib/python3.7/site-packages/fastai/basic_train.py", line 598, in load_learner
    state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
  File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 386, in load
    return _load(f, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 573, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 591, in __getattr__
    type(self).__name__, name))
AttributeError: 'WeightDropout' object has no attribute '_do_nothing'

Here is the stack used for the docker image :

Flask==1.0.2
numpy==1.16.3
scikit-learn==0.20.2
fastai==1.0.52
torch==1.2.0
pillow~=6.0
python-multipart==0.0.5

Dockerfile :

FROM python:3.7
ADD ./requirements.txt /deploy/
WORKDIR /deploy/
RUN pip install --upgrade pip && pip install --default-timeout=300 --no-cache-dir --no-use-pep517 -r requirements.txt
COPY ./app.py /deploy/
COPY ./export.pkl /deploy/
EXPOSE 80
ENTRYPOINT [“python”, “app.py”]

Regards,
Alexandre.

Ok, found it.

For those how encounter this kind of problems, get to the fastai repository and search the function that triggered the exception. Here it was “_do_nothing”.

Click on the file that contains the definition of _do_nothing

Click on the history button.

For each comit, click the button that would show the diff to get file modification and look for the appearence of “_do_nothing” :

Luckily for me, that was the first file in the list :
do nothing

Here is an updated working stack for docker inference :

Flask==1.0.2
numpy==1.16.3
scikit-learn==0.20.2
fastai==1.0.61
torch==1.5.0
pillow~=6.0
python-multipart==0.0.5