File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 13
13
from tqdm import tqdm
14
14
15
15
import vllm .envs as envs
16
- from vllm import LLM , SamplingParams
17
16
from vllm .benchmarks .lib .utils import (convert_to_pytorch_benchmark_format ,
18
17
write_to_json )
19
18
from vllm .engine .arg_utils import EngineArgs
@@ -85,6 +84,9 @@ def main(args: argparse.Namespace):
85
84
"Please set it to a valid path to use torch profiler." )
86
85
engine_args = EngineArgs .from_cli_args (args )
87
86
87
+ # Lazy import to avoid importing LLM when the bench command is not selected.
88
+ from vllm import LLM , SamplingParams
89
+
88
90
# NOTE(woosuk): If the request cannot be processed in a single batch,
89
91
# the engine will automatically process the request in multiple batches.
90
92
llm = LLM (** dataclasses .asdict (engine_args ))
Original file line number Diff line number Diff line change 8
8
import inspect
9
9
import json
10
10
import multiprocessing
11
+ import multiprocessing .forkserver as forkserver
11
12
import os
12
13
import signal
13
14
import socket
@@ -155,6 +156,15 @@ async def build_async_engine_client(
155
156
client_config : Optional [dict [str , Any ]] = None ,
156
157
) -> AsyncIterator [EngineClient ]:
157
158
159
+ if os .getenv ("VLLM_WORKER_MULTIPROC_METHOD" ) == "forkserver" :
160
+ # The executor is expected to be mp.
161
+ # Pre-import heavy modules in the forkserver process
162
+ logger .debug ("Setup forkserver with pre-imports" )
163
+ multiprocessing .set_start_method ('forkserver' )
164
+ multiprocessing .set_forkserver_preload (["vllm.v1.engine.async_llm" ])
165
+ forkserver .ensure_running ()
166
+ logger .debug ("Forkserver setup complete!" )
167
+
158
168
# Context manager to handle engine_client lifecycle
159
169
# Ensures everything is shutdown and cleaned up on error/exit
160
170
engine_args = AsyncEngineArgs .from_cli_args (args )
You can’t perform that action at this time.
0 commit comments