x
This commit is contained in:
+41
-28
@@ -1,10 +1,9 @@
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
import os
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from app.model_catalog import load_catalog, resolve_model_profile, resolve_runtime_settings
|
from app.model_catalog import load_app_config
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseModel):
|
class Settings(BaseModel):
|
||||||
@@ -35,35 +34,49 @@ class Settings(BaseModel):
|
|||||||
enable_auto_tool_choice: bool = False
|
enable_auto_tool_choice: bool = False
|
||||||
revision: Optional[str] = None
|
revision: Optional[str] = None
|
||||||
api_key: Optional[str] = None
|
api_key: Optional[str] = None
|
||||||
|
quantization: Optional[str] = None
|
||||||
|
model_impl: Optional[str] = None
|
||||||
|
reasoning_parser: Optional[str] = None
|
||||||
|
kv_cache_dtype: Optional[str] = None
|
||||||
|
enable_prefix_caching: bool = False
|
||||||
|
max_num_batched_tokens: int = 0
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=1)
|
@lru_cache(maxsize=1)
|
||||||
def get_settings() -> Settings:
|
def get_settings() -> Settings:
|
||||||
catalog = load_catalog("config.json")
|
config = load_app_config("config.json")
|
||||||
runtime = resolve_runtime_settings(catalog)
|
return Settings(
|
||||||
settings = Settings(
|
|
||||||
config_file="config.json",
|
config_file="config.json",
|
||||||
model_key=runtime["model_key"],
|
model_key=config.get("model_key"),
|
||||||
host=runtime["host"],
|
selected_model=config.get("selected_model"),
|
||||||
port=runtime["port"],
|
model_name=config.get("model_name", ""),
|
||||||
openai_host=runtime["openai_host"],
|
served_model_name=config.get("served_model_name"),
|
||||||
openai_port=runtime["openai_port"],
|
host=config.get("host", "0.0.0.0"),
|
||||||
vllm_openai_internal_url=runtime["vllm_openai_internal_url"],
|
port=config.get("port", 8000),
|
||||||
public_model_name=runtime["public_model_name"],
|
openai_host=config.get("openai_host", "0.0.0.0"),
|
||||||
default_enable_thinking=runtime["default_enable_thinking"],
|
openai_port=config.get("openai_port", 8001),
|
||||||
reasoning_enabled=runtime["reasoning_enabled"],
|
vllm_openai_internal_url=config.get("vllm_openai_internal_url", "http://127.0.0.1:8001/v1"),
|
||||||
model_root=runtime["model_root"],
|
public_model_name=config.get("public_model_name", "Qwen_local_model"),
|
||||||
offline_mode=runtime["offline_mode"],
|
default_enable_thinking=config.get("default_enable_thinking", False),
|
||||||
api_key=runtime["api_key"],
|
reasoning_enabled=config.get("reasoning_enabled", False),
|
||||||
tensor_parallel_size=runtime["tensor_parallel_size"],
|
model_root=config.get("model_root", "/opt/model"),
|
||||||
dtype=runtime["dtype"],
|
offline_mode=config.get("offline_mode", True),
|
||||||
revision=runtime["revision"],
|
max_model_len=config.get("max_model_len", 8192),
|
||||||
|
gpu_memory_utilization=config.get("gpu_memory_utilization", 0.92),
|
||||||
|
tensor_parallel_size=config.get("tensor_parallel_size", 2),
|
||||||
|
max_num_seqs=config.get("max_num_seqs", 64),
|
||||||
|
max_tokens=config.get("max_tokens", 4096),
|
||||||
|
dtype=config.get("dtype", "bfloat16"),
|
||||||
|
enforce_eager=config.get("enforce_eager", False),
|
||||||
|
trust_remote_code=config.get("trust_remote_code", False),
|
||||||
|
tool_call_parser=config.get("tool_call_parser"),
|
||||||
|
enable_auto_tool_choice=config.get("enable_auto_tool_choice", False),
|
||||||
|
revision=config.get("revision"),
|
||||||
|
api_key=config.get("api_key"),
|
||||||
|
quantization=config.get("quantization"),
|
||||||
|
model_impl=config.get("model_impl"),
|
||||||
|
reasoning_parser=config.get("reasoning_parser"),
|
||||||
|
kv_cache_dtype=config.get("kv_cache_dtype"),
|
||||||
|
enable_prefix_caching=config.get("enable_prefix_caching", False),
|
||||||
|
max_num_batched_tokens=config.get("max_num_batched_tokens", 0),
|
||||||
)
|
)
|
||||||
_, updates, env_vars = resolve_model_profile(
|
|
||||||
content=catalog,
|
|
||||||
requested_model=settings.model_key,
|
|
||||||
requested_tp=settings.tensor_parallel_size,
|
|
||||||
)
|
|
||||||
for key, value in env_vars.items():
|
|
||||||
os.environ[key] = value
|
|
||||||
return settings.model_copy(update=updates | runtime)
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -151,3 +152,25 @@ def resolve_model_profile(
|
|||||||
if "VLLM_WORKER_MULTIPROC_METHOD" not in env_vars:
|
if "VLLM_WORKER_MULTIPROC_METHOD" not in env_vars:
|
||||||
env_vars["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
|
env_vars["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
|
||||||
return model_key, updates, env_vars
|
return model_key, updates, env_vars
|
||||||
|
|
||||||
|
|
||||||
|
def load_app_config(config_file: str = "config.json") -> dict[str, Any]:
|
||||||
|
"""
|
||||||
|
统一的应用配置加载函数,封装完整的配置加载流程。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config_file: 配置文件路径,默认为 "config.json"
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
包含合并后配置的字典,包括 runtime settings 和 model profile updates
|
||||||
|
"""
|
||||||
|
catalog = load_catalog(config_file)
|
||||||
|
runtime = resolve_runtime_settings(catalog)
|
||||||
|
_, updates, env_vars = resolve_model_profile(
|
||||||
|
content=catalog,
|
||||||
|
requested_model=runtime["model_key"],
|
||||||
|
requested_tp=runtime["tensor_parallel_size"],
|
||||||
|
)
|
||||||
|
for key, value in env_vars.items():
|
||||||
|
os.environ[key] = value
|
||||||
|
return {**runtime, **updates}
|
||||||
|
|||||||
+29
-39
@@ -1,33 +1,23 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from app.model_catalog import load_catalog, resolve_model_profile, resolve_runtime_settings
|
from app.model_catalog import load_app_config
|
||||||
|
|
||||||
|
|
||||||
def build_command() -> list[str]:
|
def build_command() -> list[str]:
|
||||||
config_file = "config.json"
|
config = load_app_config("config.json")
|
||||||
catalog = load_catalog(config_file)
|
host = str(config["openai_host"])
|
||||||
runtime = resolve_runtime_settings(catalog)
|
port = str(config["openai_port"])
|
||||||
_, updates, env_vars = resolve_model_profile(
|
public_model_name = str(config["public_model_name"]).strip()
|
||||||
content=catalog,
|
default_enable_thinking = bool(config["default_enable_thinking"])
|
||||||
requested_model=runtime["model_key"],
|
reasoning_enabled = bool(config["reasoning_enabled"])
|
||||||
requested_tp=runtime["tensor_parallel_size"],
|
api_key = config.get("api_key") or ""
|
||||||
)
|
dtype = str(config.get("dtype", "bfloat16"))
|
||||||
for key, value in env_vars.items():
|
quantization = str(config.get("quantization", "")).strip()
|
||||||
os.environ[key] = value
|
model_impl = str(config.get("model_impl", "")).strip()
|
||||||
host = str(runtime["openai_host"])
|
reasoning_parser = str(config.get("reasoning_parser", "")).strip()
|
||||||
port = str(runtime["openai_port"])
|
revision = config.get("revision", "") or ""
|
||||||
public_model_name = str(runtime["public_model_name"]).strip()
|
|
||||||
default_enable_thinking = bool(runtime["default_enable_thinking"])
|
|
||||||
reasoning_enabled = bool(runtime["reasoning_enabled"])
|
|
||||||
api_key = runtime["api_key"] or ""
|
|
||||||
dtype = str(updates["dtype"] or runtime["dtype"])
|
|
||||||
quantization = str(updates["quantization"] or "").strip()
|
|
||||||
model_impl = str(updates["model_impl"] or "").strip()
|
|
||||||
reasoning_parser = str(updates["reasoning_parser"] or "").strip()
|
|
||||||
revision = runtime["revision"] or ""
|
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable,
|
sys.executable,
|
||||||
"-m",
|
"-m",
|
||||||
@@ -37,28 +27,28 @@ def build_command() -> list[str]:
|
|||||||
"--port",
|
"--port",
|
||||||
port,
|
port,
|
||||||
"--model",
|
"--model",
|
||||||
str(updates["model_name"]),
|
str(config["model_name"]),
|
||||||
"--served-model-name",
|
"--served-model-name",
|
||||||
public_model_name or str(updates["served_model_name"]),
|
public_model_name or str(config["served_model_name"]),
|
||||||
"--tensor-parallel-size",
|
"--tensor-parallel-size",
|
||||||
str(updates["tensor_parallel_size"]),
|
str(config["tensor_parallel_size"]),
|
||||||
"--max-model-len",
|
"--max-model-len",
|
||||||
str(updates["max_model_len"]),
|
str(config["max_model_len"]),
|
||||||
"--gpu-memory-utilization",
|
"--gpu-memory-utilization",
|
||||||
str(updates["gpu_memory_utilization"]),
|
str(config["gpu_memory_utilization"]),
|
||||||
"--max-num-seqs",
|
"--max-num-seqs",
|
||||||
str(updates["max_num_seqs"]),
|
str(config["max_num_seqs"]),
|
||||||
"--dtype",
|
"--dtype",
|
||||||
dtype,
|
dtype,
|
||||||
]
|
]
|
||||||
if updates["trust_remote_code"]:
|
if config["trust_remote_code"]:
|
||||||
cmd.append("--trust-remote-code")
|
cmd.append("--trust-remote-code")
|
||||||
if updates["enforce_eager"]:
|
if config["enforce_eager"]:
|
||||||
cmd.append("--enforce-eager")
|
cmd.append("--enforce-eager")
|
||||||
if updates["enable_auto_tool_choice"]:
|
if config["enable_auto_tool_choice"]:
|
||||||
cmd.append("--enable-auto-tool-choice")
|
cmd.append("--enable-auto-tool-choice")
|
||||||
if updates["tool_call_parser"]:
|
if config["tool_call_parser"]:
|
||||||
cmd.extend(["--tool-call-parser", str(updates["tool_call_parser"])])
|
cmd.extend(["--tool-call-parser", str(config["tool_call_parser"])])
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
"--default-chat-template-kwargs",
|
"--default-chat-template-kwargs",
|
||||||
@@ -75,12 +65,12 @@ def build_command() -> list[str]:
|
|||||||
cmd.extend(["--revision", revision])
|
cmd.extend(["--revision", revision])
|
||||||
if api_key:
|
if api_key:
|
||||||
cmd.extend(["--api-key", api_key])
|
cmd.extend(["--api-key", api_key])
|
||||||
if updates.get("kv_cache_dtype"):
|
if config.get("kv_cache_dtype"):
|
||||||
cmd.extend(["--kv-cache-dtype", str(updates["kv_cache_dtype"])])
|
cmd.extend(["--kv-cache-dtype", str(config["kv_cache_dtype"])])
|
||||||
if updates.get("enable_prefix_caching"):
|
if config.get("enable_prefix_caching"):
|
||||||
cmd.append("--enable-prefix-caching")
|
cmd.append("--enable-prefix-caching")
|
||||||
if updates.get("max_num_batched_tokens", 0) > 0:
|
if config.get("max_num_batched_tokens", 0) > 0:
|
||||||
cmd.extend(["--max-num-batched-tokens", str(updates["max_num_batched_tokens"])])
|
cmd.extend(["--max-num-batched-tokens", str(config["max_num_batched_tokens"])])
|
||||||
if updates.get("language_model_only"):
|
if updates.get("language_model_only"):
|
||||||
cmd.append("--language-model-only")
|
cmd.append("--language-model-only")
|
||||||
speculative_method = str(updates.get("speculative_method") or "").strip()
|
speculative_method = str(updates.get("speculative_method") or "").strip()
|
||||||
|
|||||||
+2
-2
@@ -69,7 +69,7 @@
|
|||||||
"local_path": "Qwen3.6-27B-FP8",
|
"local_path": "Qwen3.6-27B-FP8",
|
||||||
"dtype": "auto",
|
"dtype": "auto",
|
||||||
"quantization": "fp8",
|
"quantization": "fp8",
|
||||||
"ctx": "65536",
|
"ctx": "131072",
|
||||||
"max_tokens": "32768",
|
"max_tokens": "32768",
|
||||||
"max_num_batched_tokens": 16384,
|
"max_num_batched_tokens": 16384,
|
||||||
"trust_remote": true,
|
"trust_remote": true,
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
2
|
2
|
||||||
],
|
],
|
||||||
"max_num_seqs": 32,
|
"max_num_seqs": 32,
|
||||||
"gpu_util": "0.88",
|
"gpu_util": "0.75",
|
||||||
"tool_call_parser": "qwen3_coder",
|
"tool_call_parser": "qwen3_coder",
|
||||||
"reasoning_parser": "qwen3",
|
"reasoning_parser": "qwen3",
|
||||||
"enable_auto_tool_choice": true,
|
"enable_auto_tool_choice": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user