Skip to content

fix: release host weight staging buffer after device upload (47% memory saving) - #53

Merged
mudler merged 1 commit into
mudler:masterfrom
masc-it:fix/release-host-staging-after-device-upload
Jul 27, 2026
Merged

fix: release host weight staging buffer after device upload (47% memory saving)#53
mudler merged 1 commit into
mudler:masterfrom
masc-it:fix/release-host-staging-after-device-upload

Conversation

@masc-it

@masc-it masc-it commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Release the host-side GGUF weight context after all weights have been uploaded to a non-CPU backend.

Previously, device backends such as Metal retained both:

  • the complete host-side weight allocation
  • the complete device backend allocation

The host context is only needed as a staging source during upload. Once the tensor map points to the device-resident tensors, it can safely be released.

The CPU path is unchanged and continues to use the host context as a zero-copy backend buffer.

Memory improvement

Tested on macOS with Metal using parakeet-tdt-0.6b-v3-q5_k.gguf:

Version Physical footprint after inference
v0.4.0 1,474 MB
Patched 780 MB
Reduction 694 MB (~47%)

After five consecutive transcription requests, memory remained stable at approximately 771 MB.

The transcription output was identical before and after the change.

The temporary startup peak remains approximately 1.4 GB because both allocations coexist during upload, but the host staging allocation is released immediately afterward.

Validation

  • Metal release build succeeds
  • Server health endpoint remains healthy
  • Five consecutive transcription requests return identical output
  • CPU backend produces the same transcript
  • Existing non-model test suite passes

Future improvements

This was a no-brainer, zero cost improvement.

For M-series machines, we could approach model loading using two superior approaches:

  • Metal mapped buffer ggml_backend_dev_buffer_from_host_ptr
  • mmap the GGUF

AI Support

  • gpt-5.6-sol

@masc-it masc-it changed the title fix: release host weight staging buffer after device upload fix: release host weight staging buffer after device upload (47% memory saving) Jul 26, 2026

@localai-org-maint-bot localai-org-maint-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device path now releases only the host staging context after all synchronous tensor uploads and after the tensor map has been repointed; the CPU zero-copy path remains unchanged. The ownership/destructor ordering looks sound. I could not rerun the CMake suite locally because this host currently lacks cmake, so my review relies on the focused Metal/CPU validation reported in the PR.

@mudler this looks good to merge.

@mudler
mudler merged commit 3e1ddd8 into mudler:master Jul 27, 2026
7 checks passed
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.

3 participants