feat: add example 01-04 - Dependency Management - #5
Conversation
Add comprehensive dependency management example demonstrating: Worker Features: - Python dependencies with version constraints (==, >=, <) - System dependencies via apt packages - Minimal workers with no dependencies for fast cold start - ML dependencies (torch, torchvision, Pillow, numpy) - Computer vision system deps (ffmpeg, libgl1) Implementation: - CPU workers for data science (pandas, numpy, scipy, matplotlib) - GPU workers for ML inference with versioned packages - Minimal CPU worker with stdlib only - Pydantic field validators for input validation - Prevents NaN serialization with minimum row validation Validation: - At least 2 rows required for statistics computation - Exactly 2 columns per row validation - Empty data validation - Helpful error messages with examples Comprehensive README covers: - Dependency types and version constraints - Common dependency stacks (ML, data science, CV, audio, NLP) - Input validation with Pydantic best practices - Field validators and common patterns - System dependencies and cold start optimization - Troubleshooting and best practices
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive example (01-04) demonstrating dependency management in Flash applications, including Python package versioning, system dependencies, and input validation patterns.
Key Changes:
- Adds new example directory
01_getting_started/04_dependencies/with GPU and CPU workers showcasing different dependency configurations - Updates repository documentation to reflect the new port (8888) and improved setup workflows
- Adds VS Code debug configuration and PR template for better developer experience
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
01_getting_started/04_dependencies/workers/gpu/endpoint.py |
GPU workers demonstrating ML dependencies (torch, pillow) and system packages (ffmpeg, libgl1) |
01_getting_started/04_dependencies/workers/cpu/endpoint.py |
CPU workers showing data science dependencies and minimal/no-dependency patterns |
01_getting_started/04_dependencies/workers/cpu/__init__.py |
FastAPI router with Pydantic field validators for input validation |
01_getting_started/04_dependencies/README.md |
Comprehensive guide covering dependency management, validation patterns, and best practices |
README.md |
Updated setup instructions, port change (8000→8888), and testing documentation |
CONTRIBUTING.md |
Added VS Code debugging section and port updates |
pyproject.toml |
Added torch dependency to root project |
.vscode/launch.json |
VS Code debug configuration for endpoint development |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return {"result": "processed"} | ||
| ``` | ||
|
|
||
| ## Input Validation with Pydantic |
There was a problem hiding this comment.
Is it worth trimming up some of the details about Flash using Pydantic for this example? I see the use of having it but I wonder if it's okay to omit some here to keep the example focused - someone could read more about Pydantic if they want the details outside of how/why Flash uses it
| ) | ||
|
|
||
|
|
||
| @remote( |
There was a problem hiding this comment.
I know most of this is covered in the README, but for someone skimming in the code it could be helpful to have an extra inline callout that deps are handled here, and are explicitly handled differently than system deps? Also, maybe a discussion on how deps are handled under the hood and why baking deps into a custom docker image will decrease cold start time. For example, I think about Lambda's "best practices" page where they talk about putting code outside of the handler function, but also explain (briefly) why that helps with faster warm starts and costs.
Uh oh!
There was an error while loading. Please reload this page.