{"id":13578313,"url":"https://github.com/szymonmaszke/torchlambda","last_synced_at":"2025-04-13T06:35:36.262Z","repository":{"id":43776966,"uuid":"242344456","full_name":"szymonmaszke/torchlambda","owner":"szymonmaszke","description":"Lightweight tool to deploy PyTorch models to AWS Lambda","archived":false,"fork":false,"pushed_at":"2021-11-17T19:35:05.000Z","size":445,"stargazers_count":125,"open_issues_count":9,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-24T09:17:09.418Z","etag":null,"topics":["aws","aws-cli","aws-lambda","cli","cmake","cpp","deep-learning","deployment","docker","lambda","libtorch","lightweight","machine-learning","minimalistic","performance","production","python","pytorch","torchscript","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/szymonmaszke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-22T13:15:27.000Z","updated_at":"2024-08-09T19:58:19.000Z","dependencies_parsed_at":"2022-09-03T13:53:12.128Z","dependency_job_id":null,"html_url":"https://github.com/szymonmaszke/torchlambda","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szymonmaszke%2Ftorchlambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szymonmaszke%2Ftorchlambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szymonmaszke%2Ftorchlambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szymonmaszke%2Ftorchlambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szymonmaszke","download_url":"https://codeload.github.com/szymonmaszke/torchlambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675201,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cli","aws-lambda","cli","cmake","cpp","deep-learning","deployment","docker","lambda","libtorch","lightweight","machine-learning","minimalistic","performance","production","python","pytorch","torchscript","yaml"],"created_at":"2024-08-01T15:01:29.370Z","updated_at":"2025-04-13T06:35:36.234Z","avatar_url":"https://github.com/szymonmaszke.png","language":"Python","readme":"\u003cimg align=\"left\" width=\"256\" height=\"256\" src=\"https://github.com/szymonmaszke/torchlambda/blob/master/assets/banner.png\"\u003e\n\n[__torchlambda__](https://github.com/szymonmaszke/torchlambda/wiki) is a tool to deploy [PyTorch](https://pytorch.org/) models\non [Amazon's AWS Lambda](https://aws.amazon.com/lambda/) using [AWS SDK for C++](https://aws.amazon.com/sdk-for-cpp/)\nand [custom C++ runtime](https://github.com/awslabs/aws-lambda-cpp).\n\nUsing statically compiled dependencies __whole package is shrunk to only `30MB`__.\n\nDue to small size of compiled source code users can pass their models as [AWS Lambda layers](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html).\n__Services like [Amazon S3](https://aws.amazon.com/s3/) are no longer necessary to load your model__.\n\n[__torchlambda__](https://github.com/szymonmaszke/torchlambda/wiki) has it's PyTorch \u0026 AWS dependencies always tested \u0026 up to date because of daily [continuous deployment](https://en.wikipedia.org/wiki/Continuous_deployment) runs.\n\n\n| Docs | Deployment | Package | Python | PyTorch | Docker | CodeBeat | Images |\n|------|------------|---------|--------|---------|--------|----------|--------|\n|[![Documentation](https://img.shields.io/static/v1?label=\u0026message=Wiki\u0026color=EE4C2C\u0026style=for-the-badge)](https://github.com/szymonmaszke/torchlambda/wiki) | ![CD](https://img.shields.io/github/workflow/status/szymonmaszke/torchlambda/update?label=%20\u0026style=for-the-badge) | [![PyPI](https://img.shields.io/static/v1?label=\u0026message=PyPI\u0026color=377EF0\u0026style=for-the-badge)](https://pypi.org/project/torchlambda/) | [![Python](https://img.shields.io/static/v1?label=\u0026message=3.6\u0026color=377EF0\u0026style=for-the-badge\u0026logo=python\u0026logoColor=F8C63D)](https://www.python.org/) | [![PyTorch](https://img.shields.io/static/v1?label=\u0026message=1.4.0\u0026color=EE4C2C\u0026style=for-the-badge)](https://pytorch.org/) | [![Docker](https://img.shields.io/static/v1?label=\u0026message=17.05\u0026color=309cef\u0026style=for-the-badge)](https://cloud.docker.com/u/szymonmaszke/repository/docker/szymonmaszke/torchlambda) | [![codebeat badge](https://codebeat.co/badges/ca6f19c8-29ad-4ddb-beb3-4d4e2fb3aba2)](https://codebeat.co/projects/github-com-szymonmaszke-torchlambda-master) | [![Images](https://img.shields.io/static/v1?label=\u0026message=Tags\u0026color=309cef\u0026style=for-the-badge)](https://hub.docker.com/r/szymonmaszke/torchlambda/tags)|\n\n\n## :heavy_check_mark: Why should I use `torchlambda`?\n\n- __Lightweight \u0026 latest dependencies__ - compiled source code weights only `30MB`. Previous approach to PyTorch network deployment on AWS Lambda ([fastai](https://course.fast.ai/deployment_aws_lambda.html)) uses outdated PyTorch (`1.1.0`) as dependency layer and requires AWS S3 to host your model. Now you can only use AWS Lambda and host your model as layer and PyTorch `master` and latest stable release are supported on a daily basis.\n- __Cheaper and less resource hungry__ - available solutions run server hosting incoming requests all the time. AWS Lambda (and torchlambda) runs only when the request comes.\n- __Easy automated scaling__  usually autoscaling is done with [Kubernetes](https://kubernetes.io/) or similar tools (see [KubeFlow](https://www.kubeflow.org/docs/gke/deploy/)). This approach requires knowledge of another tool, setting up appropriate services (e.g. [Amazon EKS](https://aws.amazon.com/eks/)). In AWS Lambda case you just push your neural network inference code and you are done.\n- __Easy to use__ - no need to learn new tool. `torchlambda` has at most\n`4` commands and deployment is done via [YAML](https://yaml.org/) settings. No need to modify your PyTorch code.\n- __Do one thing and do it well__ - most deployment tools are complex solutions\nincluding multiple frameworks and multiple services. `torchlambda` focuses\nsolely on inference of PyTorch models on AWS Lambda.\n- __Write programs to work together__ - This tool does not repeat PyTorch \u0026 AWS's functionalities (like `aws-cli`). You can also use your favorite third party tools (say [saws](https://github.com/donnemartin/saws), [Terraform](https://www.terraform.io/) with AWS and [MLFlow](https://www.mlflow.org/docs/latest/index.html), [PyTorch-Lightning](https://github.com/PyTorchLightning/pytorch-lightning) to train your model).\n- __Test locally, run in the cloud__ - `torchlambda` uses [Amazon Linux 2](https://aws.amazon.com/amazon-linux-2/) Docker [images](https://hub.docker.com/_/amazonlinux) under the hood \u0026 allows you to use [lambci/docker-lambda](https://github.com/lambci/docker-lambda) to test your deployment on `localhost` before pushing deployment to the cloud (see [Test Lambda deployment locally](https://github.com/szymonmaszke/torchlambda/wiki/Test-Lambda-deployment-locally) tutorial).\n- __Extensible when you need it__ - All you usually need are a few lines of YAML settings, but if you wish to fine-tune your deployment you can use `torchlambda build` `--flags` (changing various properties of PyTorch and AWS dependencies themselves). You can also write your own C++ deployment code (generate template via `torchlambda template` command).\n- __Small is beautiful__ - `3000` LOC (most being convenience wrapper creating this tool)\nmake it easy to jump into source code and check what's going on under the hood.\n\n\n# :house: Table Of Contents\n\n- [Installation](https://github.com/szymonmaszke/torchlambda/wiki/Installation)\n- [Tutorials](https://github.com/szymonmaszke/torchlambda/wiki/Tutorials)\n\t- [ResNet18 deployment on AWS Lambda](https://github.com/szymonmaszke/torchlambda/wiki/ResNet18-deployment-on-AWS-Lambda)\n\t- [Test Lambda deployment locally](https://github.com/szymonmaszke/torchlambda/wiki/Test-Lambda-deployment-locally)\n\t- [`base64` image encoding](https://github.com/szymonmaszke/torchlambda/wiki/base64-image-encoding)\n- [Commands](https://github.com/szymonmaszke/torchlambda/wiki/Commands)\n\t- [settings](https://github.com/szymonmaszke/torchlambda/wiki/Commands#torchlambda-settings)\n\t- [template](https://github.com/szymonmaszke/torchlambda/wiki/Commands#torchlambda-template)\n\t- [build](https://github.com/szymonmaszke/torchlambda/wiki/Commands#torchlambda-build)\n\t- [layer](https://github.com/szymonmaszke/torchlambda/wiki/Commands#torchlambda-layer)\n- [YAML settings file reference](https://github.com/szymonmaszke/torchlambda/wiki/YAML-settings-file-reference)\n- [C++ code](https://github.com/szymonmaszke/torchlambda/wiki/CPP---code)\n\n## :page_with_curl: Benchmarks\n\nBenchmarks can be seen in [`BENCHMARKS.md`](https://github.com/szymonmaszke/torchlambda/blob/master/BENCHMARKS.md) file and are comprised of around ~30000 test cases.\n\nResults are divided based on settings used, model type, payload, AWS Lambda timing etc. Below is an example of how inference performance changes due to higher resolution images and type of encoding:\n\n|        |   128x128 |   256x256 |   512x512 |   1024x1024 |\n|:-------|----------:|----------:|----------:|------------:|\n| base64 |   120.622 |   165.184 |   311.129 |     995.249 |\n| byte   |   133.315 |   203.628 |   498.391 |    1738.97  |\n| char   |   128.331 |   209.306 |   517.482 |    1822.56  |\n| short  |   135.859 |   207.389 |   497.818 |    1740.91  |\n| int    |   133.42  |   216.163 |   519.502 |    1783.02  |\n| long   |   126.979 |   228.497 |   516.98  |    1760.93  |\n| float  |   135.825 |   223.045 |   515.245 |    1802.25  |\n| double |   137.281 |   209.267 |   536.959 |    1811.83  |\n\nClearly the bigger image, the more important it is to use `base64` encoding. For all results and description [click here](https://github.com/szymonmaszke/torchlambda/blob/master/BENCHMARKS.md).\n\n## :question: Contributing\n\nIf you find an issue or you think some functionality may be useful to you, please [open new Issue](https://help.github.com/en/articles/creating-an-issue) or [create Pull Request](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) with your changes, thanks!\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszymonmaszke%2Ftorchlambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszymonmaszke%2Ftorchlambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszymonmaszke%2Ftorchlambda/lists"}