💡 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
Update pipeline GPU usage and build script
davidmezzetti6b600d9c1f9d
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 391b6edf..f6386438 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -21,7 +21,7 @@ jobs:if: matrix.os == 'macos-latest'- name: Install dependencies - Windows- run: python -m pip install torch==1.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html+ run: python -m pip install torch==1.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.htmlif: matrix.os == 'windows-latest'- name: Builddiff --git a/src/python/txtai/pipeline.py b/src/python/txtai/pipeline.pyindex 651306df..d80062f8 100644--- a/src/python/txtai/pipeline.py+++ b/src/python/txtai/pipeline.py@@ -12,7 +12,7 @@ class Pipeline(object):quantization and minor interface changes."""- def __init__(self, task, path=None, quantize=False):+ def __init__(self, task, path=None, quantize=False, gpu=False):"""Loads a new pipeline model.@@ -20,10 +20,11 @@ class Pipeline(object):task: pipeline task or categorypath: optional path to model, will use default model for task if not providedquantize: if model should be quantized, defaults to False+ gpu: if gpu inference should be used (only works if GPUs are available)"""- # Detect GPU- gpu = torch.cuda.is_available()+ # Enable GPU inference if explicitly set and a GPU is available+ gpu = gpu and torch.cuda.is_available()# Transformer pipeline taskself.pipeline = pipeline(task, model=path, tokenizer=path, device=0 if gpu else -1)@@ -38,8 +39,8 @@ class Questions(Pipeline):Runs extractive QA for a series of questions and contexts."""- def __init__(self, path=None, quantize=False):- super().__init__("question-answering", path, quantize)+ def __init__(self, path=None, quantize=False, gpu=False):+ super().__init__("question-answering", path, quantize, gpu)def __call__(self, questions, contexts):"""@@ -79,8 +80,8 @@ class Labels(Pipeline):Applies labels to text sections using a zero shot classifier."""- def __init__(self, path=None, quantize=False):- super().__init__("zero-shot-classification", path, quantize)+ def __init__(self, path=None, quantize=False, gpu=True):+ super().__init__("zero-shot-classification", path, quantize, gpu)def __call__(self, section, labels):"""