💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Fix quantize: false silently enabling Q8_0 quantization in the GGML backend (#1236)
Amir Fathiebe13ae304bd
diff --git a/src/python/txtai/ann/dense/ggml.py b/src/python/txtai/ann/dense/ggml.pyindex 9e34e74b..8d4c71df 100644--- a/src/python/txtai/ann/dense/ggml.py+++ b/src/python/txtai/ann/dense/ggml.py@@ -519,7 +519,11 @@ class GGMLTensors:# Read tensor typetensortype = self.quantize- tensortype = "Q8_0" if isinstance(tensortype, bool) else f"Q{int(tensortype)}_0" if isinstance(tensortype, int) else tensortype+ tensortype = (+ "Q8_0"+ if isinstance(tensortype, bool) and tensortype+ else f"Q{int(tensortype)}_0" if isinstance(tensortype, int) and not isinstance(tensortype, bool) else tensortype+ )tensortype = tensortype.upper() if tensortype else "F32"# Validate tensor typediff --git a/test/python/testann/testdense.py b/test/python/testann/testdense.pyindex 5561af43..2185856d 100644--- a/test/python/testann/testdense.py+++ b/test/python/testann/testdense.py@@ -10,12 +10,14 @@ import unittestfrom unittest.mock import patch+import ggmlimport numpy as npfrom sqlalchemy.dialects.postgresql import BITfrom sqlalchemy.ext.compiler import compilesfrom txtai.ann import ANNFactory, ANN+from txtai.ann.dense.ggml import GGMLTensorsfrom txtai.serialize import SerializeFactory@@ -223,6 +225,17 @@ class TestDense(unittest.TestCase):ann.load(index)self.assertEqual(ann.count(), 99)+ def testGGMLQuantizeDisabled(self):+ """+ Test that quantize: false disables GGML tensor quantization+ """++ data = np.random.rand(4, 256).astype(np.float32)+ for quantize, expected in [(False, ggml.GGML_TYPE_F32), (True, ggml.GGML_TYPE_Q8_0), (4, ggml.GGML_TYPE_Q4_0)]:+ with self.subTest(quantize=quantize):+ tensors = GGMLTensors(False, 64, quantize)+ self.assertEqual(tensors.tensortype(data), expected)+def testGGMLEmpty(self):"""Test GGML backend with an empty index