Skip to content

feat(measurement): add RAT-Bench reidentification W&B metrics#225

Merged
lipikaramaswamy merged 4 commits into
mainfrom
lipikaramaswamy/feature/rat-bench-reid-wandb-metrics
Jul 22, 2026
Merged

feat(measurement): add RAT-Bench reidentification W&B metrics#225
lipikaramaswamy merged 4 commits into
mainfrom
lipikaramaswamy/feature/rat-bench-reid-wandb-metrics

Conversation

@lipikaramaswamy

@lipikaramaswamy lipikaramaswamy commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue required: maintainer-owned benchmark measurement integration for RAT-Bench re-identification metrics.

Plan Document

No plan required: scoped measurement schema/W&B ingestion extension with regression coverage.

Summary

Adds RAT-Bench re-identification as a first-class measurement record for Anonymizer benchmark ingestion and W&B aggregation.

  • Adds rat_bench_reidentification to measurement ingress validation.
  • Adds the matching W&B table row model and outbound field policies.
  • Registers scalar aggregation fields for row counts, re-identification rates, coverage, attacker metadata, thresholds, and summary scores.
  • Treats reid_threshold as a last-value configuration scalar rather than an averaged metric.
  • Bounds RAT-Bench percentage fields to [0, 100] at ingress and W&B table-model validation.
  • Adds regression coverage for measurement ingress and W&B scalar aggregation.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • CI, release, or contributor workflow update

Contributor Checklist

  • PR title follows Conventional Commits, for example fix: handle empty entity list
  • Related issue is linked, or a maintainer-owned no-issue reason is documented above
  • For non-trivial changes, a plan document is linked above, or the no-plan reason is documented above
  • Public API impact checked; skills/anonymizer/SKILL.md updated if needed
  • No real PII added to tests, docs, notebooks, fixtures, or artifacts
  • No API keys, service tokens, private keys, credentials, or real endpoint secrets added

Validation

  • Commands run:
    • uv run pytest tests/tools/test_measurement_ingress_completion.py::test_wandb_ingress_accepts_rat_bench_reidentification_summary tests/tools/test_measurement_ingress_completion.py::test_wandb_ingress_rejects_rat_bench_percentages_above_100 tests/tools/test_measurement_wandb_logging.py::test_wandb_aggregates_rat_bench_reidentification_record tests/tools/test_measurement_wandb_logging.py::test_wandb_scalar_registry_matches_package_field_catalog
  • Skipped checks or known failures:
    • Full test suite not run locally; this PR is scoped to measurement ingress/W&B aggregation and targeted coverage passed.

Documentation and Artifacts

  • Docs updated, or not needed
  • If docs changed: make docs-build passes locally
  • If tutorial sources changed: notebooks regenerated with make convert-notebooks
  • If e2e, benchmark, or model-provider behavior changed: relevant validation is listed above

Signed-off-by: Lipika Ramaswamy <lipika.ramaswamy@gmail.com>
@lipikaramaswamy
lipikaramaswamy force-pushed the lipikaramaswamy/feature/rat-bench-reid-wandb-metrics branch from 8777f3f to 97f5b8b Compare July 17, 2026 00:16
@lipikaramaswamy
lipikaramaswamy marked this pull request as ready for review July 17, 2026 00:39
@lipikaramaswamy
lipikaramaswamy requested review from a team as code owners July 17, 2026 00:39
@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds rat_bench_reidentification as a first-class measurement record type, wiring it through ingress validation, W&B table row models, outbound field policies, and scalar aggregation field registries. The previously-flagged issues (reid_threshold classification and unbounded percentage fields) have been correctly addressed.

  • Adds RatBenchReidentificationMeasurement in wandb_ingress.py with cross-field consistency validators and a new Percentage type (ge=0, le=100) for reidentification_rate_pct and coverage_pct.
  • Registers all new fields in fields.py across the appropriate scalar groups; reid_threshold and attacker_endpoint_kind land in SCALAR_LAST_VALUE_FIELDS as run-configuration values.
  • Adds RatBenchReidentificationTableRow in wandb_models.py with matching outbound field policies; inherits elapsed_sec from _MetricTableRow and passes the module-load-time validate_outbound_field_policies() check.

Confidence Score: 4/5

Safe to merge with awareness of one ingress validation issue that could silently reject valid records from producers using rounded floats.

The cross-field validator in validate_summary_counts uses an absolute tolerance of 1e-6 when comparing the submitted percentage against the value recomputed from integer counts. Any producer that rounds its output to 2 decimal places (e.g., 28.57 instead of 28.571428... for rows_processed=7, reidentified_rows=2) will be rejected at ingress even though the data is valid. The test suite only exercises exact round fractions, so this boundary is not exercised and the failure would surface silently in production when real benchmark data arrives.

