Skip to content
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

benchmarker API #1259

Merged
merged 13 commits into from
Sep 27, 2023
13 changes: 13 additions & 0 deletions src/deepsparse/benchmark/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
57 changes: 57 additions & 0 deletions src/deepsparse/benchmark/api/benchmarker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from typing import Optional

from deepsparse.benchmark.benchmark_model import benchmark_model
from deepsparse.benchmark.benchmark_pipeline import benchmark_pipeline


class Benchmarker:
def __init__(self, model, pipeline, url):
self.model = model
self.pipeline = pipeline
self.url = url
horheynm marked this conversation as resolved.
Show resolved Hide resolved

def __call__(self, **kwargs):

if self.model:
benchmark_model(model_path=self.model, **kwargs)

if self.pipeline:
benchmark_pipeline(model_path=self.pipeline, **kwargs)

if self.url:
# benchmark with url here
pass

@staticmethod
horheynm marked this conversation as resolved.
Show resolved Hide resolved
def benchmark(
model: Optional[str] = None,
pipeline: Optional[str] = None,
url: Optional[str] = None,
**kwargs,
):
if len((model, pipeline, url)) != 1:
return ValueError("[api.benchmark] Only one input arg required")

if model:
benchmarker = Benchmarker(model=model)
elif pipeline:
benchmarker = Benchmarker(pipeline=pipeline)
elif url:
benchmarker = Benchmarker(url=url)

return benchmarker(**kwargs)
Loading