Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ deepsparse.benchmark [-h] [-b BATCH_SIZE] [-shapes INPUT_SHAPES]
## 👩‍💻 NLP Inference Example

```python
from deepsparse.transformers import pipeline
from deepsparse import Pipeline

# SparseZoo model stub or path to ONNX file
model_path = "zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/12layer_pruned80_quant-none-vnni"

qa_pipeline = pipeline(
qa_pipeline = Pipeline.create(
task="question-answering",
model_path=model_path,
)
Expand Down
9 changes: 1 addition & 8 deletions src/deepsparse/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(
self._engine_args["scheduler"] = scheduler

self._onnx_file_path = self.setup_onnx_file_path()
self._engine = self._initialize_engine()
self.engine = self._initialize_engine()
pass

def __call__(self, *args, **kwargs) -> BaseModel:
Expand Down Expand Up @@ -350,13 +350,6 @@ def model_path(self) -> str:
"""
return self._model_path

@property
def engine(self) -> Union[Engine, ORTEngine]:
"""
:return: engine instance used for model forward pass in pipeline
"""
return self._engine

@property
def engine_args(self) -> Dict[str, Any]:
"""
Expand Down
1 change: 0 additions & 1 deletion src/deepsparse/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,3 @@ def _check_transformers_install():
from .helpers import *
from .loaders import *
from .pipelines import *
from .server import *
34 changes: 17 additions & 17 deletions src/deepsparse/transformers/eval_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

from tqdm.auto import tqdm

from deepsparse.transformers import pipeline
from deepsparse import Pipeline


from datasets import load_dataset, load_metric # isort: skip
Expand All @@ -79,14 +79,14 @@ def squad_eval(args):
squad_metrics = load_metric("squad")

# load QA pipeline
question_answer = pipeline(
question_answer = Pipeline.create(
task="question-answering",
model_path=args.onnx_filepath,
engine_type=args.engine,
num_cores=args.num_cores,
max_length=args.max_sequence_length,
sequence_length=args.max_sequence_length,
)
print(f"Engine info: {question_answer.model}")
print(f"Engine info: {question_answer.engine}")

for idx, sample in enumerate(tqdm(squad)):
pred = question_answer(
Expand All @@ -96,7 +96,7 @@ def squad_eval(args):
)

squad_metrics.add_batch(
predictions=[{"prediction_text": pred["answer"], "id": sample["id"]}],
predictions=[{"prediction_text": pred.answer, "id": sample["id"]}],
references=[{"answers": sample["answers"], "id": sample["id"]}],
)

Expand All @@ -114,19 +114,19 @@ def mnli_eval(args):
mnli_metrics = load_metric("glue", "mnli")

# load pipeline
text_classify = pipeline(
text_classify = Pipeline.create(
task="text-classification",
model_path=args.onnx_filepath,
engine_type=args.engine,
num_cores=args.num_cores,
max_length=args.max_sequence_length,
sequence_length=args.max_sequence_length,
)
print(f"Engine info: {text_classify.model}")
print(f"Engine info: {text_classify.engine}")

for idx, sample in enumerate(tqdm(mnli_matched)):
pred = text_classify(sample["premise"], sample["hypothesis"])
mnli_metrics.add_batch(
predictions=[int(pred[0]["label"].split("_")[-1])],
predictions=[int(pred.labels[0].split("_")[-1])],
references=[sample["label"]],
)

Expand All @@ -152,20 +152,20 @@ def qqp_eval(args):
qqp_metrics = load_metric("glue", "qqp")

# load pipeline
text_classify = pipeline(
text_classify = Pipeline.create(
task="text-classification",
model_path=args.onnx_filepath,
engine_type=args.engine,
num_cores=args.num_cores,
max_length=args.max_sequence_length,
sequence_length=args.max_sequence_length,
)
print(f"Engine info: {text_classify.model}")
print(f"Engine info: {text_classify.engine}")

for idx, sample in enumerate(tqdm(qqp)):
pred = text_classify([[sample["question1"], sample["question2"]]])

qqp_metrics.add_batch(
predictions=[int(pred[0]["label"].split("_")[-1])],
predictions=[int(pred.labels[0].split("_")[-1])],
references=[sample["label"]],
)

Expand All @@ -181,22 +181,22 @@ def sst2_eval(args):
sst2_metrics = load_metric("glue", "sst2")

# load pipeline
text_classify = pipeline(
text_classify = Pipeline.create(
task="text-classification",
model_path=args.onnx_filepath,
engine_type=args.engine,
num_cores=args.num_cores,
max_length=args.max_sequence_length,
sequence_length=args.max_sequence_length,
)
print(f"Engine info: {text_classify.model}")
print(f"Engine info: {text_classify.engine}")

for idx, sample in enumerate(tqdm(sst2)):
pred = text_classify(
sample["sentence"],
)

sst2_metrics.add_batch(
predictions=[int(pred[0]["label"].split("_")[-1])],
predictions=[int(pred.labels[0].split("_")[-1])],
references=[sample["label"]],
)

Expand Down
Loading