0

All I'm trying to do is create a flask app for Places365 and deploy it as an AWS Lambda with API. While everything works fine on my EC-2 instance, Lambda keeps failing with "No module named 'torch': ModuleNotFoundError" error.

Initially, when I tried to include the torch as part of my virtual environment, Lambda kept failing with "No space left" error. So, I uninstalled torch from my virtual environment, redeployed the function and added PyTorch layer (arn:aws:lambda:us-east-1:934676248949:layer:pytorchv1-py36:2) to the function. Still, it fails with "No module named 'torch': ModuleNotFoundError" error

Also, I used Zappa for Lambda deployment

It would be great if someone can share their experience of deploying torch to Lambda

jon
  • 429
  • 6
  • 15
  • Could you show us your Lambda? I don't understand how you `include the torch as part of my virtual environment`. – LiuChang Nov 08 '19 at 05:10
  • And the `No space left` error is caused by disk space restriction. [AWS Lambda No Space Left on Device error](https://stackoverflow.com/questions/48347350/aws-lambda-no-space-left-on-device-error?rq=1) – LiuChang Nov 08 '19 at 05:13
  • Were you able to resolve this? I am also trying to use that pytorch layer in a Zappa app. Did you add the layer manually in the AWS console for your Lambda function? – mihow Feb 03 '20 at 06:16
  • @mihow Yes. Pls see my answer below. – jon Feb 05 '20 at 03:26

1 Answers1

1

I was able to fix it. Below is what I did

ARN of pytorch layer that I used: arn:aws:lambda:us-east-1:934676248949:layer:pytorchv1-py36:2

Added the following code to my python Lambda function

  sys.path.insert(1, '/opt')
  import unzip_requirements
  import torch
jon
  • 429
  • 6
  • 15