-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathvalidate.py
More file actions
76 lines (59 loc) · 2.75 KB
/
validate.py
File metadata and controls
76 lines (59 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Validation functions for model configuration."""
from .model import InternalModelConfig
def is_dedicated_mode(config: InternalModelConfig) -> bool:
"""Return True if the config specifies dedicated mode (separate training and inference GPUs)."""
return "trainer_gpu_ids" in config and "inference_gpu_ids" in config
def validate_dedicated_config(config: InternalModelConfig) -> None:
"""Validate dedicated mode GPU configuration.
Raises ValueError if the configuration is invalid.
Does nothing if neither trainer_gpu_ids nor inference_gpu_ids is set (shared mode).
"""
has_trainer = "trainer_gpu_ids" in config
has_inference = "inference_gpu_ids" in config
if has_trainer != has_inference:
raise ValueError(
"trainer_gpu_ids and inference_gpu_ids must both be set or both unset"
)
if not has_trainer:
return
trainer_gpu_ids = config["trainer_gpu_ids"]
inference_gpu_ids = config["inference_gpu_ids"]
if not trainer_gpu_ids:
raise ValueError("trainer_gpu_ids must be non-empty")
if not inference_gpu_ids:
raise ValueError("inference_gpu_ids must be non-empty")
if set(trainer_gpu_ids) & set(inference_gpu_ids):
raise ValueError("trainer_gpu_ids and inference_gpu_ids must not overlap")
inference_gpu_count = len(inference_gpu_ids)
if trainer_gpu_ids[0] != 0:
raise ValueError(
"trainer_gpu_ids must start at GPU 0 (training runs in-process)"
)
expected = list(range(len(trainer_gpu_ids)))
if trainer_gpu_ids != expected:
raise ValueError(
"trainer_gpu_ids must be contiguous starting from 0 (e.g., [0], [0,1])"
)
# Reject settings that are incompatible with dedicated mode
if config.get("init_args", {}).get("fast_inference"):
raise ValueError(
"fast_inference is incompatible with dedicated mode "
"(dedicated mode runs vLLM as a subprocess, not in-process)"
)
if config.get("engine_args", {}).get("enable_sleep_mode"):
raise ValueError(
"enable_sleep_mode is incompatible with dedicated mode "
"(dedicated mode runs vLLM on a separate GPU, sleep/wake is not needed)"
)
engine_args = config.get("engine_args", {})
for key in ("data_parallel_size", "data_parallel_size_local"):
value = engine_args.get(key)
if value is None:
continue
if isinstance(value, bool) or not isinstance(value, int):
raise ValueError(f"{key} must be an integer in dedicated mode")
if value != inference_gpu_count:
raise ValueError(
f"{key} must equal len(inference_gpu_ids) ({inference_gpu_count}) "
"in dedicated mode"
)