💡 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
Code cleanup
davidmezzetti40c92c15d6b4
diff --git a/src/python/txtai/models/models.py b/src/python/txtai/models/models.pyindex beef9aa1..e05d7efa 100644--- a/src/python/txtai/models/models.py+++ b/src/python/txtai/models/models.py@@ -206,6 +206,7 @@ class Models:"default": AutoModel.from_pretrained,"question-answering": AutoModelForQuestionAnswering.from_pretrained,"summarization": AutoModelForSeq2SeqLM.from_pretrained,+ "text2text-generation": AutoModelForSeq2SeqLM.from_pretrained,"text-classification": AutoModelForSequenceClassification.from_pretrained,"zero-shot-classification": AutoModelForSequenceClassification.from_pretrained,}diff --git a/src/python/txtai/pipeline/hfmodel.py b/src/python/txtai/pipeline/hfmodel.pyindex 71f8b7dd..a7aafc48 100644--- a/src/python/txtai/pipeline/hfmodel.py+++ b/src/python/txtai/pipeline/hfmodel.py@@ -57,6 +57,9 @@ class HFModel(Tensors):# Load modelmodel = Models.load(model, task=task, modelargs=kwargs).to(self.device)+ # Apply model initialization routines+ model = self.prepare(model)+# Load tokenizertokenizer = AutoTokenizer.from_pretrained(tokenizer) if isinstance(tokenizer, str) else tokenizerdiff --git a/src/python/txtai/pipeline/llm/huggingface.py b/src/python/txtai/pipeline/llm/huggingface.pyindex 48588c73..dad5a21c 100644--- a/src/python/txtai/pipeline/llm/huggingface.py+++ b/src/python/txtai/pipeline/llm/huggingface.py@@ -5,7 +5,6 @@ Hugging Face modulefrom threading import Threadfrom transformers import AutoModelForImageTextToText, TextIteratorStreamer-from transformers import AutoModelForSeq2SeqLM, AutoTokenizerfrom ...models import Models@@ -263,14 +262,7 @@ class SequencesPipeline(HFModel):super().__init__(path, quantize, gpu, batch)# Text2Text Generation model- if isinstance(path, tuple):- self.model, self.tokenizer = path- else:- self.model = AutoModelForSeq2SeqLM.from_pretrained(path, **kwargs)- self.tokenizer = AutoTokenizer.from_pretrained(path)-- # Move model to device- self.model = self.model.to(self.device)+ self.model, self.tokenizer = self.load(path, "text2text-generation", **kwargs)# Set pipeline taskself.task = "text2text-generation"diff --git a/src/python/txtai/pipeline/text/translation.py b/src/python/txtai/pipeline/text/translation.pyindex cf00d7f3..6b1a7c10 100644--- a/src/python/txtai/pipeline/text/translation.py+++ b/src/python/txtai/pipeline/text/translation.py@@ -11,7 +11,6 @@ except ImportError:STATICVECTORS = Falsefrom huggingface_hub.hf_api import HfApi-from transformers import AutoModelForSeq2SeqLM, AutoTokenizerfrom ...models import Modelsfrom ..hfmodel import HFModel@@ -231,7 +230,7 @@ class Translation(HFModel):# Determine best translation model to use, load if necessary and returnpath = self.modelpath(source, target)if path not in self.models:- self.models[path] = self.load(path)+ self.models[path] = self.load(path, "text2text-generation")return (path,) + self.models[path]@@ -264,25 +263,6 @@ class Translation(HFModel):# Default model if no suitable model foundreturn self.path- def load(self, path):- """- Loads a model specified by path.-- Args:- path: model path-- Returns:- (model, tokenizer)- """-- model = AutoModelForSeq2SeqLM.from_pretrained(path)- tokenizer = AutoTokenizer.from_pretrained(path)-- # Apply model initialization routines- model = self.prepare(model)-- return (model, tokenizer)-def langid(self, languages, target):"""Searches a list of languages for a prefix match on target.