Consistency check

Updated at:

Overview

Feature consistency is a common engineering challenge in algorithm projects. It requires the logic for model training features to match the logic for online scoring features. Mismatches can lead to inconsistent scores and performance degradation in your products or applications. We recommend running consistency check tasks regularly to prevent performance issues caused by feature inconsistencies.

This feature automates the comparison between offline and online features to identify the following issues:

  • Inconsistent feature names: The names of online features do not match those of offline features.

  • Mismatched feature types: Features with the same name have different data types for online and offline processing.

  • Missing features: Online features are missing or are not constructed. This can happen if contextual features are not passed to the online service or if the service fails to generate the required features.

  • Mismatched feature values: The logic or methods for processing online feature values are inconsistent with how offline features were constructed.

  • Incorrect model feature processing logic: A processor, such as the one in EasyRec, may need to handle feature loading, default values, and feature derivation (FG features) before scoring. By enabling the EasyRec Processor's debug mode, you can capture the generated features for a detailed comparison.

Comparison workflow

Flowchart

image.png

Workflow details

Step 1: Create and start a consistency task

To compare feature consistency, you must first start a configured task in the console. The recommended path is Full-link Service Platform > Troubleshooting Tools > Consistency Check.

When you start a consistency check task, the Configuration Center first provisions the necessary resources based on the task configuration to process feature logs and model logs. Once the resources are created, the Configuration Center adds the required service parameters, and the task starts.

Step 2: PAI-REC engine retrieves parameters

The PAI-REC engine uses the Configuration Center SDK to fetch the latest service parameters, which include the parameters for the enabled consistency check task.

Step 3: Feature logs are persisted and retrieved

After receiving the task parameters, the PAI-REC engine persists the feature logs from the service process to MaxCompute.

Simultaneously, the Configuration Center retrieves these feature logs.

Step 4: Configuration Center calls the feature replay API

After retrieving the feature logs, the Configuration Center calls the feature replay API of the PAI-REC engine in batches based on the sampling rate defined in the task settings. Feature replay involves sending a new request to a dedicated PAI-REC engine interface with the logged features. This interface is designed to enable the debug mode for the model service.

Step 5: PAI-REC engine calls the EAS model

Upon receiving the request, the PAI-REC engine calls the EAS model service in debug mode. This process generates model debug information, which includes all feature information from before and after feature generation (FG).

Step 6: Model returns debug information

The EAS model service returns the generated debug information to the PAI-REC engine, which then creates a model debug log.

Step 7: Logs are persisted

The PAI-REC engine persists the model debug log to MaxCompute.

Step 8: Run offline prediction

The system retrieves the feature log from MaxCompute and uses it as an offline sample for prediction.

Step 9: Compare features

The system retrieves the model log from MaxCompute and compares the online features from the log with the offline features from the offline prediction results. This comparison generates the final report for the consistency check task.

Instructions

1. Configure a consistency check task

Prerequisites

Before you configure a consistency check task, you must add the required data sources, including a MaxCompute data source and an EAS model data source. If you want to export the results to OSS, you must also add an OSS data source.

For more information about how to add a data source, see metadata management.

Steps

In the left-side navigation pane, click Consistency Check to open the task management page. You can then create a new task or edit an existing one.

image.png

image.png

image.png

image.png

Create a consistency task:

image

Complete the following fields:

  • Task Name: Enter a custom name.

  • Associated Scenario: Select an associated recommendation scenario from the drop-down list. The selected scenario must be the same as the one used in the engine configuration and must match the scenario in the request body.

  • Sampling Rate: Adjust the sampling volume. The maximum value is 100%. A lower sampling rate can reduce the queries per second (QPS) load on the service. For example, if the service QPS is 10, a 10% sampling rate samples only one recommendation request log per second.

  • Data Fallback Address: Select the MaxCompute project where you want the data to be stored.

  • PAI-EAS Model Service Name: The name of the EasyRec Processor service used by the engine. The system obtains parameters from the corresponding model, such as the model address in OSS and the algorithm name.

  • fg_json File Name: The name of the fg.json file in DataWorks MaxCompute used for model training.

  • User Feature Table: Select the user feature data table to use.

  • user_id Field: Select the user_id field from the user feature table. This field is also the primary key of the table.

  • User Table Partition Field: Select the corresponding ds field. The partition field can be displayed in two formats: yyyymmdd or yyyy-mm-dd. You can select the display format from the drop-down list.

  • Item Feature Table: Select the item feature data table to use.

  • item_id Field: Select the item_id field from the item feature table. This field is also the primary key of the table.

  • Item Table Partition Field: Select the corresponding ds field. The partition field can be displayed in two formats: yyyymmdd or yyyy-mm-dd. You can select the display format from the drop-down list.

  • Enable Feature Comparison: This is set to Yes by default. If you select No, the system does not display detailed model features.

  • Recommendation Service Name: Select the name of the service whose logs will be used for replay. Service names are sourced from Service Management in System Settings.

  • Generate ZIP Package: This is set to No by default. To create the task without a ZIP package, click OK. To generate a ZIP package, select Yes, complete the related fields, including selecting an OSS Bucket, and entering a Workflow Name, Custom EasyRec Version, Custom EasyRec Package Path, Custom fg_jar Version, Feature Priority, and Feature Display Filter, and then click OK.

image

  • Feature Priority: The features specified in this parameter are queried from the feature table first. If a feature is empty in the feature table, the system then queries it from the behavior table. Separate multiple features with commas.

  • Feature Display Filter: After the consistency task is complete, certain features are filtered out from the comparison results.

  • Custom EasyRec Version: If the latest version of EasyRec is already deployed on the EAS service, you can specify that version here for offline use.

  • Custom EasyRec Package Path: Supports both OSS and ODPS resource paths. An OSS path has the format oss://{bucket_name}/xxx/easy_rec_ext_{version}_res.tar.gz. An ODPS resource path has the format odps://{project_name}/resources/easy_rec_ext_{version}_res.tar.gz.

  • Custom fg_jar Name: The name should be in a format like fg_on_odps-{version}-jar-with-dependencies.jar.

Note

Before you create a consistency check task, ensure that the user and item tables contain data from the current day.

2. Run the task and view results

Run the task

On the Consistency Check page, find the desired task and click Run Task in the Actions column. Specify the Duration and Environment (staging or production). Click OK to start the task. You can also cancel the task while it is running.

image.png

image.png

View the results

In the Task Logs section of the Consistency Check page, you can view the task's run status. The actual execution time is typically longer than the specified duration because data synchronization and final analysis require additional time.

image.png

When the task completes successfully, click Check Results in the Actions column of the corresponding log entry to view the report.

image.png

The results include Userid, Itemid, Requestid, and a Score Difference table sorted in descending order of difference. Click Feature Comparison in the Actions column to view the corresponding feature differences.

image.png

Generally, if the ScoreDiff value differs only beyond the fourth decimal place, you can consider the online and offline scores consistent.

image.png

Note

For an item ID, an online value of -1024 indicates that the system did not retrieve a valid item ID. For fields like title and author, the online values are default values.

You can use the filter button next to the Requestid column header to filter request IDs. For example, to exclude requests that are not an issue, select a specific Requestid in this column. This action filters out all entries with the same Requestid.

image.png

image.png

3. Use the results

If you configured advanced settings, the system saves the generated task files as a compressed package (package.zip) to the OSS location that you specified.

The following steps describe how to upload the compressed package to DataWorks to run the task manually.

  1. Download the compressed package from OSS to your local machine.

  2. Go to DataWorks and click the buttons in the following order.

image.png

  1. Click Migration Assistant, and then click DataWorks Import.

image.png

  1. In the upper-right corner, click New Import Task.

image.png

  1. Enter a custom name, click Upload File to upload the compressed package from your local machine, and then click Confirm Upload.

  2. The task is in the folder specified by the workflow_name parameter from the advanced settings.