test_lora_utils.py 1.24 KB
Newer Older
1
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
3
# SPDX-License-Identifier: Apache-2.0

4
5
import pytest

6
7
from dynamo.llm import lora_name_to_id

8
9
10
11
12
13
14
pytestmark = [
    pytest.mark.gpu_0,
    pytest.mark.parallel,
    pytest.mark.pre_merge,
    pytest.mark.unit,
]

15
16
17
18
max_int32 = 0x7FFFFFFF


class TestLoraNameToId:
19
    @pytest.mark.timeout(5)
20
21
22
    def test_import_function(self):
        assert callable(lora_name_to_id)

23
    @pytest.mark.timeout(5)
24
25
26
27
28
29
    def test_returns_positive_integer_for_different_names(self):
        for i in range(100):
            result = lora_name_to_id(f"test_lora_{i}")
            assert isinstance(result, int)
            assert 1 <= result <= max_int32

30
    @pytest.mark.timeout(5)
31
32
33
34
35
    def test_different_names_produce_different_ids(self):
        id1 = lora_name_to_id("lora_adapter_1")
        id2 = lora_name_to_id("lora_adapter_2")
        assert id1 != id2

36
    @pytest.mark.timeout(5)
37
38
39
40
41
    def test_consistency_across_multiple_calls(self):
        test_names = [f"lora_{i}" for i in range(100)]
        results_first = [lora_name_to_id(name) for name in test_names]
        results_second = [lora_name_to_id(name) for name in test_names]
        assert results_first == results_second