Skip to content

start engine loop on server startup event #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lmdeploy/pytorch/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,3 +1125,10 @@ def create_instance(self, cuda_stream_id=0):
"""
from .engine_instance import EngineInstance
return EngineInstance(self)

def start_loop(self):
"""start engine loop."""
if self.req_manager.is_loop_alive():
return True
self.req_manager.create_loop_task()
return True
7 changes: 7 additions & 0 deletions lmdeploy/serve/async_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,13 @@ def _gen():

return session

def start_loop(self):
"""start engine loop."""
if hasattr(self.engine, 'start_loop'):
return self.engine.start_loop()
else:
return True

""" DistServe Async Engine API Begin """

def free_cache(self, session_id: int):
Expand Down
3 changes: 3 additions & 0 deletions lmdeploy/serve/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ def dummy_get_device_id():

@router.on_event('startup')
async def startup_event():
async_engine = VariableInterface.async_engine
async_engine.start_loop()

if VariableInterface.proxy_url is None:
return
try:
Expand Down