Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Code cleanup

davidmezzetti40c92c15d6b4
diff --git a/src/python/txtai/models/models.py b/src/python/txtai/models/models.py
index 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.py
index 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 model
model = Models.load(model, task=task, modelargs=kwargs).to(self.device)
+ # Apply model initialization routines
+ model = self.prepare(model)
+
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(tokenizer) if isinstance(tokenizer, str) else tokenizer
diff --git a/src/python/txtai/pipeline/llm/huggingface.py b/src/python/txtai/pipeline/llm/huggingface.py
index 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 module
from threading import Thread
from transformers import AutoModelForImageTextToText, TextIteratorStreamer
-from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from ...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 task
self.task = "text2text-generation"
diff --git a/src/python/txtai/pipeline/text/translation.py b/src/python/txtai/pipeline/text/translation.py
index 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 = False
from huggingface_hub.hf_api import HfApi
-from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from ...models import Models
from ..hfmodel import HFModel
@@ -231,7 +230,7 @@ class Translation(HFModel):
# Determine best translation model to use, load if necessary and return
path = 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 found
return 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.