Skip to content

Allow for users to pass in a quantization config #1269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2024
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy