How to deploy Deep Learning models on AWS Lambda where models weights are more than 400 MB?

Viewed 30

I have an app working in FastAPI already. To cut the costs, I'm trying to shift everything to Lambda. The problem is that when I zip code + dependencies + model weights, it becomes a 700MB file and Lambda accepts 50 MB. I tried uploading it to S3 also but while adding the link to Lambda runtime, it throws an error as:

Unzipped size must be smaller than 262144000 bytes

There's a way around that I copy and paste model's weight using boto3 just when the script runs but it'll mean that with every initiation, my model weights will be copied, with each call until the code is running. Copying and loading the 400 MB model will be a slow process.

Since there's no support for Docker directly on Lambda Runtime, I found out that you can use mangum with Docker. If I use docker, it'll install dependencied + copy model weights from the URL everytime the function is called.

What would be a good way for this process?

1 Answers

Multiple options are there

  1. Using Amazon Elastic File System (EFS) - EFS is to mount a file system directly to the Lambda function, and the files can be accessed using standard file operations
  2. Using S3 to large files - Download that during runtime rather than building as part of lambda package itself
  3. Last but best, use lambda code as container images instead of zip files. Container images support code sizes upto 10 GB
Related