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

[Move] Common Evaluation Modules to Sparsezoo` #1520

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/deepsparse/evaluation/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
##########
Example command for evaluating a quantized MPT model from SparseZoo using the Deepsparse Engine.
The evaluation will be run using `lm-evaluation-harness` on `hellaswag` and `gsm8k` datasets:
deepsparse.eval zoo:mpt-7b-mpt_pretrain-base_quantized \
deepsparse.eval --target zoo:mpt-7b-mpt_pretrain-base_quantized \
rahul-tuli marked this conversation as resolved.
Show resolved Hide resolved
--dataset hellaswag \
--dataset gsm8k \
--integration lm-evaluation-harness \
Expand All @@ -72,13 +72,13 @@
import click

from deepsparse.evaluation.evaluator import evaluate
from deepsparse.evaluation.results import Result, save_result
from deepsparse.evaluation.utils import args_to_dict, get_save_path
from deepsparse.operators.engine_operator import (
DEEPSPARSE_ENGINE,
ORT_ENGINE,
TORCHSCRIPT_ENGINE,
)
from sparsezoo.evaluation.results import Result, save_result


_LOGGER = logging.getLogger(__name__)
Expand Down
11 changes: 5 additions & 6 deletions src/deepsparse/evaluation/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
# 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.
import logging
from typing import Any, List, Optional, Union

from deepsparse.evaluation.registry import EvaluationRegistry
from deepsparse.evaluation.results import Result
from deepsparse.evaluation.registry import DeepSparseEvaluationRegistry
from deepsparse.evaluation.utils import create_model_from_target
from deepsparse.operators.engine_operator import (
DEEPSPARSE_ENGINE,
ORT_ENGINE,
TORCHSCRIPT_ENGINE,
)
from sparsezoo.evaluation.results import Result


__all__ = ["evaluate"]

_LOGGER = logging.getLogger(__name__)


def evaluate(
target: Any,
Expand All @@ -50,7 +47,9 @@ def evaluate(
else target
)

eval_integration = EvaluationRegistry.resolve(model, datasets, integration)
eval_integration = DeepSparseEvaluationRegistry.resolve(
model=model, datasets=datasets, integration=integration
)

return eval_integration(
model=model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@

import torch
from deepsparse import Pipeline
from deepsparse.evaluation.registry import EvaluationRegistry
from deepsparse.evaluation.results import Dataset, Evaluation, Metric, Result
from deepsparse.evaluation.registry import DeepSparseEvaluationRegistry
from lm_eval import base, evaluator, tasks, utils
from sparsezoo.evaluation.results import Dataset, Evaluation, Metric, Result


_LOGGER = logging.getLogger(__name__)

__all__ = ["integration_eval"]


@EvaluationRegistry.register(name="lm-evaluation-harness")
@DeepSparseEvaluationRegistry.register(name="lm-evaluation-harness")
def integration_eval(
model: Any,
datasets: Union[List[str], str],
Expand Down
23 changes: 10 additions & 13 deletions src/deepsparse/evaluation/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
import logging
from typing import Any, Callable, List, Optional, Union

from sparsezoo.utils.registry import RegistryMixin
from sparsezoo.evaluation import EvaluationRegistry


__all__ = ["EvaluationRegistry"]
__all__ = ["DeepSparseEvaluationRegistry"]

_LOGGER = logging.getLogger(__name__)


class EvaluationRegistry(RegistryMixin):
class DeepSparseEvaluationRegistry(EvaluationRegistry):
rahul-tuli marked this conversation as resolved.
Show resolved Hide resolved
"""
Extends the RegistryMixin to enable registering
and loading of evaluation functions.
"""
and loading of evaluation functions for DeepSparse.

@classmethod
def load_from_registry(cls, name: str) -> Callable[..., "Result"]: # noqa: F821
return cls.get_value_from_registry(name=name)
Adds a resolve method to automatically infer the integration
from the model and datasets if not specified, and returns
the appropriate evaluation function as a callable.
"""

@classmethod
def resolve(
Expand All @@ -43,7 +43,7 @@ def resolve(
integration: Optional[str] = None,
) -> Callable[..., "Result"]: # noqa: F821
"""
Chooses an evaluation function from the registry based on the target,
Chooses an evaluation function from the registry based on the model,
datasets and integration.

If integration is specified, attempts to load the evaluation function
Expand All @@ -70,7 +70,4 @@ def resolve(

potentially_check_dependency_import(integration)

try:
return cls.load_from_registry(name=integration)
except KeyError as err:
raise KeyError(err)
return cls.get_value_from_registry(name=integration)
107 changes: 0 additions & 107 deletions src/deepsparse/evaluation/results.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/deepsparse/evaluation/test_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest
from deepsparse.evaluation.evaluator import evaluate
from deepsparse.evaluation.integrations import try_import_lm_evaluation_harness
from deepsparse.evaluation.registry import EvaluationRegistry
from deepsparse.evaluation.registry import DeepSparseEvaluationRegistry
from deepsparse.evaluation.results import (
Dataset,
EvalSample,
Expand All @@ -31,7 +31,7 @@
)


@EvaluationRegistry.register()
@DeepSparseEvaluationRegistry.register()
def dummy_integration(*args, **kwargs):
result_formatted = [
Evaluation(
Expand Down
51 changes: 0 additions & 51 deletions tests/deepsparse/evaluation/test_registry.py

This file was deleted.

78 changes: 0 additions & 78 deletions tests/deepsparse/evaluation/test_results.py

This file was deleted.