| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import numpy as np |
| 5 | import pytest |
| 6 | |
| 7 | from vllm.config.compilation import CompilationConfig, CUDAGraphMode |
| 8 | from vllm.models.inkling.common.mm_preprocess import InklingMultiModalDataParser |
| 9 | from vllm.models.inkling.common.towers import plan_out_scales |
| 10 | from vllm.models.inkling.configs import ( |
| 11 | InklingAudioConfig, |
| 12 | InklingModelConfig, |
| 13 | InklingVisionConfig, |
| 14 | ) |
| 15 | from vllm.models.inkling.nvidia.sconv_swa_attn import ( |
| 16 | InklingSconvMetadataBuilder, |
| 17 | ) |
| 18 | from vllm.v1.attention.backend import AttentionCGSupport |
| 19 | |
| 20 | |
| 21 | def test_vision_scale_plan_matches_released_config(): |
| 22 | assert plan_out_scales(2, 40, 4) == [ |
| 23 | (1, 1, 1, 3), |
| 24 | (1, 5, 5, 128), |
| 25 | (1, 10, 10, 320), |
| 26 | (1, 40, 40, 4800), |
| 27 | (2, 40, 40, 9600), |
| 28 | ] |
| 29 | |
| 30 | |
| 31 | def test_vision_scale_plan_breaks_assignment_ties_in_order(): |
| 32 | reductions = [np.prod(scale[:-1]) for scale in plan_out_scales(2, 52, 4)] |
| 33 | |
| 34 | assert reductions == sorted(set(reductions)) |
| 35 | |
| 36 | |
| 37 | @pytest.mark.parametrize( |
| 38 | ("config_cls", "kwargs", "missing"), |
| 39 | [ |
| 40 | (InklingAudioConfig, {"decoder_dmodel": 16}, "n_mel_bins"), |
| 41 | (InklingVisionConfig, {"decoder_dmodel": 16}, "vision_encoder_type"), |
| 42 | ], |
| 43 | ) |
| 44 | def test_enabled_tower_requires_architecture_fields(config_cls, kwargs, missing): |
| 45 | with pytest.raises(ValueError, match=missing): |
| 46 | config_cls(**kwargs) |
| 47 | |
| 48 | |
| 49 | def test_inkling_raw_2d_audio_is_rejected_as_ambiguous(): |
| 50 | parser = InklingMultiModalDataParser(target_sr=16_000, target_channels=1) |
| 51 | with pytest.raises(ValueError, match="ambiguous channel layout"): |
| 52 | parser._parse_audio_data(np.zeros((2, 100), dtype=np.float32)) |
| 53 | |
| 54 | |
| 55 | def test_inkling_mtp_chain_norm_is_disabled_by_default(): |
| 56 | assert InklingModelConfig().chain_hidden_post_norm is False |
| 57 | |
| 58 | |
| 59 | def test_inkling_supports_piecewise_cudagraphs(): |
| 60 | support = InklingSconvMetadataBuilder.get_cudagraph_support |
| 61 | assert support(None, None) == AttentionCGSupport.UNIFORM_BATCH |
| 62 | |
| 63 | compilation_config = CompilationConfig( |
| 64 | cudagraph_mode=CUDAGraphMode.PIECEWISE, |
| 65 | splitting_ops=[], |
| 66 | ) |
| 67 | resolved_mode = compilation_config.resolve_cudagraph_mode_and_sizes( |
| 68 | AttentionCGSupport.UNIFORM_BATCH, |
| 69 | "InklingSconvBackend", |
| 70 | ) |
| 71 | |
| 72 | assert resolved_mode == CUDAGraphMode.PIECEWISE |