16
16
Base Pipeline class for transformers inference pipeline
17
17
"""
18
18
19
- import logging
19
+
20
20
import warnings
21
21
from pathlib import Path
22
22
from typing import Any , Dict , List , Mapping , Optional , Union
23
23
24
24
import numpy
25
25
import transformers
26
- from transformers .models .auto import AutoTokenizer
27
26
28
27
from deepsparse import Bucketable , Pipeline
28
+ from deepsparse .transformers .helpers import overwrite_transformer_onnx_model_inputs
29
29
from deepsparse .transformers .helpers import (
30
- get_deployment_path ,
31
- overwrite_transformer_onnx_model_inputs ,
30
+ setup_onnx_file_path as setup_onnx_file_path_v2 ,
32
31
)
33
32
34
33
@@ -124,24 +123,15 @@ def setup_onnx_file_path(self) -> str:
124
123
125
124
:return: file path to the processed ONNX file for the engine to compile
126
125
"""
127
- deployment_path , onnx_path = get_deployment_path (self .model_path )
128
-
129
- # temporarily set transformers logger to ERROR to avoid
130
- # printing misleading warnings
131
- hf_logger = logging .getLogger ("transformers" )
132
- hf_logger_level = hf_logger .level
133
- hf_logger .setLevel (logging .ERROR )
134
- self .config = transformers .PretrainedConfig .from_pretrained (
135
- deployment_path ,
136
- finetuning_task = self .task if hasattr (self , "task" ) else None ,
137
- )
138
- hf_logger .setLevel (hf_logger_level )
139
-
140
- self .tokenizer = AutoTokenizer .from_pretrained (
141
- deployment_path ,
142
- trust_remote_code = self ._trust_remote_code ,
143
- model_max_length = self .sequence_length ,
126
+ # we will be soon retiring V1 pipelines. This is why I am deciding
127
+ # to reuse the functions from V2 pipelines in the (soon) legacy pipelines
128
+ onnx_path , config , tokenizer = setup_onnx_file_path_v2 (
129
+ model_path = self .model_path ,
130
+ sequence_length = self .sequence_length ,
131
+ task = self .task if hasattr (self , "task" ) else None ,
144
132
)
133
+ self .config = config
134
+ self .tokenizer = tokenizer
145
135
146
136
if not self ._delay_overwriting_inputs :
147
137
# overwrite onnx graph to given required input shape
@@ -153,12 +143,6 @@ def setup_onnx_file_path(self) -> str:
153
143
onnx_path , max_length = self .sequence_length
154
144
)
155
145
156
- if not self .config or not self .tokenizer :
157
- raise RuntimeError (
158
- "Invalid config or tokenizer provided. Please provide "
159
- "paths to the files or ensure they exist in the `model_path` provided. "
160
- "See `tokenizer` and `config` arguments for details."
161
- )
162
146
return onnx_path
163
147
164
148
def tokens_to_engine_input (
0 commit comments