Skip to content

Commit 03f0499

Browse files
authored
cache task cleanup (#680)
1 parent c0667fd commit 03f0499

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pgml-extension/src/bindings/transformers.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ def convert_dtype(kwargs):
6767
def convert_eos_token(tokenizer, args):
6868
if "eos_token" in args:
6969
args["eos_token_id"] = tokenizer.convert_tokens_to_ids(args.pop("eos_token"))
70-
else:
71-
args["eos_token_id"] = tokenizer.eos_token_id
7270

7371

7472
def ensure_device(kwargs):
@@ -94,15 +92,14 @@ def transform(task, args, inputs):
9492
inputs = json.loads(inputs)
9593

9694
key = ",".join([f"{key}:{val}" for (key, val) in sorted(task.items())])
97-
ensure_device(task)
98-
convert_dtype(task)
99-
100-
model = task.get("model", None)
101-
if model and "tokenizer" not in task:
102-
task["tokenizer"] = AutoTokenizer.from_pretrained(model)
103-
10495
if key not in __cache_transform_pipeline_by_task:
105-
__cache_transform_pipeline_by_task[key] = transformers.pipeline(**task)
96+
ensure_device(task)
97+
convert_dtype(task)
98+
pipe = transformers.pipeline(**task)
99+
if pipe.tokenizer is None:
100+
pipe.tokenizer = AutoTokenizer.from_pretrained(pipe.model.name_or_path)
101+
__cache_transform_pipeline_by_task[key] = pipe
102+
106103
pipe = __cache_transform_pipeline_by_task[key]
107104

108105
if pipe.task == "question-answering":

0 commit comments

Comments
 (0)
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