Skip to content

feat(aws-python-gpu-managed-instances): add a GPU function example with PyTorch on Lambda Managed Instances - #832

Open
czubocha wants to merge 2 commits into
v4from
aws-python-gpu-managed-instances
Open

czubocha wants to merge 2 commits into
v4from
aws-python-gpu-managed-instances

Conversation

@czubocha

Copy link
Copy Markdown
Contributor

Summary

Adds aws-python-gpu-managed-instances, the first Lambda Managed Instances example. A Python function multiplies two matrices with PyTorch on a fractional NVIDIA L4 (g6f instances, capacityProvider.gpu.memory: 3) and returns the GPU's name.

  • Lesson: run a function on a GPU with the Framework, using a container image, a capacity provider with GPU instance types, and capacityProvider.gpu.

  • Left out:

    • events (HTTP, S3);
    • loading a model from S3;
    • scale to zero, because the first invocations after an idle period are throttled for minutes, which would make Try it wait;
    • GPU scaling policies.

    The README's Next steps link the docs for each.

  • resources: a VPC with two public subnets and a security group. Capacity providers need a VPC, and the Framework doesn't create one; public subnets avoid a NAT gateway's hourly charge. The README says why and how to use an existing VPC.

  • No test block: a live test needs the EC2 quota "Running On-Demand G and VT instances" (default 0 vCPUs) in the test accounts and takes about 20 minutes, so the example has no Verified badge.

Merge after the release

The example needs capacityProvider.gpu, added by serverless/serverless#14155, which is merged and ships in the release after 4.46.0. Merge this once that release is out and the example has been deployed and invoked once on it. Before merging, check that the README's minimum version (4.47.0) matches the release.

Evidence

All in an AWS account in us-east-1, with the CLI built from source:

  • node scripts/check-examples.mjs aws-python-gpu-managed-instances: 0 errors. npm test: 311 passed.

  • Followed the README from a copy, with a unique stage:

    • the deploy took 979 s, most of it pushing the 5 GB PyTorch image;
    • two invokes returned "device": "NVIDIA L4-3Q" and "result": 4096;
    • the remove took 293 s.

    The README's output blocks are from this run.

  • Afterwards, no CloudFormation stack, ECR repository, capacity provider or /aws/lambda/aws-python-gpu* log group remained.

  • That run used a build from before the key's final name: it was then called accelerator, and was renamed to gpu in feat(aws): support GPU instances on Lambda Managed Instances serverless#14155 before release. The rename changes the key's name only; the compiled template is the same, which the Framework's unit tests cover. The run on the release build, before merge, covers the final name.

  • Not run: test-example.mjs and a negative control, because the example has no test block. No fresh-agent pass either: Try it is a single command between deploy and remove.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant