run_batch.py 2.17 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
from __future__ import annotations

6
7
import argparse
import asyncio
8
9
import importlib.metadata
import typing
10
11

from vllm.entrypoints.cli.types import CLISubcommand
12
from vllm.entrypoints.utils import VLLM_SUBCMD_PARSER_EPILOG
13
14
15
16
17
18
from vllm.logger import init_logger

if typing.TYPE_CHECKING:
    from vllm.utils import FlexibleArgumentParser

logger = init_logger(__name__)
19
20
21
22


class RunBatchSubcommand(CLISubcommand):
    """The `run-batch` subcommand for vLLM CLI."""
23
    name = "run-batch"
24
25
26

    @staticmethod
    def cmd(args: argparse.Namespace) -> None:
27
28
29
30
        from vllm.entrypoints.openai.run_batch import main as run_batch_main

        logger.info("vLLM batch processing API version %s",
                    importlib.metadata.version("vllm"))
31
32
33
34
35
36
        logger.info("args: %s", args)

        # Start the Prometheus metrics server.
        # LLMEngine uses the Prometheus client
        # to publish metrics at the /metrics endpoint.
        if args.enable_metrics:
37
38
            from prometheus_client import start_http_server

39
40
41
42
43
44
45
46
47
48
            logger.info("Prometheus metrics enabled")
            start_http_server(port=args.port, addr=args.url)
        else:
            logger.info("Prometheus metrics disabled")

        asyncio.run(run_batch_main(args))

    def subparser_init(
            self,
            subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser:
49
50
        from vllm.entrypoints.openai.run_batch import make_arg_parser

51
        run_batch_parser = subparsers.add_parser(
52
            self.name,
53
54
55
56
57
58
59
            help="Run batch prompts and write results to file.",
            description=(
                "Run batch prompts using vLLM's OpenAI-compatible API.\n"
                "Supports local or HTTP input/output files."),
            usage=
            "vllm run-batch -i INPUT.jsonl -o OUTPUT.jsonl --model <model>",
        )
60
        run_batch_parser = make_arg_parser(run_batch_parser)
61
62
        run_batch_parser.epilog = VLLM_SUBCMD_PARSER_EPILOG.format(
            subcmd=self.name)
63
        return run_batch_parser
64
65
66
67


def cmd_init() -> list[CLISubcommand]:
    return [RunBatchSubcommand()]