Skip to content

Commit

Permalink
Rename to --routing-logic
Browse files Browse the repository at this point in the history
Signed-off-by: KuntaiDu <[email protected]>
  • Loading branch information
KuntaiDu committed Mar 6, 2025
1 parent 49dd17a commit d9afbd0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
6 changes: 2 additions & 4 deletions src/vllm_router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The router can be configured using command-line arguments. Below are the availab

### Routing Logic Options

- `--routing-affinity`: The routing logic to use. Options are `roundrobin` or `session`. This option is required.
- `--routing-logic`: The routing logic to use. Options are `roundrobin` or `session`. This option is required.
- `--session-key`: The key (in the header) to identify a session.

### Monitoring Options
Expand Down Expand Up @@ -71,9 +71,7 @@ vllm-router --port 8000 \
--static-models "facebook/opt-125m,meta-llama/Llama-3.1-8B-Instruct,facebook/opt-125m" \
--engine-stats-interval 10 \
--log-stats \
--routing-affinity longest_prefix \
--endpoint-filters num_queueing_request \
--endpoint-filters-configs {}
--routing-logic longest_prefix
```

## Dynamic Router Config
Expand Down
4 changes: 2 additions & 2 deletions src/vllm_router/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def initialize_all(app: FastAPI, args):
)

initialize_routing_logic(
args.routing_affinity,
args.routing_logic,
args.session_key,
args.routing_affinity_config,
args.routing_logic_config,
args.endpoint_filters,
args.endpoint_filters_configs,
)
Expand Down
8 changes: 4 additions & 4 deletions src/vllm_router/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate_args(args):
)
if args.service_discovery == "k8s" and args.k8s_port is None:
raise ValueError("K8s port must be provided when using K8s service discovery.")
if args.routing_affinity == "session" and args.session_key is None:
if args.routing_logic == "session" and args.session_key is None:
raise ValueError(
"Session key must be provided when using session routing affinity."
)
Expand Down Expand Up @@ -96,7 +96,7 @@ def parse_args():
help="The label selector to filter vLLM pods when using K8s service discovery.",
)
parser.add_argument(
"--routing-affinity",
"--routing-logic",
type=str,
required=True,
choices=["roundrobin", "session", "longest_prefix", "simhash"],
Expand All @@ -107,11 +107,11 @@ def parse_args():
type=str,
default=None,
help="The key (in the header) to identify a session. This is a shortcut"
" for --routing-affinity-config "
" for --routing-logic-config "
'\'{"session_key": "<session_key>"}\'.',
)
parser.add_argument(
"--routing-affinity-config",
"--routing-logic-config",
type=str,
default="{}",
help="The routing configuration in JSON format.",
Expand Down
36 changes: 18 additions & 18 deletions src/vllm_router/routers/routing_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Router(RoutingInterface):

def __init__(
self,
routing_affinity: str,
routing_affinity_config: Dict[str, Any],
routing_logic: str,
routing_logic_config: Dict[str, Any],
endpoint_filters: List[str],
endpoint_filters_configs: List[Dict[str, Any]],
):
Expand All @@ -57,26 +57,26 @@ def __init__(
return

self.reconfigure(
routing_affinity=routing_affinity,
routing_affinity_config=routing_affinity_config,
routing_logic=routing_logic,
routing_logic_config=routing_logic_config,
endpoint_filters=endpoint_filters,
endpoint_filters_configs=endpoint_filters_configs,
)
self.initialized = True

def reconfigure(
self,
routing_affinity: str,
routing_affinity_config: str,
routing_logic: str,
routing_logic_config: str,
endpoint_filters: List[str],
endpoint_filters_configs: List[str],
):

# Initialize the affinity module
self.affinity = None

routing_affinity_config = json.loads(routing_affinity_config)
self.affinity = get_affinity(routing_affinity, **routing_affinity_config)
routing_logic_config = json.loads(routing_logic_config)
self.affinity = get_affinity(routing_logic, **routing_logic_config)

# Initialize the endpoint filters
self.endpoint_filters = []
Expand Down Expand Up @@ -145,37 +145,37 @@ def route_request(

# Instead of managing a global _global_router, we can define the initialization functions as:
def initialize_routing_logic(
routing_affinity: str,
routing_logic: str,
session_key: str,
routing_affinity_config: str,
routing_logic_config: str,
endpoint_filters: List[str],
endpoint_filters_configs: str,
) -> RoutingInterface:

global _router
assert _router is None, "Routing logic already initialized"
if routing_affinity == "session":
routing_affinity_config.update({"session_key": session_key})
if routing_logic == "session":
routing_logic_config.update({"session_key": session_key})
_router = Router(
routing_affinity=routing_affinity,
routing_affinity_config=routing_affinity_config,
routing_logic=routing_logic,
routing_logic_config=routing_logic_config,
endpoint_filters=endpoint_filters,
endpoint_filters_configs=endpoint_filters_configs,
)
return _router


def reconfigure_routing_logic(
routing_affinity: str,
routing_logic: str,
session_key: str,
routing_affinity_config: str,
routing_logic_config: str,
endpoint_filters: List[str],
endpoint_filters_configs: str,
) -> RoutingInterface:
global _router
_router.reconfigure(
routing_affinity=routing_affinity,
routing_affinity_config=routing_affinity_config,
routing_logic=routing_logic,
routing_logic_config=routing_logic_config,
endpoint_filters=endpoint_filters,
endpoint_filters_configs=endpoint_filters_configs,
)
Expand Down
12 changes: 6 additions & 6 deletions src/vllm_router/services/routing_service/affinity/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
}


def get_affinity(routing_affinity_name: str, **kwargs) -> BaseAffinity:
def get_affinity(routing_logic_name: str, **kwargs) -> BaseAffinity:

if routing_affinity_name not in affinity_name_to_class:
raise ValueError(f"Invalid affinity name: {routing_affinity_name}")
if routing_logic_name not in affinity_name_to_class:
raise ValueError(f"Invalid affinity name: {routing_logic_name}")

routing_affinity_config = kwargs
routing_logic_config = kwargs

logger.info(
f"Using affinity type: {routing_affinity_name} with config: {routing_affinity_config}"
f"Using affinity type: {routing_logic_name} with config: {routing_logic_config}"
)
return affinity_name_to_class[routing_affinity_name](**routing_affinity_config)
return affinity_name_to_class[routing_logic_name](**routing_logic_config)

0 comments on commit d9afbd0

Please sign in to comment.