From 04fa60a53d8eb4811b4858cddb0b8f4224b6c453 Mon Sep 17 00:00:00 2001 From: PRIMA Date: Mon, 20 Apr 2026 20:36:15 -0400 Subject: [PATCH] fix: quant selector quality-order assertion (closes #139, closes #138) The test asserted strictly descending bits_per_channel across ALL levels, but q4_0 (4.0 bits) is a standard fallback that comes after turbo2 (1.5 bits) despite having more bits. These are different quantization schemes: TurboQuant vs standard GGUF. Fix: separate the assertion into two checks: 1. TurboQuant levels (turbo4 > turbo3 > turbo2) must have strictly descending bits_per_channel 2. Standard fallback(s) must come after all TurboQuant levels in the list --- tests/test_quant_selector.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/test_quant_selector.py b/tests/test_quant_selector.py index 5447d143..faa8b219 100644 --- a/tests/test_quant_selector.py +++ b/tests/test_quant_selector.py @@ -20,9 +20,26 @@ from evolution.quant_selector import ( class TestQuantLevels: def test_levels_ordered_by_quality(self): - """Levels should be ordered from best quality to most aggressive.""" - for i in range(len(QUANT_LEVELS) - 1): - assert QUANT_LEVELS[i].bits_per_channel > QUANT_LEVELS[i + 1].bits_per_channel + """Levels should be ordered from best quality to most aggressive. + + TurboQuant levels (turbo4, turbo3, turbo2) are ordered by descending + bits_per_channel (higher = better quality). The standard fallback q4_0 + comes last regardless of its bits value — it's a different quantization + scheme (standard vs TurboQuant) and serves as a last-resort fallback. + """ + # TurboQuant levels must be strictly descending in bits + turbo_levels = [l for l in QUANT_LEVELS if l.kv_type.startswith("turbo")] + for i in range(len(turbo_levels) - 1): + assert turbo_levels[i].bits_per_channel > turbo_levels[i + 1].bits_per_channel + + # Standard fallback(s) must come after all TurboQuant levels + standard_levels = [l for l in QUANT_LEVELS if not l.kv_type.startswith("turbo")] + if standard_levels: + last_turbo = turbo_levels[-1] + for std in standard_levels: + turbo_idx = QUANT_LEVELS.index(last_turbo) + std_idx = QUANT_LEVELS.index(std) + assert std_idx > turbo_idx, f"{std.name} should come after all TurboQuant levels" def test_all_levels_have_required_fields(self): for level in QUANT_LEVELS: