fix: quant selector quality-order assertion (closes #139, closes #138)
All checks were successful
Smoke Test / smoke (pull_request) Successful in 20s

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
This commit is contained in:
2026-04-20 20:36:15 -04:00
parent 492c1cdcfd
commit 04fa60a53d

View File

@@ -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: