mlx_lm.server: option to restrict which models a request may load (allow-list)
Problem
mlx_lm.server loads whatever model path a request names in "model" and keeps it resident. On a shared machine where several scripts point at the same server, each script that names a different model silently adds a resident model. On an M4 Pro (48 GB) today five models ended up resident (a 27B dense, a 35B, an 8B, a 0.6B, plus the intended 35B-A3B), free memory fell to ~6 GB, and a trivial request went from ~0.5 s to ~40 s / timeouts.
Proposal
A server flag such as --allowed-models <path> [<path> ...] (or --no-dynamic-load to pin the --model given at start). A request naming any other model returns a 400 with a clear message instead of loading it. The default (load on demand) stays as it is.
Measured on the same machine after restricting to one model
| before | after | |
|---|---|---|
| models resident | 5 | 1 |
| free memory | ~6 GB | ~18 GB |
| 10-token round trip | ~40 s / wedged | 0.56 s |
| 3 concurrent 33-token completions | timed out | 1.97 s total |
Interim
A small loopback proxy that does this in front of the server, MIT: https://github.com/mrcushen-arch/mlx-guard. Happy to open a PR adding the flag to server.py if that shape is acceptable — a set of allowed paths checked in the request handler before the model-cache lookup.
Source: ml-explore/mlx-lm