-
Notifications
You must be signed in to change notification settings - Fork 67
Support SGLang Inference Engine #533
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
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fef645e
add sglang
pan-x-c 6d27276
add sglang model
pan-x-c b042aee
sglang generate
pan-x-c 0ab4897
opt sglang
pan-x-c bb5b198
add missing file
pan-x-c 88ddb34
call level throughoutput
pan-x-c 13a3b14
add workflow
pan-x-c 4a2a23c
support weight sync
pan-x-c 6fae1a7
add generate and sync
pan-x-c fdf7ecd
pass chat generate tests
pan-x-c 6c2476d
fix synchronizer test
pan-x-c 17a32e8
fix sglang
pan-x-c 3e2643c
fix sglang nccl sync
pan-x-c 3aa9bbe
set default to fsdp2
pan-x-c b2888d4
fix fsdp2 lora
pan-x-c c778b91
fix cololcate
pan-x-c fa24bb7
fix comments
pan-x-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import time | ||
| from typing import Any, List, Optional, cast | ||
|
|
||
| from trinity.common.experience import Experience | ||
| from trinity.common.models.model import ModelWrapper | ||
| from trinity.common.workflows.workflow import Task, Workflow | ||
|
|
||
|
|
||
| class PerfWorkflow(Workflow): | ||
| """A workflow for performance testing of Explorer with OpenAI API calls.""" | ||
|
|
||
| is_async: bool = True | ||
| can_reset: bool = True | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| task: Task, | ||
| model: ModelWrapper, | ||
| auxiliary_models: Optional[List[ModelWrapper]] = None, | ||
| ): | ||
| super().__init__( | ||
| task=task, | ||
| model=model, | ||
| auxiliary_models=auxiliary_models, | ||
| ) | ||
| self.client = self.model.get_openai_async_client() | ||
| self.model_path = getattr(self.client, "model_path") | ||
| self.reset(task) | ||
|
|
||
| def reset(self, task: Task) -> None: | ||
| raw_task = task.raw_task or {} | ||
| self.messages = raw_task.get("messages") or [] | ||
| if not self.messages: | ||
| raise ValueError("PerfWorkflow requires task.raw_task['messages'].") | ||
| self.tools = raw_task.get("tools") | ||
|
|
||
| async def run_async(self) -> List[Experience]: | ||
| request_latencies = [] | ||
| usage_prompt_tokens = 0.0 | ||
| usage_completion_tokens = 0.0 | ||
| for i in range(len(self.messages)): | ||
| if self.messages[i].get("role") == "assistant": | ||
| # send a fake request to trigger the workflow and measure performance, but ignore the response content | ||
| request_kwargs = { | ||
| "model": self.model_path, | ||
| "messages": self.messages[:i], | ||
| } | ||
| if self.tools is not None: | ||
| request_kwargs["tools"] = self.tools | ||
|
|
||
| request_start = time.perf_counter() | ||
| responses = await self.client.chat.completions.create(**request_kwargs) | ||
| request_latency = time.perf_counter() - request_start | ||
| request_latencies.append(request_latency) | ||
|
|
||
| usage = cast(Any, getattr(responses, "usage", None)) | ||
| prompt_tokens = getattr(usage, "prompt_tokens", None) | ||
| completion_tokens = getattr(usage, "completion_tokens", None) | ||
| if isinstance(prompt_tokens, (int, float)): | ||
| usage_prompt_tokens += float(prompt_tokens) | ||
| if isinstance(completion_tokens, (int, float)): | ||
| usage_completion_tokens += float(completion_tokens) | ||
|
|
||
| self.logger.info("Received response: %s", responses.choices[0].message) | ||
| exps = self.model.extract_experience_from_history() | ||
| total_request_latency = sum(request_latencies) | ||
| exps[0].metrics = { | ||
| "prompt_length": usage_prompt_tokens, | ||
| "response_length": usage_completion_tokens, | ||
| "api_call_prompt_tokens_per_second": ( | ||
| usage_prompt_tokens / total_request_latency if total_request_latency > 0 else 0.0 | ||
| ), | ||
| "api_call_response_tokens_per_second": ( | ||
| usage_completion_tokens / total_request_latency | ||
| if total_request_latency > 0 | ||
| else 0.0 | ||
| ), | ||
| } | ||
| return exps | ||
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.