Skip to content

vllm.entrypoints.cli.preload

The preload subcommand for the vLLM CLI.

Launches one weight cache daemon per GPU; each daemon holds the post-quantized, TP-sharded weights of its rank in GPU memory and serves CUDA IPC handles to vLLM engines over a Unix domain socket, so restarting engines can map the weights via zero-copy IPC instead of reloading from disk:

vllm preload --model /path/to/model --tensor-parallel-size 4

Engines then load from the daemons with:

vllm serve /path/to/model --tensor-parallel-size 4 --load-format ipc_cache

Tensor, expert and data parallelism are supported, including across nodes; see vllm/model_executor/model_loader/weight_cache/daemon.py for the rank layout and rendezvous details.

A second replica's daemons can instead pull their weights from a loaded replica (--weight-cache-seed); see docs/features/preload.md.

Classes:

PreloadSubcommand

Bases: CLISubcommand

The preload subcommand for the vLLM CLI.

Source code in vllm/entrypoints/cli/preload.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
class PreloadSubcommand(CLISubcommand):
    """The `preload` subcommand for the vLLM CLI."""

    name = "preload"

    @staticmethod
    def add_cli_args(parser: FlexibleArgumentParser) -> None:
        EngineArgs.add_cli_args(parser)
        parser.add_argument(
            "--weight-cache-socket-dir",
            type=str,
            default=None,
            help="Directory for the daemon Unix sockets (default: tempdir).",
        )
        parser.add_argument(
            "--weight-cache-master-port",
            type=int,
            default=None,
            help="Rendezvous port for the daemon's own TP group. Must differ "
            "from the engine's --master-port (the daemons may still be loading "
            "when the engine starts) and match across nodes. Required when "
            "--nnodes > 1; defaults to a free port for single-node.",
        )
        parser.add_argument(
            "--weight-cache-draft-master-port",
            type=int,
            default=None,
            help="Rendezvous port for the MTP draft daemon group. Defaults to "
            "--weight-cache-master-port + 1 for multi-node, or a free port "
            "for single-node.",
        )
        parser.add_argument(
            "--weight-cache-health-port",
            type=int,
            default=None,
            help="Port for the parent /health endpoint; disabled by default.",
        )
        parser.add_argument(
            "--weight-cache-health-host",
            type=str,
            default="0.0.0.0",
            help="Host for the parent /health endpoint (default: 0.0.0.0).",
        )
        parser.add_argument(
            "--seed-listen-host",
            type=str,
            default=None,
            help="Host to bind for authenticated daemon-to-daemon requests.",
        )
        parser.add_argument(
            "--seed-listen-port",
            type=int,
            default=None,
            help="Base port for daemon-to-daemon requests; each daemon binds "
            "base_port + group offset + its global rank.",
        )
        parser.add_argument(
            "--seed-source-host",
            type=str,
            default=None,
            help="Host of a source daemon replica to seed warmup caches from.",
        )
        parser.add_argument(
            "--seed-source-port",
            type=int,
            default=None,
            help="Base port of the source daemon replica; each daemon dials "
            "base_port + group offset + its global rank.",
        )
        parser.add_argument(
            "--seed-token",
            type=str,
            default=None,
            help="Shared secret for daemon-to-daemon requests. The JSON "
            "connection is unencrypted; use a trusted network.",
        )
        parser.add_argument(
            "--weight-cache-seed",
            type=str,
            default=None,
            help="Fill these daemons from an already-loaded replica instead "
            "of the checkpoint: each daemon still builds its model (config "
            "files required, safetensors not) and pulls the post-processed "
            "weights from its rank-matched source. For same-host CUDA IPC, "
            "pass one target Unix socket per local GPU (comma separated, in "
            "device order); draft daemons use the corresponding *_draft.sock "
            "paths. For cross-host Mooncake RDMA, pass one host:base_port per "
            "source node (comma separated, in node_rank order); each rank "
            "selects its node's address and dials base_port + group offset + "
            "its global rank.",
        )
        parser.add_argument(
            "--warmup-cache-stores",
            type=str,
            default=None,
            help="Comma-separated shared store backends mirroring the "
            "warmup caches (e.g. 'mooncake', connected via "
            "MOONCAKE_CONFIG_PATH). The local disk cache is always the "
            "first tier; these add shared tiers that reads fall back to "
            "and tuned tables are published to.",
        )

    @staticmethod
    def cmd(args: argparse.Namespace) -> None:
        # Imported here so `vllm --help` and friends stay free of torch.
        from vllm.model_executor.model_loader.weight_cache.daemon import (
            _reject_unsupported_parallelism,
            _run_daemon,
            daemon_serves_model,
            get_draft_daemon_config,
            plan_local_ranks,
        )
        from vllm.model_executor.model_loader.weight_cache.transport import SeedConfig
        from vllm.model_executor.model_loader.weight_cache.utils import (
            format_daemon_role,
        )
        from vllm.model_executor.model_loader.weight_cache.weight_seed.seed import (
            WEIGHT_COPY_LEASE_TIMEOUT_S,
        )

        engine_args = EngineArgs.from_cli_args(args)
        # Warmup context for flashinfer autotune.
        usage_context = (
            UsageContext.OPENAI_API_SERVER
            if engine_args.kernel_config.enable_flashinfer_autotune is not False
            else None
        )
        vllm_config = engine_args.create_engine_config(usage_context=usage_context)
        load_format = vllm_config.load_config.load_format
        if load_format in ("ipc_cache", "peer_cache"):
            raise ValueError(
                f"--load-format {load_format} is not accepted here: the "
                "weight cache daemon loads from disk by default, and "
                "--weight-cache-seed switches it to peer_cache internally"
            )
        # Config-only so it can fail before any model loading; the quant
        # method check needs the created model and runs in
        # WeightCacheDaemon.get_model.
        check_ipc_platform_support()
        parallel_config = vllm_config.parallel_config
        _reject_unsupported_parallelism(parallel_config)
        tp_size = parallel_config.tensor_parallel_size
        pp_size = parallel_config.pipeline_parallel_size
        dp_size = parallel_config.data_parallel_size
        world_size = dp_size * pp_size * tp_size

        placements = plan_local_ranks(parallel_config)
        local_world_size = len(placements)
        if dp_size == 1:
            nnodes = parallel_config.nnodes
            node_rank = parallel_config.node_rank
            master_addr = parallel_config.master_addr
        else:
            master_addr = parallel_config.data_parallel_master_ip
            if parallel_config.nnodes > 1:
                nnodes = parallel_config.nnodes
                node_rank = parallel_config.node_rank
            else:
                nnodes = dp_size // parallel_config.data_parallel_size_local
                node_rank = parallel_config.data_parallel_rank // (
                    parallel_config.data_parallel_size_local
                )
            if nnodes > 1 and master_addr in ("127.0.0.1", "localhost"):
                raise ValueError(
                    "Data parallelism across nodes requires a reachable "
                    "--data-parallel-address for the daemon rendezvous"
                )

        # The daemon forms its own world group and holds it open while
        # serving, so it needs a rendezvous port distinct from the engine's.
        # All nodes must agree on it; single-node can auto-pick a free port.
        # The master address is the engine's --master-addr (TP across nodes)
        # or --data-parallel-address.
        if nnodes > 1 and args.weight_cache_master_port is None:
            raise ValueError(
                "--weight-cache-master-port is required when the daemons span nodes"
            )
        master_port = args.weight_cache_master_port or get_open_port()
        distributed_init_method = get_distributed_init_method(master_addr, master_port)

        # (is_draft, vllm_config, rendezvous) per daemon group.
        groups: list[tuple[bool, VllmConfig, str]] = [
            (False, vllm_config, distributed_init_method)
        ]
        draft_vllm_config = get_draft_daemon_config(vllm_config)
        if draft_vllm_config is not None:
            draft_master_port = args.weight_cache_draft_master_port or (
                master_port + 1 if nnodes > 1 else get_open_port()
            )
            if draft_master_port == master_port:
                raise ValueError(
                    "--weight-cache-draft-master-port must differ from "
                    "--weight-cache-master-port"
                )
            groups.append(
                (
                    True,
                    draft_vllm_config,
                    get_distributed_init_method(master_addr, draft_master_port),
                )
            )

        ctx = multiprocessing.get_context("spawn")
        ready_queue: multiprocessing.Queue[tuple[str, int]] = ctx.Queue()
        # Local index == device index; global rank enumerates DP, PP, then TP.
        expected_ready = {
            (
                format_daemon_role(is_draft),
                dp_rank * pp_size * tp_size + pp_rank * tp_size + tp_rank,
            )
            for (is_draft, _, _), (_, dp_rank, pp_rank, tp_rank) in product(
                groups, placements
            )
            if daemon_serves_model(is_draft, pp_rank, pp_size)
        }
        seed_addresses = parse_seed_addresses(args.weight_cache_seed)
        _validate_seed_args(
            args,
            world_size=world_size,
            num_groups=len(groups),
            nnodes=nnodes,
            local_world_size=local_world_size,
            addresses=seed_addresses,
        )
        warmup_cache_stores = [
            name.strip()
            for name in (args.warmup_cache_stores or "").split(",")
            if name.strip()
        ]

        def _seed_endpoint(
            host: str | None, base_port: int | None, offset: int
        ) -> tuple[str, int] | None:
            # Validated above: host and port are provided together.
            if host is None or base_port is None:
                return None
            return host, base_port + offset

        mirror_devices = None
        if seed_addresses and all(
            isinstance(address, str) for address in seed_addresses
        ):
            # Same-host mirror: place every local daemon on a GPU the
            # source replica does not use, inferred from the source's GPUs.
            mirror_devices = mirror_device_indices(seed_addresses, local_world_size)

        procs: list[BaseProcess] = []
        serving: list[BaseProcess] = []
        for group_index, (is_draft, config, init_method) in enumerate(groups):
            # Draft daemons live past the target group's port block at every
            # source node.
            port_offset = group_index * world_size
            for local_rank, dp_rank, pp_rank, tp_rank in placements:
                global_rank = dp_rank * pp_size * tp_size + pp_rank * tp_size + tp_rank
                offset = port_offset + global_rank
                peer_source = seed_address(
                    seed_addresses,
                    local_rank,
                    global_rank,
                    port_offset,
                    node_rank=node_rank,
                    is_draft=is_draft,
                )
                source: str | tuple[str, int] | None
                if peer_source is not None:
                    daemon_config = peer_cache_config(config, is_draft=is_draft)
                    # The mirror also adopts the source's warmup caches (the
                    # FlashInfer autotune table) from the same address
                    # through the ordinary warmup-cache seeding path.
                    source = peer_source
                else:
                    daemon_config = config
                    source = _seed_endpoint(
                        args.seed_source_host, args.seed_source_port, offset
                    )
                seed_config = SeedConfig(
                    listen=_seed_endpoint(
                        args.seed_listen_host, args.seed_listen_port, offset
                    ),
                    source=source,
                    token=args.seed_token,
                )
                procs.append(
                    ctx.Process(
                        target=_run_daemon,
                        args=(
                            global_rank,
                            local_rank,
                            daemon_config,
                            init_method,
                            args.weight_cache_socket_dir,
                            ready_queue,
                            is_draft,
                            dp_rank,
                            pp_rank,
                            seed_config,
                            mirror_devices[local_rank]
                            if mirror_devices is not None
                            else None,
                            warmup_cache_stores,
                        ),
                        name=(
                            f"vllm-weight-cache-{format_daemon_role(is_draft)}-"
                            f"{global_rank}"
                        ),
                    )
                )
                if daemon_serves_model(is_draft, pp_rank, pp_size):
                    serving.append(procs[-1])
        health_state = _HealthState(serving)
        health_server = None
        health_thread = None
        if args.weight_cache_health_port is not None:
            health_server, health_thread = _start_health_server(
                args.weight_cache_health_host,
                args.weight_cache_health_port,
                health_state,
            )
        shutdown_requested = False
        exit_code = 0

        def _shutdown(signum, frame):
            nonlocal shutdown_requested, exit_code
            shutdown_requested = True
            exit_code = 128 + signum

        signal.signal(signal.SIGINT, _shutdown)
        signal.signal(signal.SIGTERM, _shutdown)

        started: list[BaseProcess] = []
        try:
            for proc in procs:
                if shutdown_requested:
                    break
                proc.start()
                started.append(proc)

            ready: set[tuple[str, int]] = set()
            while not shutdown_requested:
                # Daemons that serve no model exit cleanly after the rendezvous.
                dead = [
                    p
                    for p in procs
                    if p.exitcode is not None and (p in serving or p.exitcode != 0)
                ]
                if dead:
                    logger.error(
                        "Weight cache daemon rank(s) exited during %s "
                        "(exitcodes=%s); shutting down.",
                        "serving" if ready == expected_ready else "startup",
                        [p.exitcode for p in dead],
                    )
                    # Preserve the failure before terminating healthy siblings.
                    # A clean rank exit is also unexpected while serving.
                    failure = next((code for p in dead if (code := p.exitcode)), 1)
                    exit_code = 128 - failure if failure < 0 else failure
                    break
                if ready == expected_ready:
                    wait([p.sentinel for p in serving], timeout=1.0)
                    continue
                try:
                    ready.add(ready_queue.get(timeout=1.0))
                except queue.Empty:
                    continue
                if ready == expected_ready:
                    health_state.mark_ready()
                    socket_dir_msg = (
                        args.weight_cache_socket_dir or "the default socket dir"
                    )
                    logger.info_once(
                        "===== Weight cache daemon READY: node %d/%d serving %d "
                        "daemon(s) in %s =====",
                        node_rank,
                        nnodes,
                        len(expected_ready),
                        socket_dir_msg,
                    )
        finally:
            if health_server is not None:
                health_server.should_exit = True
            for proc in started:
                if proc.is_alive():
                    proc.terminate()
            # SIGTERM runs the daemon's lease-aware cleanup. Leave enough
            # time for outstanding copies to acknowledge before escalating
            # during an external shutdown; fail fast when a rank has exited.
            grace_period = (
                WEIGHT_COPY_LEASE_TIMEOUT_S + 30.0 if shutdown_requested else 10.0
            )
            deadline = time.monotonic() + grace_period
            for proc in started:
                proc.join(timeout=max(0.0, deadline - time.monotonic()))
            for proc in started:
                if proc.is_alive():
                    proc.kill()
            for proc in started:
                proc.join()
            if health_thread is not None:
                health_thread.join()
            ready_queue.close()
        sys.exit(exit_code)

    def subparser_init(
        self, subparsers: argparse._SubParsersAction
    ) -> FlexibleArgumentParser:
        preload_parser = subparsers.add_parser(
            self.name,
            help="Launch weight cache daemons (one per GPU) for fast engine restarts.",
            description="Launch weight cache daemons (one per GPU) that "
            "keep post-quantized weights in GPU memory and serve them to "
            "engines over CUDA IPC.",
            usage="vllm preload --model <model> [options]",
        )
        self.add_cli_args(preload_parser)
        preload_parser.epilog = VLLM_SUBCMD_PARSER_EPILOG.format(subcmd=self.name)
        return preload_parser

