server: --allowed-models to restrict which model paths a request may load - #1893
Open
mrcushen-arch wants to merge 1 commit into
Open
mrcushen-arch wants to merge 1 commit into
mrcushen-arch wants to merge 1 commit into
Conversation
…load On a shared machine every script that names a different model swaps or adds a resident model for everyone else. With --allowed-models the server refuses any model path not listed (the --model given at start is always allowed) before touching weights; the request gets the existing 404 error path. Default is unchanged (load on demand). Fixes ml-explore#1892.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
--allowed-modelstomlx_lm.server: an optional allow-list of model paths a request may load. The--modelgiven at start is always allowed. A request naming anything else is refused before any weights are touched, through the existing error path (HTTP 404 with a JSON error), instead of loading or swapping the resident model. Default behaviour (load on demand) is unchanged.Fixes #1892.
Why
On a shared machine several scripts point at one server. Each script that names a different model swaps or adds a resident model for everyone else. Measured on an M4 Pro (48 GB): five models cycled through residency, free memory fell to ~6 GB, and a 10-token request went from ~0.5 s to ~40 s / timeouts. With the server restricted to one model: 1 resident, ~18 GB free, 0.56 s.
Changes
ModelProvider.__init__: buildallowed_modelsfrom the flag (+ the startup--model).ModelProvider.load: raiseValueErrorwhen the resolved path is not allowed.--allowed-modelsargparse flag (nargs="*").TestAllowedModels— refuses a foreign model, allows listed + default +default_model, no list means any.tests/test_server.pypasses in full (36).