| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Unit tests for ``system_fingerprint`` construction.""" |
| 4 | |
| 5 | from types import SimpleNamespace |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from vllm.entrypoints.serve.utils import fingerprint as fp |
| 10 | |
| 11 | |
| 12 | def _cfg(tp=1, pp=1, dp=1, ep=False, digest="a3b21f94deadbeef"): |
| 13 | c = SimpleNamespace( |
| 14 | parallel_config=SimpleNamespace( |
| 15 | tensor_parallel_size=tp, |
| 16 | pipeline_parallel_size=pp, |
| 17 | data_parallel_size=dp, |
| 18 | enable_expert_parallel=ep, |
| 19 | ) |
| 20 | ) |
| 21 | c.compute_hash = lambda: digest |
| 22 | return c |
| 23 | |
| 24 | |
| 25 | @pytest.fixture(autouse=True) |
| 26 | def _reset(): |
| 27 | fp.set_default_fingerprint_mode("full") |
| 28 | yield |
| 29 | fp.set_default_fingerprint_mode("full") |
| 30 | |
| 31 | |
| 32 | def test_four_modes_produce_expected_shapes(): |
| 33 | from vllm import __version__ as v |
| 34 | |
| 35 | cfg = _cfg(tp=8, ep=True) |
| 36 | |
| 37 | assert fp.build_system_fingerprint(cfg, "full") == (f"vllm-{v}-tp8-ep-a3b21f94") |
| 38 | assert fp.build_system_fingerprint(cfg, "hash") == f"vllm-{v}-a3b21f94" |
| 39 | assert fp.build_system_fingerprint(cfg, "custom", "my-fp") == "my-fp" |
| 40 | assert fp.build_system_fingerprint(cfg, "none") is None |
| 41 | |
| 42 | |
| 43 | def test_full_mode_emits_only_non_trivial_parallelism(): |
| 44 | from vllm import __version__ as v |
| 45 | |
| 46 | # Single-GPU: nothing between version and hash. |
| 47 | assert fp.build_system_fingerprint(_cfg(), "full") == f"vllm-{v}-a3b21f94" |
| 48 | # All parallelism axes. |
| 49 | assert ( |
| 50 | fp.build_system_fingerprint(_cfg(tp=8, pp=2, dp=4, ep=True), "full") |
| 51 | == f"vllm-{v}-tp8-pp2-dp4-ep-a3b21f94" |
| 52 | ) |
| 53 | |
| 54 | |
| 55 | def test_get_respects_set_default(): |
| 56 | cfg = _cfg(tp=8) |
| 57 | full = fp.get_system_fingerprint(cfg) |
| 58 | assert full == fp.get_system_fingerprint(cfg) |
| 59 | |
| 60 | fp.set_default_fingerprint_mode("hash") |
| 61 | hashed = fp.get_system_fingerprint(cfg) |
| 62 | assert hashed is not None |
| 63 | assert hashed != full |
| 64 | assert "tp8" not in hashed |
| 65 | |
| 66 | fp.set_default_fingerprint_mode("custom", "deploy-42") |
| 67 | assert fp.get_system_fingerprint(cfg) == "deploy-42" |
| 68 | |
| 69 | fp.set_default_fingerprint_mode("none") |
| 70 | assert fp.get_system_fingerprint(cfg) is None |
| 71 | |
| 72 | |
| 73 | def test_compute_hash_failure_does_not_raise(): |
| 74 | cfg = _cfg() |
| 75 | cfg.compute_hash = lambda: (_ for _ in ()).throw(RuntimeError("boom")) |
| 76 | full_fp = fp.build_system_fingerprint(cfg, "full") |
| 77 | assert full_fp is not None and full_fp.endswith("-nohash") |
| 78 | hash_fp = fp.build_system_fingerprint(cfg, "hash") |
| 79 | assert hash_fp is not None and hash_fp.endswith("-nohash") |