_validate_seed_args(args, *, world_size, num_groups, nnodes, local_world_size, addresses)

Validate the seed CLI options before any daemon spawns.

Source code in vllm/entrypoints/cli/preload.py
def _validate_seed_args(
    args: argparse.Namespace,
    *,
    world_size: int,
    num_groups: int,
    nnodes: int,
    local_world_size: int,
    addresses: list[SeedAddress],
) -> None:
    """Validate the seed CLI options before any daemon spawns."""
    for flag, host, port in (
        ("--seed-listen", args.seed_listen_host, args.seed_listen_port),
        ("--seed-source", args.seed_source_host, args.seed_source_port),
    ):
        if (host is None) != (port is None):
            raise ValueError(f"{flag}-host and {flag}-port must be provided together")
    if args.weight_cache_seed is not None and args.seed_source_host is not None:
        raise ValueError(
            "--weight-cache-seed conflicts with --seed-source-host/--seed-source-port"
        )
    unix_seed = any(isinstance(address, str) for address in addresses)
    remote_seed = any(not isinstance(address, str) for address in addresses)
    if unix_seed and remote_seed:
        raise ValueError(
            "--weight-cache-seed cannot mix Unix socket paths and "
            "host:base_port addresses"
        )
    if unix_seed and len(addresses) != local_world_size:
        raise ValueError(
            "Unix --weight-cache-seed requires one target socket per local "
            f"GPU; expected {local_world_size}, got {len(addresses)}"
        )
    if remote_seed and len(addresses) != nnodes:
        raise ValueError(
            "Remote --weight-cache-seed requires one host:base_port per source "
            f"node in node_rank order; expected {nnodes}, got {len(addresses)}"
        )
    # A token only protects the TCP planes: the listener and a remote source.
    has_remote = (
        args.seed_listen_host is not None
        or args.seed_source_host is not None
        or remote_seed
    )
    if has_remote != bool(args.seed_token):
        raise ValueError(
            "Remote daemon-to-daemon seeding requires --seed-token (and a "
            "token without a remote endpoint has no effect)"
        )
    for base_port in (
        args.seed_listen_port,
        args.seed_source_port,
        *(address[1] for address in addresses if isinstance(address, tuple)),
    ):
        if base_port is None:
            continue
        max_port = base_port + num_groups * world_size - 1
        if not 1 <= base_port <= 65535 or max_port > 65535:
            raise ValueError(
                f"Daemon-to-daemon port range {base_port}-{max_port} exceeds 65535"
            )