-
Notifications
You must be signed in to change notification settings - Fork 56
Optimize vid_vec_rep_clip operator for long videos and add profiling … #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aatmanvaidya
merged 11 commits into
tattle-made:development
from
Ishaswm:feat/optimize-vid-vec-rep
May 19, 2025
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5dbde69
Optimize vid_vec_rep_clip operator for long videos and add profiling …
393a1de
refactor(vid_vec_rep_clip): remove inline benchmarking from analyze()
7d91265
feat: add benchmarking system
31c12e2
refactor(vid_vec_rep_clip): enhance cross-platform compatibility and …
256504f
refactor(vid_vec_rep_clip): improve cross-platform compatibility and …
8e31b19
Remove markdown file from the operator
ddffd0b
Remove unused frame_sample_rate argument from VideoAnalyzer
291957b
Clean up: remove unnecessary files, update vid_vec_rep_clip logic and…
69fd6be
chore: remove operator changes
aatmanvaidya da650a7
refactor: readme file
aatmanvaidya 641ab0b
chore: fix lint issues
aatmanvaidya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move this file to the benchmark folder? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Optimization Notes for `vid_vec_rep_clip` | ||
|
|
||
| ## **Problem Statement** | ||
| The current implementation of the `vid_vec_rep_clip` operator lacks support for processing longer videos efficiently and reliably. Specifically, we wanted to investigate: | ||
| - Can the operator process longer videos (1min to 1hr) without breaking or exhausting system resources? | ||
| - Is the model itself a bottleneck, or is the limitation due to code inefficiencies? | ||
| - How does the operator perform in terms of CPU and memory usage for large video inputs? | ||
|
|
||
| ## **Goals** | ||
| - Determine if the operator can process videos of varying lengths (1, 5, 10, 20, 30, 45, 60 mins). | ||
| - Profile memory and CPU usage during execution. | ||
| - Fix inefficiencies (if any) in the original implementation. | ||
| - Ensure output vector correctness post-refactor. | ||
|
|
||
| ## Findings from Original Implementation | ||
|
|
||
|  | ||
| **Inconsistencies:** Memory usage for the 60-min video is unexpectedly lower than for the 30-min video, suggesting inefficient memory handling or potential leaks in intermediate steps. | ||
|
|
||
| ## Results After Refactor | ||
|
|
||
|  | ||
| _Note: Longer videos show memory increase due to more efficient baseline measurement._ | ||
|
|
||
| ## Performance Comparison | ||
|
|
||
| ### Memory-Optimized vs Original Implementation | ||
|  | ||
|
|
||
| ### Memory Optimization Highlights: | ||
| - 81% reduction for 30-minute videos (1917MB → 365MB) | ||
|
|
||
| - 73.7% savings for 10-minute videos (1858MB → 488MB) | ||
|
|
||
| - More stable memory profile across all durations. | ||
|
|
||
| ### Processing Tradeoffs: | ||
| - 37-121% longer processing for videos ≤30 minutes. | ||
|
|
||
| - 14-22% faster for very long videos (>45 minutes) | ||
|
|
||
| - More accurate performance measurements | ||
|
|
||
| ## Key Improvements | ||
|
|
||
| ### Efficient I-Frame Sampling | ||
| - Switched to extracting only I-frames using `ffmpeg`, reducing unnecessary frame processing and improving memory efficiency. | ||
|
|
||
| ### Built-in Memory Profiling: | ||
| - Integrated `psutil` and `tracemalloc` to monitor memory usage before and after processing. | ||
|
|
||
| - Reports net memory change, helping diagnose scaling issues. | ||
|
|
||
| ### Scalable to Long Videos: | ||
| - Successfully tested on videos up to 1 hour, showing stable memory growth. | ||
|
|
||
| - Reports net memory change, helping diagnose scaling issues. | ||
|
|
||
| ### Enhanced Test Coverage: | ||
| - Includes test cases for: | ||
| - Local long videos (e.g., 1 hr) | ||
| - Sample short videos | ||
| - Remote video URLs | ||
|
|
||
| ## Summary of Changes | ||
|
|
||
| This PR introduces the following enhancements to the `vid_vec_rep_clip` operator: | ||
|
|
||
| 1. #### I-Frame Sampling Strategy: | ||
| Instead of decoding every frame or relying on precomputed metadata, the updated operator uses `ffmpeg` to extract only **I-frames** for vector representation. This reduces redundancy and improves scalability. | ||
|
|
||
| 2. #### Streaming Feature Extraction: | ||
| Frames are now loaded and processed in a streaming manner (one at a time) using temporary storage, preventing memory bloat. | ||
|
|
||
| 3. #### Detailed Profiling Added to Tests: | ||
|
|
||
| The `unittest` suite has been enhanced to capture: | ||
| - Memory usage before/after processing | ||
| - Net memory consumption | ||
| - CPU time and usage | ||
| - Peak memory (from `tracemalloc`) | ||
| - Total I-frames and vectors generated | ||
|
|
||
| 4. #### Average Vector Addition: | ||
| The final output includes a mean vector of all I-frame features, maintaining consistency with prior behavior. | ||
|
|
||
|
|
||
| ## 📌 Limitations | ||
| - **I-Frame Distribution:** The number of I-frames is determined by video encoding, so a shorter video could occasionally have more I-frames than a longer one. This is expected and valid behavior. | ||
|
|
||
| - **Processing Time:** The new implementation may take slightly longer for short videos due to I-frame extraction overhead, but this tradeoff is acceptable given the lower memory usage and improved scalability. | ||
|
|
||
| - **No Parallelism Yet:** Current implementation processes frames sequentially. There’s room for future speedup via batching or multithreading. | ||
|
|
||
| ## Checklist | ||
|
|
||
| - ✅ Code handles long videos (1 min to 1 hour) | ||
| - ✅ Memory and CPU profiling included | ||
| - ✅ Documented tradeoffs (time vs. memory) | ||
| - ✅ Old and new results clearly documented | ||
| - ✅ Known limitations acknowledged | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.