| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """ROCm guards for shared Inkling model-definition contracts.""" |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import torch |
| 8 | |
| 9 | import vllm.models.inkling as inkling |
| 10 | from vllm.lora.utils import get_supported_lora_modules |
| 11 | from vllm.model_executor.models.interfaces import supports_lora |
| 12 | from vllm.models.inkling.amd import model as amd_model |
| 13 | from vllm.models.inkling.amd.mtp import InklingMTP |
| 14 | |
| 15 | |
| 16 | def test_backend_neutral_definitions_match_nvidia_reference() -> None: |
| 17 | inkling_dir = Path(amd_model.__file__).parents[1] |
| 18 | for filename in ("logits_processor.py", "mtp.py"): |
| 19 | assert (inkling_dir / "amd" / filename).read_bytes() == ( |
| 20 | inkling_dir / "nvidia" / filename |
| 21 | ).read_bytes() |
| 22 | |
| 23 | |
| 24 | def test_rocm_exports_its_aligned_mtp_implementation() -> None: |
| 25 | assert inkling.InklingMTP is InklingMTP |
| 26 | |
| 27 | |
| 28 | def test_rocm_model_exposes_the_upstream_lora_contract() -> None: |
| 29 | model_cls = amd_model._TmlForCausalLMBase |
| 30 | |
| 31 | assert supports_lora(model_cls) |
| 32 | assert model_cls.packed_modules_mapping == { |
| 33 | "qkvr": ["wq_du", "wk_dv", "wv_dv", "wr_du"], |
| 34 | "w13": ["w1", "w3"], |
| 35 | } |
| 36 | assert model_cls.embedding_modules == {"lm_head": "output_embeddings"} |
| 37 | |
| 38 | model = torch.nn.Module() |
| 39 | model.embedding_modules = model_cls.embedding_modules |
| 40 | supported = get_supported_lora_modules(model) |
| 41 | assert "embed_tokens" not in supported |
| 42 | assert "lm_head" in supported |
| 43 | |
| 44 | |
| 45 | def test_lightseek_bundled_adapter_weights_remain_opt_in() -> None: |
| 46 | mapper = amd_model._TmlForCausalLMBase.hf_to_vllm_mapper |
| 47 | weight = torch.empty(1) |
| 48 | name, mapped_weight = next( |
| 49 | iter( |
| 50 | mapper.apply([("language_model.layers.3.attn.wq_du.lora_A.weight", weight)]) |
| 51 | ) |
| 52 | ) |
| 53 | |
| 54 | assert name == "model.layers.3.attn.qkvr.lora_A.weight" |
| 55 | assert mapped_weight.shard_id == 0 |
| 56 | assert amd_model._is_peft_adapter_weight(name) |
| 57 | |
| 58 | lm_head_name = mapper.apply_list(["language_model.lm_head.lora_B.weight"]) |
| 59 | assert lm_head_name == ["lm_head.lora_B.weight"] |