[Serve] Public option to turn off model pinning in serve.multiplexed
Follow-up to #68078, agreed in this review thread.
Problem
- With #68078,
serve.multiplexedkeeps a model loaded while a request that looked it up is still running. - Some models don't need that, because unloading them frees nothing a running request uses. For example, Serve LLM's LoRA lookup only returns where the adapter is on disk.
- For those models, pinning only makes a miss wait for a free slot.
- The only way to opt out is the private
_unpinned_model_lookups()context manager, which Serve LLM uses today.
Current: wrap each lookup in a private context manager.
from ray import serve
from ray.serve.multiplex import _unpinned_model_lookups # private
@serve.deployment
class Adapters:
@serve.multiplexed(max_num_models_per_replica=2)
async def get_adapter_path(self, model_id: str) -> str:
return f"/tmp/adapters/{model_id}"
async def __call__(self, request) -> str:
with _unpinned_model_lookups():
return await self.get_adapter_path(serve.get_multiplexed_model_id())
Expected: opt out once, on the decorator.
from ray import serve
@serve.deployment
class Adapters:
@serve.multiplexed(
max_num_models_per_replica=2, pin_while_request_in_flight=False
)
async def get_adapter_path(self, model_id: str) -> str:
return f"/tmp/adapters/{model_id}"
async def __call__(self, request) -> str:
return await self.get_adapter_path(serve.get_multiplexed_model_id())
Decisions to confirm
- The option's name.
pin_while_request_in_flightis the name from the review. - Whether Serve LLM moves to the public option and the private context manager is removed.
Hi @marwan116 @dstrodtman, I'd like to pick this up. Plan: add a public keyword to serve.multiplexed (I'd call it pin_models_during_requests, default True, unless the review thread on #68078 settled on another name) that skips the pin #68078 added, keep _unpinned_model_lookups() working as a thin alias for now, and switch Serve LLM's LoRA lookup to the new option. Tests: with the option off, a cache miss evicts an in-use model without waiting; with it on, the miss still waits; plus the docstring. Could you assign it to me?