| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Tests for the MoEKernelOracle ABC introduced in PR series for #37753. |
| 4 | |
| 5 | This file contains a single canonical demonstration that |
| 6 | `UnquantizedMoEKernelOracle` methods delegate one-to-one to the |
| 7 | existing module-level functions in `oracle/unquantized.py`. Each method |
| 8 | on `UnquantizedMoEKernelOracle` follows the same `return module_fn(args)` |
| 9 | pattern, so verifying delegation for one method (`make_kernel`) gives |
| 10 | high confidence in the rest. |
| 11 | """ |
| 12 | |
| 13 | from unittest.mock import patch |
| 14 | |
| 15 | from vllm.model_executor.layers.fused_moe.experts.triton_moe import TritonExperts |
| 16 | from vllm.model_executor.layers.fused_moe.oracle import UnquantizedMoEKernelOracle |
| 17 | from vllm.model_executor.layers.fused_moe.oracle.unquantized import ( |
| 18 | UnquantizedMoeBackend, |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | class TestUnquantizedDelegation: |
| 23 | """UnquantizedMoEKernelOracle methods must delegate to the existing |
| 24 | module-level functions; behaviour is bit-identical.""" |
| 25 | |
| 26 | def test_make_kernel_delegates(self) -> None: |
| 27 | quant_config = object() |
| 28 | moe_config = object() |
| 29 | experts_cls = TritonExperts |
| 30 | sentinel_kernel = object() |
| 31 | |
| 32 | with patch( |
| 33 | "vllm.model_executor.layers.fused_moe.oracle.unquantized." |
| 34 | "make_unquantized_moe_kernel", |
| 35 | return_value=sentinel_kernel, |
| 36 | ) as mocked: |
| 37 | out = UnquantizedMoEKernelOracle().make_kernel( |
| 38 | quant_config, |
| 39 | moe_config, |
| 40 | UnquantizedMoeBackend.TRITON, |
| 41 | experts_cls, |
| 42 | ) |
| 43 | |
| 44 | mocked.assert_called_once_with( |
| 45 | quant_config, |
| 46 | moe_config, |
| 47 | UnquantizedMoeBackend.TRITON, |
| 48 | experts_cls, |
| 49 | None, # routing_tables default |
| 50 | ) |
| 51 | assert out is sentinel_kernel |