Skip to content

Add adaptive memory management based on system RAM#4

Open
sb1992 wants to merge 1 commit into
mainfrom
adaptive-memory-management
Open

Add adaptive memory management based on system RAM#4
sb1992 wants to merge 1 commit into
mainfrom
adaptive-memory-management

Conversation

@sb1992

@sb1992 sb1992 commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Auto-detect system RAM and set MLX buffer cache limit to balance speed vs. memory usage
  • Formula: min(8, max(0, (ram_gb - 12) * 0.4)) GB — reserves 12 GB for OS, caps at 8 GB
  • Add --cache-gb CLI override and --num_frames flag for manual tuning
  • Clear MLX cache between denoising chunks + free models after their pipeline stage

Memory benchmarks (v1.5, 256px)

System RAM Auto Cache Peak Memory Speed (per chunk)
8 GB 0 GB ~10.5 GB ~21s
16 GB 1.6 GB ~15 GB ~19s
24 GB 4.8 GB ~18 GB ~18s
32+ GB 8 GB ~22 GB ~14s

Test plan

  • Run on 16 GB Mac with auto-detection, verify peak stays under ~15 GB
  • Run with --cache-gb 0, verify ~10.5 GB peak
  • Run with --cache-gb 8, verify no regression vs. unlimited
  • Verify output quality unchanged (compare PSNR to baseline)

🤖 Generated with Claude Code

- Auto-detect system RAM and set MLX buffer cache limit accordingly:
  8 GB → 0 cache, 16 GB → 1.6 GB, 24 GB → 4.8 GB, 32+ GB → 8 GB (cap)
- Add --cache-gb CLI override for manual tuning
- Add --num_frames flag to control chunk size (lower = less memory)
- Clear MLX cache between denoising chunks to prevent runaway growth
- Free Whisper encoder and face detector after preprocessing
- Add memory profiling script (scripts/profile_memory.py)
- Update README with memory optimization docs and benchmark table

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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