|
| 1 | +""" |
| 2 | +# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License" |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +# This file is modified from https://github.com/vllm-project/vllm/blob/main/vllm/entrypoints/cli/run_batch.py |
| 18 | + |
| 19 | +from __future__ import annotations |
| 20 | + |
| 21 | +import argparse |
| 22 | +import asyncio |
| 23 | +import importlib.metadata |
| 24 | + |
| 25 | +from fastdeploy.entrypoints.cli.types import CLISubcommand |
| 26 | +from fastdeploy.utils import ( |
| 27 | + FASTDEPLOY_SUBCMD_PARSER_EPILOG, |
| 28 | + FlexibleArgumentParser, |
| 29 | + show_filtered_argument_or_group_from_help, |
| 30 | +) |
| 31 | + |
| 32 | + |
| 33 | +class RunBatchSubcommand(CLISubcommand): |
| 34 | + """The `run-batch` subcommand for FastDeploy CLI.""" |
| 35 | + |
| 36 | + name = "run-batch" |
| 37 | + |
| 38 | + @staticmethod |
| 39 | + def cmd(args: argparse.Namespace) -> None: |
| 40 | + from fastdeploy.entrypoints.openai.run_batch import main as run_batch_main |
| 41 | + |
| 42 | + print("FastDeploy batch processing API version", importlib.metadata.version("fastdeploy-gpu")) |
| 43 | + print(args) |
| 44 | + asyncio.run(run_batch_main(args)) |
| 45 | + |
| 46 | + def subparser_init(self, subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser: |
| 47 | + from fastdeploy.entrypoints.openai.run_batch import make_arg_parser |
| 48 | + |
| 49 | + run_batch_parser = subparsers.add_parser( |
| 50 | + "run-batch", |
| 51 | + help="Run batch prompts and write results to file.", |
| 52 | + description=( |
| 53 | + "Run batch prompts using FastDeploy's OpenAI-compatible API.\n" |
| 54 | + "Supports local or HTTP input/output files." |
| 55 | + ), |
| 56 | + usage="FastDeploy run-batch -i INPUT.jsonl -o OUTPUT.jsonl --model <model>", |
| 57 | + ) |
| 58 | + run_batch_parser = make_arg_parser(run_batch_parser) |
| 59 | + show_filtered_argument_or_group_from_help(run_batch_parser, ["run-batch"]) |
| 60 | + run_batch_parser.epilog = FASTDEPLOY_SUBCMD_PARSER_EPILOG |
| 61 | + return run_batch_parser |
| 62 | + |
| 63 | + |
| 64 | +def cmd_init() -> list[CLISubcommand]: |
| 65 | + return [RunBatchSubcommand()] |
0 commit comments