Serverless Inference: AWS Lambda & Modal
+-----------------------------------------------------------------------------+
| SERVERLESS INFERENCE PARADIGMS |
+-----------------------------------------------------------------------------+
| Lightweight LLM APIs (OpenAI/Anthropic wrappers): AWS Lambda / API Gateway |
| Heavyweight Self-Hosted GPU Inference (Llama 3 8B): Modal / RunPod |
+-----------------------------------------------------------------------------+
Running LLM Applications on AWS Lambda
AWS Lambda is ideal for orchestration and API proxies:
- Zero Idle Cost: Scale down to 0 requests when inactive.
- Integration: Seamless IAM auth, CloudWatch logs, and S3 event triggers.
- Limitations: Max 15-minute timeout, 10 GB container limit, and no GPU support.
Running Open-Source GPU Models Serverlessly with Modal
For hosting open-source models (like Llama-3-8B) with serverless pay-per-second GPU execution:
import modal
app = modal.App("llama-inference-service")
image = modal.Image.debian_slim().pip_install(
"vllm", "torch", "transformers"
)
@app.cls(gpu="A10G", image=image, container_idle_timeout=120)
class LlamaModel:
@modal.enter()
def load_model(self):
from vllm import LLM
self.llm = LLM(model="meta-llama/Meta-Llama-3-8B-Instruct")
@modal.method()
def generate(self, prompt: str):
from vllm import SamplingParams
sampling_params = SamplingParams(temperature=0.2, max_tokens=256)
outputs = self.llm.generate([prompt], sampling_params)
return outputs[0].outputs[0].text
@app.local_entrypoint()
def main():
model = LlamaModel()
result = model.generate.remote("Explain Delta Lake ACID transactions in 1 sentence.")
print("Result:", result)