-
Notifications
You must be signed in to change notification settings - Fork 692
chore: add utilities for benchmarking #1371
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 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7884341
chore: update config to match vLLM parameter used in benchmarking guide
GuanLuo 98558e4
fix: add comment on deployment pitfall
GuanLuo eed9ff7
chore: helper scripts
GuanLuo d429feb
chore: minor update for benchmark need
GuanLuo 57d274c
chore: add utilities for benchmarking
GuanLuo 81b78d6
chore: clean up
GuanLuo 7446406
chore: address comment
GuanLuo 059d58c
Update examples/llm/benchmarks/benchmark_watcher.py
GuanLuo c8c9c0c
fix: fix suggestion artifact
GuanLuo 413a166
chore: address comment
GuanLuo 843da74
chore: address comments
GuanLuo 1d01a3b
fix: fix typo
GuanLuo e026ae2
Merge branch 'main' into gluo/benchmarking
GuanLuo 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
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,153 @@ | ||
| # type: ignore # Ignore all mypy errors in this file | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import asyncio | ||
| import logging | ||
| import threading | ||
| import time | ||
| from argparse import Namespace | ||
| from http.server import BaseHTTPRequestHandler, HTTPServer | ||
|
|
||
| from dynamo.sdk import async_on_start, dynamo_context, service | ||
| from dynamo.sdk.lib.config import ServiceConfig | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def start_server(server): | ||
| # Setup stuff here... | ||
| server.serve_forever() | ||
|
|
||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class HealthServer(HTTPServer): | ||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| self.ready = False | ||
|
|
||
| def set_ready(self, ready: bool): | ||
| self.ready = ready | ||
|
|
||
|
|
||
| class RequestHandler(BaseHTTPRequestHandler): | ||
| def do_GET(self): | ||
| if self.server.ready: | ||
| self.send_response(200) | ||
| self.end_headers() | ||
| self.wfile.write(b"Ready.") | ||
| else: | ||
| self.send_response(400) | ||
| self.end_headers() | ||
| self.wfile.write(b"Not Ready") | ||
| return | ||
|
|
||
|
|
||
| def parse_args(service_name, prefix) -> Namespace: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--total-workers", | ||
| type=int, | ||
| default=1, | ||
| help="Total number of workers to be registered", | ||
| ) | ||
| parser.add_argument( | ||
| "--worker-components", | ||
| nargs="+", | ||
| default=["VllmWorker", "PrefillWorker"], | ||
| help="Components that we are tracking worker readiness", | ||
| ) | ||
| parser.add_argument( | ||
| "--component-endpoints", | ||
| nargs="+", | ||
| default=["generate", "mock"], | ||
| help="Components that we are tracking worker readiness", | ||
| ) | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| parser.add_argument( | ||
| "--timeout", | ||
| type=int, | ||
| default=600, | ||
| help="Timeout (seconds) for waiting for workers to be ready", | ||
| ) | ||
| parser.add_argument( | ||
| "--port", | ||
| type=int, | ||
| default=7001, | ||
| help="port for readiness check", | ||
| ) | ||
| config = ServiceConfig.get_instance() | ||
| config_args = config.as_args(service_name, prefix=prefix) | ||
| args = parser.parse_args(config_args) | ||
| return args | ||
|
|
||
|
|
||
| # Use dynamo style to have access to clients | ||
| @service( | ||
| dynamo={ | ||
| "namespace": "dynamo", | ||
| }, | ||
| resources={"cpu": "1", "memory": "1Gi"}, | ||
| workers=1, | ||
| ) | ||
| class Watcher: | ||
| def __init__(self): | ||
| self.args = parse_args(self.__class__.__name__, "") | ||
|
|
||
| @async_on_start | ||
| async def async_init(self): | ||
| self.runtime = dynamo_context["runtime"] | ||
| self.workers_clients = [] | ||
| for component, endpoint in zip( | ||
| self.args.worker_components, self.args.component_endpoints | ||
| ): | ||
| self.workers_clients.append( | ||
| await self.runtime.namespace("dynamo") | ||
| .component(component) | ||
| .endpoint(endpoint) | ||
| .client() | ||
| ) | ||
| logger.info(f"Component {component}/{endpoint} is registered") | ||
| logger.info(f"Total number of workers to be waited: {self.args.total_workers}") | ||
| logger.info(f"Timeout for waiting for workers to be ready: {self.args.timeout}") | ||
| self.server = HealthServer(("0.0.0.0", self.args.port), RequestHandler) | ||
| print(f"Serving on 0.0.0.0:{self.args.port}, listening to readiness check...") | ||
| self._server_thread = threading.Thread(target=start_server, args=(self.server,)) | ||
| self._server_thread.start() | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await check_required_workers( | ||
| self.workers_clients, self.args.total_workers, self.args.timeout | ||
| ) | ||
| self.server.set_ready(True) | ||
| logger.info("All workers are ready.") | ||
|
|
||
|
|
||
| async def check_required_workers( | ||
| workers_clients, required_workers: int, timeout: int, poll_interval=1 | ||
| ): | ||
| """Wait until the minimum number of workers are ready.""" | ||
| start_time = time.time() | ||
| num_workers = 0 | ||
| while num_workers < required_workers and time.time() - start_time < timeout: | ||
| num_workers = sum(map(lambda wc: len(wc.instance_ids()), workers_clients)) | ||
| if num_workers < required_workers: | ||
| logger.info( | ||
| f"Waiting for more workers to be ready.\n" | ||
| f" Current: {num_workers}," | ||
| f" Required: {required_workers}" | ||
| ) | ||
| await asyncio.sleep(poll_interval) | ||
| if num_workers < required_workers: | ||
| raise TimeoutError( | ||
| f"Timed out waiting for {required_workers} workers to be ready." | ||
| ) | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
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,35 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # start nats and etcd | ||
| if [[ -z "${HEAD_NODE_IP}" ]]; then | ||
| nats-server -js & | ||
| etcd --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379 & | ||
| HEAD_NODE_IP=`hostname -i` | ||
| else | ||
| export NATS_SERVER=nats://${HEAD_NODE_IP}:4222 | ||
| export ETCD_ENDPOINTS=${HEAD_NODE_IP}:2379 | ||
| fi | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # start ray cluster | ||
| if [[ -z "${RAY_LEADER_NODE_IP}" ]]; then | ||
| ray start --head --port=6379 --disable-usage-stats | ||
| RAY_LEADER_NODE_IP=`hostname -i` | ||
GuanLuo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else | ||
| ray start --address=${RAY_LEADER_NODE_IP}:6379 | ||
| fi | ||
|
|
||
| echo "HEAD_NODE_IP=${HEAD_NODE_IP} RAY_LEADER_NODE_IP=${RAY_LEADER_NODE_IP=} source ${BASH_SOURCE[0]}" | ||
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.
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.