Skip to content

Release owned MLX model and tokenizer references on unload - #249

Merged
daniele21 merged 3 commits into
devfrom
fix/mlx-runtime-release-references
Oct 18, 2026
Merged

daniele21 merged 3 commits into
devfrom
fix/mlx-runtime-release-references

Conversation

@daniele21

@daniele21 daniele21 commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Problem and outcome

MLXEngine.close() was a no-op: even when Korgis logically unloaded a runtime, its backend could keep model/tokenizer references alive. Correct that root cause in the canonical MLX backend, ensuring idempotent close, closed-runtime inference rejection, and model-isolated teardown under lease-safe manager semantics.

Invariants

  • No forceful removal during active leases.
  • Do not invoke global Metal allocator/cache cleanups that could interfere with other resident MLX runtimes.
  • Reference release is not proof of reclaimed RAM/Metal unified memory; physical measurements remain necessary.
  • No backend-specific process or new resource manager created.

Classification

PRODUCT_LOCAL / INTEGRATION / STRONG (native runtime lifecycle and resources) / REMOTE_AUTOMATED deterministic, REAL_ENVIRONMENT 32-GiB Apple Silicon reclamation pending #239 and #244.

Evidence

Deterministic tests verify weakref release, repeated close, closed stream, busy-lease protection and unrelated MLX model retention. Required CI and base revalidation before merge.

Exact-head validation

@daniele21
daniele21 marked this pull request as ready for review October 18, 2026 12:48
@daniele21
daniele21 merged commit bc2be64 into dev Oct 18, 2026
15 checks passed
@daniele21
daniele21 deleted the fix/mlx-runtime-release-references branch October 18, 2026 12:51
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