Skip to content

Commit

Permalink
Merge pull request #1162 from jayercule/jayallen/remote-validation-edits
Browse files Browse the repository at this point in the history
Edited remote validation notebook
  • Loading branch information
zsimjee authored Dec 5, 2024
2 parents 6dec8c8 + b2a16a8 commit f55e470
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions docs/concepts/remote_validation_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
"source": [
"# Remote Validation Inference\n",
"\n",
"## The Need\n",
"## The problem\n",
"\n",
"As a concept, guardrailing has a few areas which, when unoptimized, can be extremely latency and resource expensive to run. The main two areas are in guardrailing orchestration and in the ML models used for validating a single guard. These two are resource heavy in slightly different ways. ML models can run with really low latency on GPU-equipped machines, while guardrailing orchestration benefits from general memory and compute resources. Some ML models used for validation run in tens of seconds on CPUs, while they run in milliseconds on GPUs.\n",
"As a concept, [guardrailing](https://www.guardrailsai.com/docs/concepts/guard) has a few areas that, when unoptimized, can introduce latency and be extremely resource-expensive. The main two areas are: \n",
"\n",
"* Guardrailing orchestration; and\n",
"* ML models that validate a single guard\n",
"\n",
"These are resource-heavy in slightly different ways. ML models can run with low latency on GPU-equipped machines. (Some ML models used for validation run in tens of seconds on CPUs, while they run in milliseconds on GPUs.) Meanwhile, guardrailing orchestration benefits from general memory and compute resources. \n",
"\n",
"## The Guardrails approach\n",
"\n",
"The Guardrails library tackles this problem by providing an interface that allows users to separate the execution of orchestraion from the exeuction of ML-based validation.\n",
"The Guardrails library tackles this problem by providing an interface that allows users to separate the execution of orchestration from the execution of ML-based validation.\n",
"\n",
"The layout of this solution is a simple upgrade to validator libraries themselves. Instead of *always* downloading and installing ML models, they can be configured to reach out to a remote endpoint. This remote endpoint hosts the ML model behind an API that has a uninfied interface for all validator models. Guardrails hosts some of these as a preview feature for free, and users can host their own models as well by following the same interface.\n",
"The layout of this solution is a simple upgrade to validator libraries themselves. Instead of *always* downloading and installing ML models, you can configure them to call a remote endpoint. This remote endpoint hosts the ML model behind an API that presents a unified interface for all validator models. \n",
"\n",
"Guardrails hosts some of these for free as a preview feature. Users can host their own models by following the same interface.\n",
"\n",
"\n",
":::note\n",
Expand All @@ -26,15 +33,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using Guardrails Inferencing Endpoints\n",
"## Using Guardrails inferencing endpoints\n",
"\n",
"To use an guardrails endpoint, you simply need to find a validator that has implemented support. Validators with a Guardrails hosted endpoint are labeled as such on the [Validator Hub](https://hub.guardrailsai.com). One example is ToxicLanguage.\n",
"To use a guardrails endpoint, find a validator that has implemented support. Validators with a Guardrails-hosted endpoint are labeled as such on the [Validator Hub](https://hub.guardrailsai.com). One example is [Toxic Language](https://hub.guardrailsai.com/validator/guardrails/toxic_language).\n",
"\n",
"\n",
":::note\n",
"To use remote inferencing endpoints, you need to have a Guardrails API key. You can get one by signing up at [the Guardrails Hub](https://hub.guardrailsai.com).\n",
"To use remote inferencing endpoints, you need a Guardrails API key. You can get one by signing up at [the Guardrails Hub](https://hub.guardrailsai.com). \n",
"\n",
"Then, run `guardrails configure`\n",
"Then, run `guardrails configure`.\n",
":::"
]
},
Expand Down Expand Up @@ -79,7 +86,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The major benefit of hosting a validator inference endpoint is the increase in speed and throughput compared to running locally. This implementation makes use cases such as streaming much more viable!\n"
"The benefit of hosting a validator inference endpoint is the increase in speed and throughput compared to running locally. This implementation makes use cases such as [streaming](https://www.guardrailsai.com/docs/concepts/streaming) much more viable in production.\n"
]
},
{
Expand Down Expand Up @@ -114,11 +121,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Toggling Remote Inferencing\n",
"\n",
"To enable/disable remote inferencing, you can run the cli command `guardrails configure` or modify your `~/.guardrailsrc`.\n",
"## Toggling remote inferencing\n",
"\n",
"\n"
"To enable/disable remote inferencing, you can run the CLI command `guardrails configure` or modify your `~/.guardrailsrc`."
]
},
{
Expand All @@ -142,10 +147,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To disable remote inferencing from a specific validator, you can add a `use_local` kwarg to the validator's initializer\n",
"To disable remote inferencing from a specific validator, add a `use_local` kwarg to the validator's initializer. \n",
"\n",
":::note\n",
"When runnning locally, you may need to reinstall the validator with the --install-local-models flag.\n",
"When running locally, you may need to reinstall the validator with the `--install-local-models` flag.\n",
":::"
]
},
Expand All @@ -172,9 +177,9 @@
"source": [
"## Hosting your own endpoint\n",
"\n",
"Validators are able to point to any endpoint that implements the interface that Guardrails validators expect. This interface can be found in the `_inference_remote` method of the validator.\n",
"Validators can point to any endpoint that implements the interface that Guardrails validators expect. This interface can be found in the `_inference_remote` method of the validator.\n",
"\n",
"After implementing this interface, you can host your own endpoint (for example, using gunicorn and Flask) and point your validator to it by setting the `validation_endpoint` constructor argument.\n"
"After implementing this interface, you can host your own endpoint (for example, [using gunicorn and Flask](https://flask.palletsprojects.com/en/stable/deploying/gunicorn/)) and point your validator to it by setting the `validation_endpoint` constructor argument.\n"
]
},
{
Expand Down Expand Up @@ -225,7 +230,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f55e470

Please sign in to comment.