chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:17:40 +08:00
commit f1825c8ceb
10096 changed files with 2364182 additions and 0 deletions
@@ -0,0 +1,20 @@
# config.yaml
applications:
- name: llm-direct-streaming
route_prefix: /
import_path: ray.serve.llm:build_openai_app
args:
llm_configs:
- model_loading_config:
model_id: qwen3.5-0.8b
model_source: Qwen/Qwen3.5-0.8B
deployment_config:
autoscaling_config:
min_replicas: 1
max_replicas: 4
engine_kwargs:
trust_remote_code: true
tensor_parallel_size: 1
enable_auto_tool_choice: true
tool_call_parser: qwen3_coder
reasoning_parser: qwen3
@@ -0,0 +1,88 @@
"""
This file serves as a documentation example and CI test.
Structure:
1. Monkeypatch setup: Ensures serve.run is non-blocking and removes accelerator requirements for CI testing.
2. Docs example (between __direct_streaming_custom_router_example_start/end__): Embedded in Sphinx docs via literalinclude.
3. Test validation (deployment status polling + cleanup)
Scope: validates the documented request_router_config snippet (config and the
build_openai_app call signature) for direct streaming.
"""
import time
from ray import serve
from ray.serve.schema import ApplicationStatus
from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
from ray.serve import llm
_original_serve_run = serve.run
_original_build_openai_app = llm.build_openai_app
def _non_blocking_serve_run(app, **kwargs):
"""Forces blocking=False for testing"""
kwargs["blocking"] = False
return _original_serve_run(app, **kwargs)
def _testing_build_openai_app(llm_serving_args):
"""Removes accelerator requirements for testing"""
for config in llm_serving_args["llm_configs"]:
config.accelerator_type = None
return _original_build_openai_app(llm_serving_args)
serve.run = _non_blocking_serve_run
llm.build_openai_app = _testing_build_openai_app
# __direct_streaming_custom_router_example_start__
from ray.serve.config import RequestRouterConfig
from ray.serve.llm import LLMConfig
llm_config = LLMConfig(
model_loading_config={
"model_id": "qwen3.5-0.8b",
"model_source": "Qwen/Qwen3.5-0.8B",
},
deployment_config={
"request_router_config": RequestRouterConfig(
request_router_class="ray.serve.experimental.consistent_hash_router.ConsistentHashRouter",
),
},
engine_kwargs={
"trust_remote_code": True,
"tensor_parallel_size": 1,
"enable_auto_tool_choice": True,
"tool_call_parser": "qwen3_coder",
"reasoning_parser": "qwen3",
},
)
# __direct_streaming_custom_router_example_end__
from ray.serve.llm import build_openai_app
app = build_openai_app({"llm_configs": [llm_config]})
serve.run(app)
status = ApplicationStatus.NOT_STARTED
timeout_seconds = 180
start_time = time.time()
while (
status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
if status in [ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY]:
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)
if status != ApplicationStatus.RUNNING:
raise AssertionError(
f"Deployment failed to reach RUNNING status within {timeout_seconds}s. Current status: {status}"
)
serve.shutdown()
@@ -0,0 +1,88 @@
"""
This file serves as a documentation example and CI test.
Structure:
1. Monkeypatch setup: Ensures serve.run is non-blocking and removes accelerator requirements for CI testing.
2. Docs example (between __direct_streaming_example_start/end__): Embedded in Sphinx docs via literalinclude.
3. Test validation (deployment status polling + cleanup)
Scope: builds and deploys the documented snippet with direct streaming enabled.
The bazel target sets ``RAY_SERVE_ENABLE_HA_PROXY`` and
``RAY_SERVE_LLM_ENABLE_DIRECT_STREAMING``, so build_openai_app returns the
direct streaming deployment and the app reaches RUNNING on the HAProxy ingress.
The end-to-end streaming data path is covered by the openai-compatibility
direct-streaming test suite.
"""
import time
from ray import serve
from ray.serve.schema import ApplicationStatus
from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
from ray.serve import llm
_original_serve_run = serve.run
_original_build_openai_app = llm.build_openai_app
def _non_blocking_serve_run(app, **kwargs):
"""Forces blocking=False for testing"""
kwargs["blocking"] = False
return _original_serve_run(app, **kwargs)
def _testing_build_openai_app(llm_serving_args):
"""Removes accelerator requirements for testing"""
for config in llm_serving_args["llm_configs"]:
config.accelerator_type = None
return _original_build_openai_app(llm_serving_args)
serve.run = _non_blocking_serve_run
llm.build_openai_app = _testing_build_openai_app
# __direct_streaming_example_start__
from ray import serve
from ray.serve.llm import LLMConfig, build_openai_app
llm_config = LLMConfig(
model_loading_config={
"model_id": "qwen3.5-0.8b",
"model_source": "Qwen/Qwen3.5-0.8B",
},
deployment_config={
"autoscaling_config": {"min_replicas": 1, "max_replicas": 4},
},
engine_kwargs={
"trust_remote_code": True,
"tensor_parallel_size": 1,
"enable_auto_tool_choice": True,
"tool_call_parser": "qwen3_coder",
"reasoning_parser": "qwen3",
},
)
app = build_openai_app({"llm_configs": [llm_config]})
serve.run(app)
# __direct_streaming_example_end__
status = ApplicationStatus.NOT_STARTED
timeout_seconds = 180
start_time = time.time()
while (
status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
if status in [ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY]:
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)
if status != ApplicationStatus.RUNNING:
raise AssertionError(
f"Deployment failed to reach RUNNING status within {timeout_seconds}s. Current status: {status}"
)
serve.shutdown()
@@ -0,0 +1,62 @@
"""
This file serves as a documentation example and CI test for the direct
streaming YAML config.
Structure:
1. Load the YAML config shown in the guide and convert it to an app with
build_openai_app, removing accelerator requirements for CI testing.
2. Test validation (deployment status polling + cleanup).
Scope: validates that the documented config.yaml parses into a valid
LLMServingArgs and deploys with direct streaming enabled. The bazel target sets
RAY_SERVE_ENABLE_HA_PROXY and RAY_SERVE_LLM_ENABLE_DIRECT_STREAMING, so the app
reaches RUNNING on the HAProxy ingress. The end-to-end streaming data path is
covered by the openai-compatibility direct-streaming test suite.
"""
import time
import os
import yaml
from ray import serve
from ray.serve.schema import ApplicationStatus
from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
from ray.serve import llm
config_path = os.path.join(os.path.dirname(__file__), "direct_streaming_config.yaml")
with open(config_path, "r") as f:
config_dict = yaml.safe_load(f)
llm_configs = config_dict["applications"][0]["args"]["llm_configs"]
for config in llm_configs:
config.pop("accelerator_type", None)
# Disable compile cache to avoid cache corruption in CI
if "runtime_env" not in config:
config["runtime_env"] = {}
if "env_vars" not in config["runtime_env"]:
config["runtime_env"]["env_vars"] = {}
config["runtime_env"]["env_vars"]["VLLM_DISABLE_COMPILE_CACHE"] = "1"
app = llm.build_openai_app({"llm_configs": llm_configs})
serve.run(app, blocking=False)
status = ApplicationStatus.NOT_STARTED
timeout_seconds = 180
start_time = time.time()
while (
status != ApplicationStatus.RUNNING and time.time() - start_time < timeout_seconds
):
status = serve.status().applications[SERVE_DEFAULT_APP_NAME].status
if status in [ApplicationStatus.DEPLOY_FAILED, ApplicationStatus.UNHEALTHY]:
raise AssertionError(f"Deployment failed with status: {status}")
time.sleep(1)
if status != ApplicationStatus.RUNNING:
raise AssertionError(
f"Deployment failed to reach RUNNING status within {timeout_seconds}s. Current status: {status}"
)
serve.shutdown()