test_quark_maybe_update_config.py 2.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Unit tests for QuarkConfig.maybe_update_config.

Fetches real HF configs (metadata only, no model weights) to verify
that dynamic_mxfp4_quant is only enabled for DeepSeek-V3-family models.

Run: pytest tests/quantization/test_quark_maybe_update_config.py -v
"""

import pytest
from transformers import AutoConfig

from vllm.model_executor.layers.quantization.quark.quark import QuarkConfig


def _make_quark_config() -> QuarkConfig:
    """Create a minimal QuarkConfig for testing."""
    return QuarkConfig(quant_config={}, kv_cache_group=[], pack_method="reorder")


# ---------------------------------------------------------------------------
# Non-deepseek models must not flip dynamic_mxfp4_quant
# ---------------------------------------------------------------------------
@pytest.mark.parametrize(
    "model_name",
    ["amd/MiniMax-M2.1-MXFP4"],
)
def test_non_deepseek_model_stays_false(model_name: str):
    """Non-deepseek_v3 models must not enable dynamic_mxfp4_quant."""
    hf_config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
    qcfg = _make_quark_config()

    qcfg.maybe_update_config(model_name, hf_config=hf_config)

    assert qcfg.dynamic_mxfp4_quant is False


# ---------------------------------------------------------------------------
# DeepSeek-V3 family + fp4 must enable dynamic_mxfp4_quant
# ---------------------------------------------------------------------------
@pytest.mark.parametrize(
    "model_name",
    ["amd/DeepSeek-R1-MXFP4-ASQ"],
)
def test_deepseek_family_fp4_enables_flag(model_name: str):
    hf_config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
    qcfg = _make_quark_config()

    qcfg.maybe_update_config(model_name, hf_config=hf_config)

    assert qcfg.dynamic_mxfp4_quant is True


# ---------------------------------------------------------------------------
# Missing hf_config → warn and stay False
# ---------------------------------------------------------------------------
def test_missing_hf_config_stays_false():
    qcfg = _make_quark_config()

    qcfg.maybe_update_config("some/model")

    assert qcfg.dynamic_mxfp4_quant is False