-
Notifications
You must be signed in to change notification settings - Fork 6.9k
add sglang engine demo for /v1/chat/completions #58366
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
base: master
Are you sure you want to change the base?
Changes from all commits
b170767
3c5f57d
5cee539
dc139e8
a97e6dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||
| import ray | ||||||
| import requests | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| from ray import serve | ||||||
| from ray.serve.handle import DeploymentHandle | ||||||
|
|
||||||
| #@serve.deployment disable serve.deployment | ||||||
| class SGLangServer: | ||||||
| def __init__(self, llm_config: LLMConfig): | ||||||
|
|
||||||
| default_engine_kwargs = dict( | ||||||
| model_path = "/scratch2/huggingface/hub/meta-llama/Llama-3.1-8B-Instruct/", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Hardcoded Dev Path Breaks Production DeploymentHardcoded personal development path
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is only for demo usage Hardcoded personal development path |
||||||
| mem_fraction_static = 0.8, | ||||||
| tp_size = 8, | ||||||
| ) | ||||||
|
|
||||||
| if llm_config.engine_kwargs: | ||||||
| default_engine_kwargs.update(llm_config.engine_kwargs) | ||||||
| self.engine_kwargs = default_engine_kwargs | ||||||
|
|
||||||
| try: | ||||||
| import sglang | ||||||
| except ImportError as e: | ||||||
| raise ImportError( | ||||||
| "SGLang is not installed or failed to import. Please run " | ||||||
| "`pip install sglang[all]` to install required dependencies." | ||||||
| ) from e | ||||||
| self.engine = sglang.Engine(**self.engine_kwargs) | ||||||
|
|
||||||
| async def chat(self, message: str): | ||||||
| print('In SGLangServer CHAT with message', message) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be ignore |
||||||
| res = await self.engine.async_generate( | ||||||
| prompt = message, | ||||||
| stream = False | ||||||
| ) | ||||||
|
Comment on lines
+31
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| return {"echo": res} | ||||||
|
|
||||||
| @classmethod | ||||||
| def get_deployment_options(cls, llm_config: "LLMConfig"): | ||||||
| return {'autoscaling_config': {'min_replicas': 1, 'max_replicas': 1}, | ||||||
| 'placement_group_bundles': [{'CPU': 1, 'GPU': 1, 'accelerator_type:H100': 0.001}, {'GPU': 1, 'accelerator_type:H100': 0.001}], | ||||||
| 'placement_group_strategy': 'PACK', | ||||||
| 'ray_actor_options': {'runtime_env': | ||||||
| {'worker_process_setup_hook': 'ray.llm._internal.serve._worker_process_setup_hook'} | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #sglangServer = SGLangServer.bind() | ||||||
| #my_App = MyFastAPIDeployment.bind(sglangServer) | ||||||
| #handle: DeploymentHandle = serve.run(my_App, blocking = True) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Misleading Deployment Class Behavior
The
deployment_clsparameter is accepted but completely ignored, always being overridden toSGLangServer. This creates misleading API behavior where callers might pass a custom deployment class expecting it to be used, but it will be silently ignored.