Unverified Commit 9cbf8031 authored by ishandhanani's avatar ishandhanani Committed by GitHub
Browse files

feat: add dynamo components for sglang (#1721)

parent 008bb1e6
# SPDX-FileCopyrightText: Copyright (c) 2020 Atalaya Tech. Inc
# 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.
# Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES
import argparse
import asyncio
import logging
from dynamo.runtime import DistributedRuntime, EtcdKvCache, dynamo_worker
from dynamo.runtime.logging import configure_dynamo_logging
configure_dynamo_logging()
logger = logging.getLogger(__name__)
@dynamo_worker()
async def clear_namespace(runtime: DistributedRuntime, namespace: str):
etcd_kv_cache = await EtcdKvCache.create(
runtime.etcd_client(),
f"/{namespace}/",
{},
)
await etcd_kv_cache.clear_all()
logger.info(f"Cleared /{namespace} in EtcdKvCache")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--namespace", type=str, required=True)
args = parser.parse_args()
asyncio.run(clear_namespace(args.namespace))
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Helper script to generate environment variables for each node during a multinode SGLang deployment
echo "=== USAGE ==="
echo "1. Run this script: ./gen_env_vars.sh"
echo "2. Enter the IP addresses when prompted"
echo "3. Copy the commands for the head prefill node and run them"
echo "4. Copy the commands for all other nodes and run them on each node"
echo "5. Proceed with starting your prefill and decode workers"
echo ""
# Prompt for IP addresses
read -p "Enter HEAD_PREFILL_NODE IP: " HEAD_PREFILL_NODE
read -p "Enter HEAD_DECODE_NODE IP: " HEAD_DECODE_NODE
# Validate inputs
if [ -z "$HEAD_PREFILL_NODE" ] || [ -z "$HEAD_DECODE_NODE" ]; then
echo "Error: Both IP addresses are required"
exit 1
fi
echo "=== HEAD PREFILL NODE ($HEAD_PREFILL_NODE) ==="
echo "Run all of these commands on the head prefill node:"
echo ""
echo "nats-server -js &"
echo "etcd --listen-client-urls http://0.0.0.0:2379 \\"
echo " --advertise-client-urls http://0.0.0.0:2379 \\"
echo " --listen-peer-urls http://0.0.0.0:2380 \\"
echo " --initial-cluster default=http://$HEAD_PREFILL_NODE:2380 &"
echo "export HEAD_PREFILL_NODE_IP=$HEAD_PREFILL_NODE"
echo "export HEAD_DECODE_NODE_IP=$HEAD_DECODE_NODE"
echo ""
echo "=== ALL OTHER NODES ==="
echo "Run these commands on all other nodes (prefill and decode):"
echo ""
echo "# Export environment variables"
echo "export NATS_SERVER=nats://$HEAD_PREFILL_NODE:4222"
echo "export ETCD_ENDPOINTS=http://$HEAD_PREFILL_NODE:2379"
echo "export HEAD_PREFILL_NODE_IP=$HEAD_PREFILL_NODE"
echo "export HEAD_DECODE_NODE_IP=$HEAD_DECODE_NODE"
......@@ -19,26 +19,18 @@ from argparse import Namespace
from sglang.srt.server_args import ServerArgs
from dynamo.sdk.cli.utils import reserve_free_port
from dynamo.sdk.lib.config import ServiceConfig
def parse_sglang_args(service_name, prefix) -> ServerArgs:
config = ServiceConfig.get_instance()
sglang_args = config.as_args(service_name, prefix=prefix)
def parse_sglang_args_inc(args: list[str]) -> ServerArgs:
parser = argparse.ArgumentParser()
bootstrap_port = _reserve_disaggregation_bootstrap_port()
# add future dynamo arguments here
ServerArgs.add_cli_args(parser)
args = parser.parse_args(sglang_args)
if not any(
arg.startswith("--disaggregation-bootstrap-port") for arg in sglang_args
):
args_dict = vars(args)
parsed_args = parser.parse_args(args)
if not any(arg.startswith("--disaggregation-bootstrap-port") for arg in args):
args_dict = vars(parsed_args)
args_dict["disaggregation_bootstrap_port"] = bootstrap_port
args = Namespace(**args_dict)
return ServerArgs.from_cli_args(args)
parsed_args = Namespace(**args_dict)
return ServerArgs.from_cli_args(parsed_args)
def _reserve_disaggregation_bootstrap_port():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment