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

use _validate, _inference_remote, _inference_local #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 40 additions & 1 deletion validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
self._arg_1 = arg_1
self._arg_2 = arg_2

def validate(self, value: Any, metadata: Dict = {}) -> ValidationResult:
def _validate(self, value: Any, metadata: Dict = {}) -> ValidationResult:
"""Validates that {fill in how you validator interacts with the passed value}."""
# Add your custom validator logic here and return a PassResult or FailResult accordingly.
if value != "pass": # FIXME
Expand All @@ -46,3 +46,42 @@ def validate(self, value: Any, metadata: Dict = {}) -> ValidationResult:
fix_value="{The programmtic fix if applicable, otherwise remove this kwarg.}",
)
return PassResult()

def _inference_local(self, model_input: Any) -> Any:
"""
Runs a machine learning pipeline on some input on the local
machine. This function should receive the expected input to the
ML model, and output the results from the ml model.
"""
raise NotImplementedError

def _inference_remote(self, model_input: Any) -> Any:
"""
Runs a machine learning pipeline on some input on a remote
machine. This function should receive the expected input to the
ML model, and output the results from the ml model.

"""
raise NotImplementedError

def _inference(self, model_input: Any) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to rework how this and the base Validator class interact. Maybe by specifying any methods we want/need the validator author to override as abstract. I would prefer to keep the higher level orchestration methods like this one in house vs requiring the author to define it.

"""Calls either a local or remote inference engine for use in the
validation call.

Args:
model_input (Any): Receives the input to be passed to your ML model.

Returns:
Any: Returns the output from the ML model inference.
"""
# Only use if both are set, otherwise fall back to local inference
if self.use_local:
return self._inference_local(model_input)
if not self.use_local and self.validation_endpoint:
return self._inference_remote(model_input)

raise RuntimeError(
"No inference endpoint set, but use_local was false. "
"Please set either use_local=True or "
"set an validation_endpoint to perform inference in the validator."
)