tools/measurement/measurement_tools/wandb_ingress.py — the tolerance values in validate_summary_counts for reidentification_rate_pct and coverage_pct

Important Files Changed

Filename Overview
tools/measurement/measurement_tools/wandb_ingress.py Adds RatBenchReidentificationMeasurement with cross-field validators; 1e-6 float tolerance in the derived-percentage checks is too tight for non-round fractions
src/anonymizer/measurement/fields.py Adds RAT-Bench additive, averaged, and last-value scalar field registrations; reid_threshold correctly placed in SCALAR_LAST_VALUE_FIELDS
tools/measurement/measurement_tools/validation.py Adds Percentage annotated type (ge=0, le=100) and RatBenchAttackerEndpointKind literal; clean additions with no issues
tools/measurement/measurement_tools/wandb_models.py Adds RatBenchReidentificationTableRow with Percentage-bounded fields; outbound field policies and table row registration look correct; elapsed_sec inherited from _MetricTableRow
tests/tools/test_measurement_ingress_completion.py Adds acceptance, rejection, and consistency-failure tests; all consistency tests use exact round fractions, so the 1e-6 tolerance edge case is not caught
tests/tools/test_measurement_wandb_logging.py Adds W&B scalar aggregation test; correctly verifies reid_threshold emitted without _mean suffix and attacker_model excluded from aggregation

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Producer
    participant Ingress as wandb_ingress.py
    participant Fields as fields.py
    participant Models as wandb_models.py
    participant WandB

    Producer->>Ingress: JSONL record (rat_bench_reidentification)
    Ingress->>Ingress: "RatBenchReidentificationMeasurement.model_validate()<br/>Percentage bounds [0,100], cross-field consistency"
    Ingress-->>Producer: ValidationError if invalid
    Ingress->>Fields: aggregate_measurement_scalars()
    Fields->>Fields: "SCALAR_ADDITIVE_FIELDS (row counts)<br/>SCALAR_AVERAGED_FIELDS (rate_pct, coverage_pct, mean_reid_score)<br/>SCALAR_LAST_VALUE_FIELDS (reid_threshold, attacker_endpoint_kind)"
    Fields->>Models: "WandbHistoryPayload(metrics={...})"
    Models->>Models: metric_keys_have_policy() via AGGREGATED_MEASUREMENT_FIELDS
    Models->>WandB: "Log scalars (measurement/rat_bench_reidentification/*)"
    Models->>WandB: Log table row (RatBenchReidentificationTableRow)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Producer
    participant Ingress as wandb_ingress.py
    participant Fields as fields.py
    participant Models as wandb_models.py
    participant WandB

    Producer->>Ingress: JSONL record (rat_bench_reidentification)
    Ingress->>Ingress: "RatBenchReidentificationMeasurement.model_validate()<br/>Percentage bounds [0,100], cross-field consistency"
    Ingress-->>Producer: ValidationError if invalid
    Ingress->>Fields: aggregate_measurement_scalars()
    Fields->>Fields: "SCALAR_ADDITIVE_FIELDS (row counts)<br/>SCALAR_AVERAGED_FIELDS (rate_pct, coverage_pct, mean_reid_score)<br/>SCALAR_LAST_VALUE_FIELDS (reid_threshold, attacker_endpoint_kind)"
    Fields->>Models: "WandbHistoryPayload(metrics={...})"
    Models->>Models: metric_keys_have_policy() via AGGREGATED_MEASUREMENT_FIELDS
    Models->>WandB: "Log scalars (measurement/rat_bench_reidentification/*)"
    Models->>WandB: Log table row (RatBenchReidentificationTableRow)
Loading

Reviews (4): Last reviewed commit: "fix(measurement): validate RAT-Bench rei..." | Re-trigger Greptile

Comment thread src/anonymizer/measurement/fields.py
Comment thread tools/measurement/measurement_tools/wandb_ingress.py Outdated
Signed-off-by: Lipika Ramaswamy <lipika.ramaswamy@gmail.com>
Comment thread tools/measurement/measurement_tools/wandb_ingress.py
Signed-off-by: Lipika Ramaswamy <lipika.ramaswamy@gmail.com>
Comment thread tools/measurement/measurement_tools/wandb_ingress.py
Signed-off-by: lipikaramaswamy <lramaswamy@nvidia.com>
@lipikaramaswamy
lipikaramaswamy merged commit c96c6e3 into main Jul 22, 2026
15 checks passed
@lipikaramaswamy
lipikaramaswamy deleted the lipikaramaswamy/feature/rat-bench-reid-wandb-metrics branch July 22, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants