| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from pathlib import Path |
| 5 | |
| 6 | import pytest |
| 7 | from transformers import PreTrainedConfig |
| 8 | |
| 9 | from vllm.transformers_utils.config import get_config_parser, register_config_parser |
| 10 | from vllm.transformers_utils.config_parser_base import ConfigParserBase |
| 11 | |
| 12 | |
| 13 | @register_config_parser("custom_config_parser") |
| 14 | class CustomConfigParser(ConfigParserBase): |
| 15 | def parse( |
| 16 | self, |
| 17 | model: str | Path, |
| 18 | trust_remote_code: bool, |
| 19 | revision: str | None = None, |
| 20 | code_revision: str | None = None, |
| 21 | **kwargs, |
| 22 | ) -> tuple[dict, PreTrainedConfig]: |
| 23 | raise NotImplementedError |
| 24 | |
| 25 | |
| 26 | def test_register_config_parser(): |
| 27 | assert isinstance(get_config_parser("custom_config_parser"), CustomConfigParser) |
| 28 | |
| 29 | |
| 30 | def test_invalid_config_parser(): |
| 31 | with pytest.raises(ValueError): |
| 32 | |
| 33 | @register_config_parser("invalid_config_parser") |
| 34 | class InvalidConfigParser: |
| 35 | pass |