Deployment Platform: AWS Lambda

I had the exact same problem and downgrading to torch 1.1.0 solved it. I think the format of the jit trace file changed between pytorch versions.

To downgrade for this export without breaking my fastai2 install, I made a new conda environment as follows:

conda create -n pytorch11 python=3.6 pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0
conda activate pytorch11
conda install -c pytorch -c fastai fastai pytorch=1.1.0 torchvision=0.3.0 cuda100 jupyter jupyterlab
conda install boto3
jupyter notebook password
jupyter notebook --ip=10.0.1.100
python -c “import torch; print(torch.version)” # this command should print 1.1.0

I then imported the old model in jupyter notebook with:
from fastai.vision import *
classes = [‘Anger’, ‘Disgust’, ‘Surprise’, ‘Sadness’, ‘Happiness’, ‘Neutral’, ‘Contempt’, ‘Fear’]
data = ImageDataBunch.single_from_classes(’’, classes, ds_tfms=None)
learner = cnn_learner(data, models.resnet34)
learner.load(‘gokul-sentiment-stage-5n’)

… and from here on I followed the description on https://course.fast.ai/deployment_aws_lambda.html from “Export your trained model and upload to S3”.