💡 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
feat: promote tqdm to a default library dependency
morgan-coded436662e32b51
diff --git a/setup.py b/setup.pyindex 0298f12a..4a897192 100644--- a/setup.py+++ b/setup.py@@ -20,6 +20,7 @@ default = ["pyyaml>=5.3","safetensors>=0.4.5","torch>=2.4",+ "tqdm>=4.66.3","transformers>=5.9.0",]diff --git a/src/python/txtai/pipeline/train/lemur.py b/src/python/txtai/pipeline/train/lemur.pyindex fb36d34c..3444f05f 100644--- a/src/python/txtai/pipeline/train/lemur.py+++ b/src/python/txtai/pipeline/train/lemur.py@@ -5,18 +5,6 @@ LEMUR trainer moduleimport randomimport sys-# Conditional import. Minimal installs do not include the model stack that-# provides tqdm and only need this module to remain importable.-try:- from tqdm.auto import tqdm-except ImportError:-- def tqdm(values, **_):- """Returns values unchanged when training dependencies are unavailable."""-- return values--from ...models import Lemur, Models, PoolingFactoryfrom ...models.pooling.lemur import LemurModelfrom ...util import Library@@ -25,6 +13,7 @@ from ..base import Pipelinelibrary = Library()torch = library.torch()+tqdm = library.tqdm()class LemurTrainer(Pipeline):@@ -360,7 +349,7 @@ class LemurTrainer(Pipeline):generator.manual_seed(seed)best, state = float("inf"), None- progress = tqdm(range(epochs), desc="LEMUR training", unit="epoch", disable=not sys.stderr.isatty())+ progress = tqdm.tqdm(range(epochs), desc="LEMUR training", unit="epoch", disable=not sys.stderr.isatty())for epoch in progress:lemur.model.train()indices = torch.randperm(len(inputs), generator=generator)diff --git a/src/python/txtai/util/library.py b/src/python/txtai/util/library.pyindex 7b220996..f1c6e46c 100644--- a/src/python/txtai/util/library.py+++ b/src/python/txtai/util/library.py@@ -251,6 +251,31 @@ class Library:return torch+ def tqdm(self):+ """+ Imports tqdm.++ Returns:+ tqdm+ """++ try:+ from tqdm import auto as tqdm++ except ImportError:++ class Tqdm:+ """+ Stub for tqdm+ """++ def __getattr__(self, name):+ raise ImportError("Tqdm is not installed, install tqdm to use this module")++ tqdm = Tqdm()++ return tqdm+def trainer(self):"""Import transformers.Trainerdiff --git a/test/python/testpipeline/testtrain/testtrainer.py b/test/python/testpipeline/testtrain/testtrainer.pyindex dbb31c8a..d4be33da 100644--- a/test/python/testpipeline/testtrain/testtrainer.py+++ b/test/python/testpipeline/testtrain/testtrainer.py@@ -502,7 +502,7 @@ class TestTrainer(unittest.TestCase):documents = [random.normal(size=(5, 6)).astype(np.float32) for _ in range(8)]with (patch("txtai.pipeline.train.lemur.sys.stderr", new=Stream()),- patch("txtai.pipeline.train.lemur.tqdm", side_effect=create),+ patch("txtai.pipeline.train.lemur.tqdm.tqdm", side_effect=create),):lemur = LemurTrainer().fit(documents,