Skip to content

Avoid allocating beyond MTLDevice.recommendedMaxWorkingSetSize - #2069

Draft
kiltyj wants to merge 1 commit into
ggml-org:masterfrom
kiltyj:avoid-metal-allocation-limit
Draft

kiltyj wants to merge 1 commit into
ggml-org:masterfrom
kiltyj:avoid-metal-allocation-limit

Conversation

@kiltyj

@kiltyj kiltyj commented Jul 2, 2023

Copy link
Copy Markdown
Contributor

When I've found spare time, I've been playing around with some ideas for avoiding allocating beyond MTLDevice.recommendedMaxWorkingSetSize. I'm not sure this is ready to merge, but I thought I'd share what I have to start a discussion, since I saw that @ggerganov pushed something related to this earlier this week.

What I'm observing:

  • Keeping allocations below recommendedMaxWorkingSetSize avoids runtime errors (but performance suffers)
  • When a model is larger than recommendedMaxWorkingSetSize, it's very easy to get into a situation where memory starts swapping out to disk, significantly impacting performance. To avoid this, I usually run benchmarks after a fresh boot.
  • Even after a fresh boot, GPU performance for models larger than recommendedMaxWorkingSetSize still don't quite match CPU performance

Questions to dig into:

  • Why are we hitting this GPU ceiling (fresh reboot, no swapping, CPU-limited? consequence of MTLBuffer allocation/deallocation?)?:
    image
  • Can we match CPU performance when swapping to SSD is unnecessary?
  • Is there an allocation limit other than ctx->device.recommendedMaxWorkingSetSize that we can use to avoid swap?
  • Deallocation logic / caching is pretty dumb right now. Are there smarter strategies?
  • Is 1GB the right view size? Could we do one view per tensor, or would this require too much CPU-side, w/r/t memory and/or computation?

Curious to hear if others have interesting observations/ideas.

This branch has not been deployed

No deployments
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