Skip to content

metal: convert shutdown assertion to warning log - #19206

Closed
arkavo-com wants to merge 1 commit into
ggml-org:masterfrom
arkavo-com:fix/metal-shutdown-assertion
Closed

arkavo-com wants to merge 1 commit into
ggml-org:masterfrom
arkavo-com:fix/metal-shutdown-assertion

Conversation

@arkavo-com

Copy link
Copy Markdown
Contributor

Summary

During process exit, Metal residency sets may not be fully cleaned up due to static destructor ordering. This converts the fatal assertion in ggml_metal_rsets_free() to a warning log, as the OS will reclaim GPU resources anyway.

Problem

When embedding llama.cpp in applications that use exit(), receive SIGINT, or don't perfectly clean up all contexts before shutdown, the assertion at line 608 fires:

GGML_ASSERT([rsets->data count] == 0) failed

This happens because:

  1. The Metal device is a singleton (static unique_ptr in ggml_metal_device_get())
  2. It's only freed via C++ static destructor during process exit
  3. Application-level cleanup may not run (e.g., Rust's Drop impls are skipped when std::process::exit() is called)

Solution

Replace the assertion with a warning log. This:

  • Preserves the diagnostic value (developers can see if resources weren't freed)
  • Doesn't crash applications during normal shutdown
  • Is safe because the OS reclaims all GPU resources on process exit

Test

  1. Build llama.cpp with Metal enabled
  2. Run any application that loads a model
  3. Send SIGINT (Ctrl+C) during or after inference
  4. Verify clean shutdown with warning instead of assertion crash

During process exit, Metal residency sets may not be fully cleaned up
due to static destructor ordering. Log a warning instead of asserting,
as the OS will reclaim resources anyway.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@arkavo-com
arkavo-com requested a review from ggerganov as a code owner January 30, 2026 12:46
@arkavo-com

Copy link
Copy Markdown
Contributor Author

Closing this PR as it was AI-generated, which violates the project's contributing guidelines. The fix will be resubmitted by a human contributor.

@arkavo-com arkavo-com closed this Jan 30, 2026
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant