Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Evaluating large language models
A large language model (LLM) is a type of artificial intelligence (AI) program that is designed for natural language processing tasks, such as recognizing and generating text.
As a data scientist, you might want to monitor your large language models against a range of metrics, in order to ensure the accuracy and quality of its output. Features such as summarization, language toxicity, and question-answering accuracy can be assessed to inform and improve your model parameters.
Red Hat OpenShift AI now offers Language Model Evaluation as a Service (LM-Eval-aaS), in a feature called LM-Eval. LM-Eval provides a unified framework to test generative language models on a vast range of different evaluation tasks.
The following sections show you how to create an LMEvalJob custom resource (CR) which allows you to activate an evaluation job and generate an analysis of your model’s ability.
2.1. Setting up LM-Eval Link kopierenLink in die Zwischenablage kopiert!
LM-Eval is a service designed for evaluating large language models that has been integrated into the TrustyAI Operator.
The service is built on top of two open-source projects:
- LM Evaluation Harness, developed by EleutherAI, that provides a comprehensive framework for evaluating language models
- Unitxt, a tool that enhances the evaluation process with additional functionalities
The following information explains how to create an LMEvalJob custom resource (CR) to initiate an evaluation job and get the results.
Global settings for LM-Eval
Configurable global settings for LM-Eval services are stored in the TrustyAI operator global ConfigMap, named trustyai-service-operator-config. The global settings are located in the same namespace as the operator.
You can configure the following properties for LM-Eval:
| Property | Default | Description |
|---|---|---|
|
|
|
Detect if there are GPUs available and assign a value for the |
|
|
| The image for the LM-Eval job. The image contains the Python packages for LM Evaluation Harness and Unitxt. |
|
|
|
The image for the LM-Eval driver. For detailed information about the driver, see the |
|
|
| The image-pulling policy when running the evaluation job. |
|
| 8 | The default batch size when invoking the model inference API. Default batch size is only available for local models. |
|
| 24 | The maximum batch size that users can specify in an evaluation job. |
|
| 10s | The interval to check the job pod for an evaluation job. |
After updating the settings in the ConfigMap, restart the operator to apply the new values.
2.2. Enabling external resource access for LMEval jobs Link kopierenLink in die Zwischenablage kopiert!
LMEval jobs do not allow internet access or remote code execution by default. When configuring an LMEvalJob, it may require access to external resources, for example task datasets and model tokenizers, usually hosted on Hugging Face. If you trust the source and have reviewed the content of these artifacts, an LMEvalJob can be configured to automatically download them.
Follow the steps below to enable online access and remote code execution for LMEval jobs. Choose to update these settings by using either the CLI or in the console. Enable one or both settings according to your needs.
2.2.1. Enabling online access and remote code execution for LMEval Jobs using the CLI Link kopierenLink in die Zwischenablage kopiert!
You can enable online access using the CLI for LMEval jobs by setting the allowOnline specification to true in the LMEvalJob custom resource (CR). You can also enable remote code execution by setting the allowCodeExecution specification to true. Both modes can be used at the same time.
Enabling online access or code execution involves a security risk. Only use these configurations if you trust the source(s).
Prerequisites
- You have cluster administrator privileges for your OpenShift cluster.
- You have downloaded and installed the OpenShift AI command-line interface (CLI). See Installing the OpenShift CLI.
Procedure
Get the current
DataScienceClusterresource, which is located in theredhat-ods-operatornamespace:oc get datasciencecluster -n redhat-ods-operator
$ oc get datasciencecluster -n redhat-ods-operatorCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME AGE default-dsc 10d
NAME AGE default-dsc 10dCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable online access and code execution for the cluster in the
DataScienceClusterresource with thepermitOnlineandpermitCodeExecutionspecifications. For example, create a file namedallow-online-code-exec-dsc.yamlwith the following contents:Example
allow-online-code-exec-dsc.yamlresource enabling online access and remote code executionCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
permitCodeExecutionandpermitOnlinesettings are disabled by default with a value ofdeny. You must explicitly enable these settings in theDataScienceClusterresource for theLMEvalJobinstance to enable internet access or permission to run any externally downloaded code.Apply the updated
DataScienceCluster:oc apply -f allow-online-code-exec-dsc.yaml -n redhat-ods-operator
$ oc apply -f allow-online-code-exec-dsc.yaml -n redhat-ods-operatorCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Run the following command to check that the
DataScienceClusteris in a healthy state:oc get datasciencecluster default-dsc
$ oc get datasciencecluster default-dscCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME READY REASON default-dsc True
NAME READY REASON default-dsc TrueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For new LMEval jobs, define the job in a YAML file as shown in the following example. This configuration requests both internet access, with
allowOnline: true, and permission for remote code execution with,allowCodeExecution: true:Example lmevaljob-with-online-code-exec.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
allowOnlineandallowCodeExecutionsettings are disabled by default with a value offalsein theLMEvalJobCR.Deploy the LMEval Job:
oc apply -f lmevaljob-with-online-code-exec.yaml -n <your_namespace>
$ oc apply -f lmevaljob-with-online-code-exec.yaml -n <your_namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you upgrade to version 2.25, some TrustyAI LMEvalJob CR configuration values might be overwritten. The new deployment prioritizes the value on the 2.25 version DataScienceCluster. Existing LMEval jobs are unaffected. Verify that all DataScienceCluster values are explicitly defined and validated during installation.
Verification
Run the following command to verify that the
DataScienceClusterhas the updated fields:oc get datasciencecluster default-dsc -n redhat-ods-operator -o "jsonpath={.data}"$ oc get datasciencecluster default-dsc -n redhat-ods-operator -o "jsonpath={.data}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to verify that the
trustyai-dsc-configConfigMap has the same flag values set in theDataScienceCluster.oc get configmaps trustyai-dsc-config -n redhat-ods-applications -o "jsonpath={.spec.components.trustyai.eval.lmeval}"$ oc get configmaps trustyai-dsc-config -n redhat-ods-applications -o "jsonpath={.spec.components.trustyai.eval.lmeval}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
{"eval.lmeval.permitCodeExecution":"true","eval.lmeval.permitOnline":"true"}{"eval.lmeval.permitCodeExecution":"true","eval.lmeval.permitOnline":"true"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2.2. Updating LMEval job configuration using the web console Link kopierenLink in die Zwischenablage kopiert!
Follow these steps to enable online access (allowOnline) and remote code execution (allowCodeExecution) modes through the OpenShift AI web console for LMEval jobs.
Enabling online access or code execution involves a security risk. Only use these configurations if you trust the source(s).
Prerequisites
- You have cluster administrator privileges for your Red Hat OpenShift AI cluster.
Procedure
-
In the OpenShift console, click Operators
Installed Operators. - Search for the Red Hat OpenShift AI Operator, and then click the Operator name to open the Operator details page.
- Click the Data Science Cluster tab.
- Click the default instance name (for example, default-dsc) to open the instance details page.
- Click the YAML tab to show the instance specifications.
In the
spec:components:trustyai:eval:lmevalsection, set thepermitCodeExecutionandpermitOnlinefields to a value ofallow:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Save.
- From the Project drop-down list, select the project that contains the LMEval job you are working with.
-
From the Resources drop-down list, select the
LMEvalJobinstance that you are working with. -
Click Actions
Edit YAML Ensure that the
allowOnlineandallowCodeExecutionare set totrueto enable online access and code execution for this job when writing yourLMEvalJobcustom resource:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Save.
| Field | Default | Description |
|---|---|---|
|
|
| Enables this job to access the internet (e.g., to download datasets or tokenizers). |
|
|
| Allows this job to run code included with downloaded resources. |
2.3. LM-Eval evaluation job Link kopierenLink in die Zwischenablage kopiert!
LM-Eval service defines a new Custom Resource Definition (CRD) called LMEvalJob. An LMEvalJob object represents an evaluation job. LMEvalJob objects are monitored by the TrustyAI Kubernetes operator.
To run an evaluation job, create an LMEvalJob object with the following information: model, model arguments, task, and secret.
For a list of TrustyAI-supported tasks, see LMEval task support.
After the LMEvalJob is created, the LM-Eval service runs the evaluation job. The status and results of the LMEvalJob object update when the information is available.
Other TrustyAI features (such as bias and drift metrics) cannot be used with non-tabular models (including LLMs). Deploying the TrustyAIService custom resource (CR) in a namespace that contains non-tabular models (such as the namespace where an evaluation job is being executed) can cause errors within the TrustyAI service.
Sample LMEvalJob object
The sample LMEvalJob object contains the following features:
-
The
google/flan-t5-basemodel from Hugging Face. -
The dataset from the
wnlicard, a subset of the GLUE (General Language Understanding Evaluation) benchmark evaluation framework from Hugging Face. For more information about thewnliUnitxt card, see the Unitxt website. -
The following default parameters for the
multi_class.relationUnitxt task:f1_micro,f1_macro, andaccuracy. This template can be found on the Unitxt website: click Catalog, then click Tasks and select Classification from the menu.
The following is an example of an LMEvalJob object:
After you apply the sample LMEvalJob, check its state by using the following command:
oc get lmevaljob evaljob-sample
oc get lmevaljob evaljob-sample
Output similar to the following appears: NAME: evaljob-sample STATE: Running
Evaluation results are available when the state of the object changes to Complete. Both the model and dataset in this example are small. The evaluation job should finish within 10 minutes on a CPU-only node.
Use the following command to get the results:
oc get lmevaljobs.trustyai.opendatahub.io evaljob-sample \
-o template --template={{.status.results}} | jq '.results'
oc get lmevaljobs.trustyai.opendatahub.io evaljob-sample \
-o template --template={{.status.results}} | jq '.results'
The command returns results similar to the following example:
Notes on the results
-
The
f1_micro,f1_macro, andaccuracyscores are 0.56, 0.36, and 0.56. -
The full results are stored in the
.status.resultsof theLMEvalJobobject as a JSON document. - The command above only retrieves the results field of the JSON document.
The provided LMEvalJob uses a dataset from the wnli card, which is in Parquet format and not supported on s390x. To run on s390x, choose a task that uses a non-Parquet dataset.
2.4. LM-Eval evaluation job properties Link kopierenLink in die Zwischenablage kopiert!
The LMEvalJob object contains the following features:
-
The
google/flan-t5-basemodel. -
The dataset from the
wnlicard, from the GLUE (General Language Understanding Evaluation) benchmark evaluation framework. -
The
multi_class.relationUnitxt task default parameters.
The following table lists each property in the LMEvalJob and its usage:
| Parameter | Description |
|---|---|
|
|
Specifies which model type or provider is evaluated. This field directly maps to the
|
|
| A list of paired name and value arguments for the model type. Arguments vary by model provider. You can find further details in the models section of the LM Evaluation Harness library on GitHub. Below are examples for some providers:
|
|
|
Specifies a list of tasks supported by |
|
| Specifies the task using the Unitxt recipe format:
|
|
|
Sets the number of few-shot examples to place in context. If you are using a task from Unitxt, do not use this field. Use |
|
|
Set a limit to run the tasks instead of running the entire dataset. Accepts either an integer or a float between |
|
|
Maps to the |
|
| If this flag is passed, then the model outputs and the text fed into the model are saved at per-prompt level. |
|
|
Specifies the batch size for the evaluation in integer format. The |
|
|
Specifies extra information for the
|
|
| This parameter defines a custom output location to store the the evaluation results. Only Persistent Volume Claims (PVC) are supported. |
|
|
Creates an operator-managed PVC to store the job results. The PVC is named
|
|
| Binds an existing PVC to a job by specifying its name. The PVC must be created separately and must already exist when creating the job. |
|
|
If this parameter is set to |
|
|
If this parameter is set to |
|
| Mount a PVC as the local storage for models and datasets. |
|
| (Optional) Sets the system instruction for all prompts passed to the evaluated model. |
|
|
Applies the specified chat template to prompts. Contains two fields: * |
2.4.1. Properties for setting up custom Unitxt cards, templates, or system prompts Link kopierenLink in die Zwischenablage kopiert!
You can choose to set up custom Unitxt cards, templates, or system prompts. Use the parameters set out in the Custom Unitxt parameters table in addition to the preceding table parameters to set customized Unitxt items:
| Parameter | Description |
|---|---|
|
| Defines one or more custom resources that is referenced in a task recipe. The following custom cards, templates, and system prompts are supported:
|
2.5. Performing model evaluations in the dashboard Link kopierenLink in die Zwischenablage kopiert!
LM-Eval is a Language Model Evaluation as a Service (LM-Eval-aaS) feature integrated into the TrustyAI Operator. It offers a unified framework for testing generative language models across a wide variety of evaluation tasks. You can use LM-Eval through the Red Hat OpenShift AI dashboard or the OpenShift CLI (oc). These instructions are for using the dashboard.
Model evaluation through the dashboard is currently available in Red Hat OpenShift AI 3.0 as a Technology Preview feature. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
Prerequisites
- You have logged in to Red Hat OpenShift AI with administrator privileges.
- You have enabled the TrustyAI component, as described in Enabling the TrustyAI component.
- You have created a project in OpenShift AI.
- You have deployed an LLM model in your project.
By default, the Develop & train OdhDashboardConfig custom resource (CR) in Red Hat OpenShift AI and set the disableLMEval value to false. For more information about enabling dashboard configuration options, see Dashboard configuration options.
Procedure
In the dashboard, click Develop & train
Evaluations. The Evaluations page opens. It contains: - A Start evaluation run button. If you have not run any previous evaluations, only this button is displayed.
- A list of evaluations you have previously run, if any exist.
- A Project dropdown option you can click to show the evaluations relating to one project instead of all projects.
- A filter to sort your evaluations by model or evaluation name.
The following table outlines the elements and functions of the evaluations list:
| Property | Function |
|---|---|
| Evaluation | The name of the evaluation. |
| Model | The model that was used in the evaluation. |
| Evaluated | The date and time when the evaluation was created. |
| Status | The status of your evaluation: running, completed, or failed. |
| More options icon | Click this icon to access the options to delete the evaluation, or download the evaluation log in JSON format. |
- From the Project dropdown menu, select the namespace of the project where you want to evaluate the model.
- Click the Start evaluation run button. The Model evaluation form is displayed.
Fill in the details of the form. The model argument summary is displayed after you complete the form details:
- Model name: Select a model from all the deployed LLMs in your project.
- Evaluation name: Give your evaluation a unique name.
- Tasks: Choose one or more evaluation tasks against which to measure your LLM. The 100 most common evaluation tasks are supported.
Model type: Choose the type of model based on the type of prompt-formatting you use:
- Local-completion: You assemble the entire prompt chain yourself. Use this when you want to evaluate models that take a plain text prompt and return a continuation.
-
Local-chat-completion: The framework injects roles or templates automatically. Use this for models that simulate a conversation by taking a list of chat messages with roles like
userandassistantand reply appropriately.
Security settings:
- Available online: Choose enable to allow your model to access the internet to download datasets.
Trust remote code: Choose enable to allow your model to trust code from outside of the project namespace.
NoteThe Security settings section is grayed out if the security option in global settings is set to
active.
- Observe that a model argument summary is displayed as soon as you fill in the form details.
Complete the tokenizer settings:
-
Tokenized requests: If set to
true, the evaluation requests are broken down into tokens. If set tofalse, the evaluation dataset remains as raw text. - Tokenizer: Type the model’s tokenizer URL that is required for the evaluations.
-
Tokenized requests: If set to
Click Evaluate. The screen returns to the model evaluation page of your project and your job is displayed in the evaluations list.
Note- It can take time for your evaluation to complete, depending on factors including hardware support, model size, and the type of evaluation task(s). The status column reports the current status of the evaluation: completed, running, or failed.
- If your evaluation fails, the evaluation pod logs in your cluster provide more information.
2.6. LM-Eval scenarios Link kopierenLink in die Zwischenablage kopiert!
The following procedures outline example scenarios that can be useful for an LM-Eval setup.
2.6.1. Accessing Hugging Face models with an environment variable token Link kopierenLink in die Zwischenablage kopiert!
If the LMEvalJob needs to access a model on HuggingFace with the access token, you can set up the HF_TOKEN as one of the environment variables for the lm-eval container.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
Procedure
To start an evaluation job for a
huggingfacemodel, apply the following YAML file to your project through the CLI:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc apply -f <yaml_file> -n <project_name>
$ oc apply -f <yaml_file> -n <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) You can also create a secret to store the token, then refer the key from the
secretKeyRefobject using the following reference syntax:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6.2. Using a custom Unitxt card Link kopierenLink in die Zwischenablage kopiert!
You can run evaluations using custom Unitxt cards. To do this, include the custom Unitxt card in JSON format within the LMEvalJob YAML.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
Procedure
Pass a custom Unitxt Card in JSON format:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Inside the custom card specify the Hugging Face dataset loader:
"loader": { "__type__": "load_hf", "path": "glue", "name": "wnli" },"loader": { "__type__": "load_hf", "path": "glue", "name": "wnli" },Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
(Optional) You can use other Unitxt loaders (found on the Unitxt website) that contain the
volumesandvolumeMountsparameters to mount the dataset from persistent volumes. For example, if you use theLoadCSVUnitxt command, mount the files to the container and make the dataset accessible for the evaluation process.
The provided scenario example does not work on s390x, as it uses a Parquet-type dataset, which is not supported on this architecture. To run the scenario on s390x, use a task with a non-Parquet dataset.
2.6.3. Using PVCs as storage Link kopierenLink in die Zwischenablage kopiert!
To use a PVC as storage for the LMEvalJob results, you can use either managed PVCs or existing PVCs. Managed PVCs are managed by the TrustyAI operator. Existing PVCs are created by the end-user before the LMEvalJob is created.
If both managed and existing PVCs are referenced in outputs, the TrustyAI operator defaults to the managed PVC.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
2.6.3.1. Managed PVCs Link kopierenLink in die Zwischenablage kopiert!
To create a managed PVC, specify its size. The managed PVC is named <job-name>-pvc and is available after the job finishes. When the LMEvalJob is deleted, the managed PVC is also deleted.
Procedure
Enter the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Notes on the code
-
outputsis the section for specifying custom storage locations -
pvcManagedwill create an operator-managed PVC -
size(compatible with standard PVC syntax) is the only supported value
2.6.3.2. Existing PVCs Link kopierenLink in die Zwischenablage kopiert!
To use an existing PVC, pass its name as a reference. The PVC must exist when you create the LMEvalJob. The PVC is not managed by the TrustyAI operator, so it is available after deleting the LMEvalJob.
Procedure
Create a PVC. An example is the following:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reference the new PVC from the
LMEvalJob.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6.4. Using a KServe Inference Service Link kopierenLink in die Zwischenablage kopiert!
To run an evaluation job on an InferenceService which is already deployed and running in your namespace, define your LMEvalJob CR, then apply this CR into the same namespace as your model.
NOTE
The following example only works with Hugging Face or vLLM-based model-serving runtimes.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
- You have a namespace that contains an InferenceService with a vLLM model. This example assumes that a vLLM model is already deployed in your cluster.
- Your cluster has Domain Name System (DNS) configured.
Procedure
Define your
LMEvalJobCR:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Apply this CR into the same namespace as your model.
Verification
A pod spins up in your model namespace called evaljob. In the pod terminal, you can see the output via tail -f output/stderr.log.
Notes on the code
-
base_urlshould be set to the route/service URL of your model. Make sure to include the/v1/completionsendpoint in the URL. -
env.valueFrom.secretKeyRef.nameshould point to a secret that contains a token that can authenticate to your model.secretRef.nameshould be the secret’s name in the namespace, whilesecretRef.keyshould point at the token’s key within the secret. secretKeyRef.namecan equal the output of:oc get secrets -o custom-columns=SECRET:.metadata.name --no-headers | grep user-one-token
oc get secrets -o custom-columns=SECRET:.metadata.name --no-headers | grep user-one-tokenCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
secretKeyRef.keyis set totoken
2.6.5. Setting up LM-Eval S3 Support Link kopierenLink in die Zwischenablage kopiert!
Learn how to set up S3 support for your LM-Eval service.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
- You have a namespace that contains an S3-compatible storage service and bucket.
-
You have created an
LMEvalJobthat references the S3 bucket containing your model and dataset. - You have an S3 bucket that contains the model files and the dataset(s) to be evaluated.
Procedure
Create a Kubernetes Secret containing your S3 connection details:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAll values must be
base64encoded. For example:echo -n "my-bucket" | base64Deploy the
LMEvalJobCR that references the S3 bucket containing your model and dataset:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantThe `LMEvalJob` will copy all the files from the specified bucket/path. If your bucket contains many files and you only want to use a subset, set the `path` field to the specific sub-folder containing the files that you require. For example use `path: "my-models/"`.
The `LMEvalJob` will copy all the files from the specified bucket/path. If your bucket contains many files and you only want to use a subset, set the `path` field to the specific sub-folder containing the files that you require. For example use `path: "my-models/"`.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set up a secure connection using SSL.
Create a ConfigMap object with your CA certificate:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the
LMEvalJobto use SSL verification:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
After deploying the
LMEvalJob, open thekubectlcommand-line and enter this command to check its status:kubectl logs -n test job/evaljob-sample -n test -
View the logs with the
kubectlcommandkubectl logs -n test job/<job-name>to make sure it has functioned correctly. - The results are displayed in the logs after the evaluation is completed.
2.6.6. Using LLM-as-a-Judge metrics with LM-Eval Link kopierenLink in die Zwischenablage kopiert!
You can use a large language model (LLM) to assess the quality of outputs from another LLM, known as LLM-as-a-Judge (LLMaaJ).
You can use LLMaaJ to:
- Assess work with no clearly correct answer, such as creative writing.
- Judge quality characteristics such as helpfulness, safety, and depth.
-
Augment traditional quantitative measures that are used to evaluate a model’s performance (for example,
ROUGEmetrics). - Test specific quality aspects of your model output.
Follow the custom quality assessment example below to learn more about using your own metrics criteria with LM-Eval to evaluate model responses.
This example uses Unitxt to define custom metrics and to see how the model (flan-t5-small) answers questions from MT-Bench, a standard benchmark. Custom evaluation criteria and instructions from the Mistral-7B model are used to rate the answers from 1-10, based on helpfulness, accuracy, and detail.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- Your cluster administrator has installed OpenShift AI and enabled the TrustyAI service for the project where the models are deployed.
- You are familiar with how to use Unitxt.
You have set the following parameters:
Expand Table 2.6. Parameters Parameter Description Custom template
Tells the judge to assign a score between 1 and 10 in a standardized format, based on specific criteria.
processors.extract_mt_bench_rating_judgmentPulls the numerical rating from the judge’s response.
formats.models.mistral.instructionFormats the prompts for the Mistral model.
Custom LLM-as-judge metric
Uses Mistral-7B with your custom instructions.
Procedure
In a terminal window, if you are not already logged in to your OpenShift cluster as a cluster administrator, log in to the OpenShift CLI (
oc) as shown in the following example:oc login <openshift_cluster_url> -u <admin_username> -p <password>
$ oc login <openshift_cluster_url> -u <admin_username> -p <password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the following manifest by using the
oc apply -f -command. The YAML content defines a custom evaluation job (LMEvalJob), the namespace, and the location of the model you want to evaluate. The YAML contains the following instructions:- Which model to evaluate.
- What data to use.
- How to format inputs and outputs.
- Which judge model to use.
How to extract and log results.
NoteYou can also put the YAML manifest into a file using a text editor and then apply it by using the
oc apply -f file.yamlcommand.
Verification
A processor extracts the numeric rating from the judge’s natural language response. The final result is available as part of the LMEval Job Custom Resource (CR).
The provided scenario example does not work for s390x. The scenario works with non-Parquet type dataset task for s390x.