1

Is it possible to run TensorFlow.js (the Node.js version - tfjs-node) on AWS Lambda? I tried to deploy tfjs-node as AWS Lambda Layer but it exceeds allowed 256 MB size limit.

Arpit Jain
  • 1,217
  • 8
  • 27

3 Answers3

1

Finally I managed to deploy one of the previous versions (1.1.2) of tfjs-node to AWS Lambda Layers. Apparently this is a last version that is small enough to get it out there.

To build it yourself you can use following script. You will need to have Docker installed on your machine to build it for AWS Linux:

#!/bin/sh

# cleaning previous build
rm -rf ./layer

# installing tfjs-node with docker
docker run --rm -v $PWD:/var/task lambci/lambda:build-nodejs12.x npm install @tensorflow/tfjs-node@1.1.2 --no-package-lock --prefix layer/nodejs

# zipping layer
cd ./layer && zip -qrX ./tfjs-node-layer.zip .

# removing unzipped module
rm -rf ./layer/nodejs

This will create ./layers/tfjs-node-layer.zip in your working dir. You will need upload it to s3 bucket and create new AWS Lambda Layer from the s3 bucket URL.

1

AWS Lambda functions can mount EFS (since June 2020). You can load libraries or packages that are larger than the 250 MB package deployment size limit of AWS Lambda using EFS.

Detailed steps on how to set it up are here: https://aws.amazon.com/blogs/aws/new-a-shared-file-system-for-your-lambda-functions/

hben
  • 35
  • 5
1

Yes, it is possible to run TensorFlow.js (the Node.js version - tfjs-node) on AWS Lambda by deploying it as a container image using Amazon Elastic Container Registry (ECR). Unlike Lambda layers, container images can have a maximum size limit of 10GB, which allows for the deployment of larger packages such as tfjs-node.

To deploy the container image to Lambda, you can follow the steps outlined in the official AWS Lambda documentation for creating container images: https://docs.aws.amazon.com/lambda/latest/dg/images-create.html. Once the container image is created and pushed to ECR, you can then configure Lambda to use it as the execution environment.

By using a container image, you can easily use even very large models in Lambda with tfjs-node.

Miki
  • 11
  • 2