🌐 AI搜索 & 代理 主页
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pgml-extension/src/bindings/transformers/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
PegasusTokenizer,
TrainingArguments,
Trainer,
GPTQConfig
)
import threading

Expand Down Expand Up @@ -279,7 +280,13 @@ def __init__(self, model_name, **kwargs):
elif self.task == "summarization" or self.task == "translation":
self.model = AutoModelForSeq2SeqLM.from_pretrained(model_name, **kwargs)
elif self.task == "text-generation" or self.task == "conversational":
self.model = AutoModelForCausalLM.from_pretrained(model_name, **kwargs)
# See: https://huggingface.co/docs/transformers/main/quantization
if "quantization_config" in kwargs:
quantization_config = kwargs.pop("quantization_config")
quantization_config = GPTQConfig(**quantization_config)
self.model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=quantization_config, **kwargs)
else:
self.model = AutoModelForCausalLM.from_pretrained(model_name, **kwargs)
else:
raise PgMLException(f"Unhandled task: {self.task}")

Expand Down Expand Up @@ -409,10 +416,13 @@ def create_pipeline(task):
else:
try:
pipe = StandardPipeline(model_name, **task)
except TypeError:
# some models fail when given "device" kwargs, remove and try again
task.pop("device")
pipe = StandardPipeline(model_name, **task)
except TypeError as error:
if "device" in task:
# some models fail when given "device" kwargs, remove and try again
task.pop("device")
pipe = StandardPipeline(model_name, **task)
else:
raise error
return pipe


Expand Down