You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds two per-model MLX backend runtime options to bound and reduce
memory during long/multi-session serving. clear_cache_interval makes
MLXBackend::execute() call mlx::core::clear_cache() every N forward
calls (counter on the handle, guarded by the global mutex so no atomic
is needed), and skip_mutable_buffer_init lets a multi-session load skip
allocating the handle's default mutable-buffer (KV/recurrent state)
copy, which is dead weight once mlx_mutable_state.h allocates
per-session buffers — eliminating one full KV-cache copy. Both are
delivered per-delegate via the existing
LoadBackendOptionsMap/get_runtime_spec path and exposed through a shared
backends/mlx/runtime/backend_options.h. Skipping is gated for safety: a
new auto-generated for_each_tid walker (added to generate.py + the
MLXLoader templates, covering all op nodes) powers
init_chain_references_mutable_buffer(), and init() errors out cleanly if
skip_mutable_buffer_init is set while the program's init chain
references mutable buffers. mutable_state_bytes_per_session is rebased
onto program metadata (with a per-tensor size clamp to avoid overflow
from malformed payloads) so capacity accounting stays correct when
default buffers are skipped. Finally, the gemma4_31b runner enables
these in build_gemma_module: clear_cache_interval is hardcoded to 1, and
skip_mutable_buffer_init is set automatically when max_sessions > 1.
0 commit comments