|
| 1 | +"""Unit tests for ``Runner.check()`` parameter validation. |
| 2 | +
|
| 3 | +These tests exercise only the configuration validation path |
| 4 | +(``Runner.check()``) and therefore do not require a GPU or model |
| 5 | +loading. |
| 6 | +
|
| 7 | +Copyright 2025-2026 Fujitsu Ltd. |
| 8 | +""" |
| 9 | + |
| 10 | +import pytest |
| 11 | + |
| 12 | +from onecomp import CalibrationConfig, ModelConfig, Runner |
| 13 | +from onecomp.quantizer.autobit import AutoBitQuantizer |
| 14 | +from onecomp.quantizer.gptq import GPTQ |
| 15 | +from onecomp.quantizer.jointq import JointQ |
| 16 | + |
| 17 | + |
| 18 | +def _model_config() -> ModelConfig: |
| 19 | + return ModelConfig( |
| 20 | + model_id="TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T", |
| 21 | + device="cuda:0", |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +class TestRunnerCheckQEPSupport: |
| 26 | + """``qep=True`` must raise a clear error when the quantizer does |
| 27 | + not support the generic QEP pipeline. |
| 28 | + """ |
| 29 | + |
| 30 | + def test_jointq_with_qep_true_raises_clear_error(self): |
| 31 | + """JointQ + qep=True should raise a clear ValueError, not an |
| 32 | + obscure error from deep inside the QEP runtime. |
| 33 | + """ |
| 34 | + runner = Runner( |
| 35 | + model_config=_model_config(), |
| 36 | + quantizer=JointQ(bits=4, group_size=128), |
| 37 | + calibration_config=CalibrationConfig(max_length=128, num_calibration_samples=8), |
| 38 | + qep=True, |
| 39 | + ) |
| 40 | + |
| 41 | + with pytest.raises(ValueError, match=r"JointQ.*does not support QEP"): |
| 42 | + runner.check() |
| 43 | + |
| 44 | + def test_jointq_with_qep_false_passes_check(self): |
| 45 | + """JointQ + qep=False is the supported configuration.""" |
| 46 | + runner = Runner( |
| 47 | + model_config=_model_config(), |
| 48 | + quantizer=JointQ(bits=4, group_size=128), |
| 49 | + calibration_config=CalibrationConfig(max_length=128, num_calibration_samples=8), |
| 50 | + qep=False, |
| 51 | + ) |
| 52 | + runner.check() |
| 53 | + |
| 54 | + def test_gptq_with_qep_true_passes_check(self): |
| 55 | + """GPTQ supports QEP, so check() must pass.""" |
| 56 | + runner = Runner( |
| 57 | + model_config=_model_config(), |
| 58 | + quantizer=GPTQ(wbits=4, groupsize=128), |
| 59 | + calibration_config=CalibrationConfig(max_length=128, num_calibration_samples=8), |
| 60 | + qep=True, |
| 61 | + ) |
| 62 | + runner.check() |
| 63 | + |
| 64 | + def test_autobit_with_jointq_candidate_and_qep_true_raises(self): |
| 65 | + """AutoBit with a JointQ candidate must also raise on qep=True. |
| 66 | +
|
| 67 | + ``AutoBitQuantizer.flag_qep_supported`` is True only when *all* |
| 68 | + candidate quantizers support QEP, so a JointQ candidate must |
| 69 | + propagate the unsupported state. |
| 70 | + """ |
| 71 | + autobit = AutoBitQuantizer( |
| 72 | + quantizers=[GPTQ(wbits=4), JointQ(bits=2)], |
| 73 | + target_bit=3.0, |
| 74 | + ) |
| 75 | + runner = Runner( |
| 76 | + model_config=_model_config(), |
| 77 | + quantizer=autobit, |
| 78 | + calibration_config=CalibrationConfig(max_length=128, num_calibration_samples=8), |
| 79 | + qep=True, |
| 80 | + ) |
| 81 | + |
| 82 | + with pytest.raises( |
| 83 | + ValueError, |
| 84 | + match=r"AutoBitQuantizer.*does not support QEP", |
| 85 | + ): |
| 86 | + runner.check() |
| 87 | + |
| 88 | + def test_autobit_with_only_gptq_candidates_and_qep_true_passes(self): |
| 89 | + """AutoBit with only QEP-compatible candidates must pass.""" |
| 90 | + autobit = AutoBitQuantizer( |
| 91 | + quantizers=[GPTQ(wbits=4), GPTQ(wbits=2)], |
| 92 | + target_bit=3.0, |
| 93 | + ) |
| 94 | + runner = Runner( |
| 95 | + model_config=_model_config(), |
| 96 | + quantizer=autobit, |
| 97 | + calibration_config=CalibrationConfig(max_length=128, num_calibration_samples=8), |
| 98 | + qep=True, |
| 99 | + ) |
| 100 | + runner.check() |
0 commit comments