Skip to content

feat(validate): report cosine similarity in output parity results#217

Open
mvanhorn wants to merge 1 commit into
FastCrest:mainfrom
mvanhorn:fix/53-cosine-similarity-parity-report
Open

feat(validate): report cosine similarity in output parity results#217
mvanhorn wants to merge 1 commit into
FastCrest:mainfrom
mvanhorn:fix/53-cosine-similarity-parity-report

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Jun 7, 2026

Summary

validate_outputs reports only absolute/relative element-wise differences, which makes it hard to tell whether a parity failure is noise or a directional mismatch (#53). This adds cosine similarity between the flattened reference and candidate tensors to the parity report.

Changes

  • ValidationResult gains a cosine_sim field (defaults to nan for backward compatibility), included in to_dict() and the logged PASS/FAIL details line.
  • Computed in float64 over the flattened tensors; zero-norm inputs report 0.0 rather than dividing by zero.
  • Pass/fail criteria are unchanged — cosine similarity is reported, not thresholded, so existing behavior is preserved.

Testing

PYTHONPATH=src python3 -m pytest tests/test_validate.py — 10 passed, including new cases for identical tensors (cos=1), opposite tensors (cos=-1), and zero-norm handling.

Closes #53

AI was used for assistance.

Adds cosine_sim to ValidationResult, to_dict(), and the logged details
line. Computed in float64 over flattened tensors; zero-norm inputs report
0.0. Pass/fail thresholds unchanged.

Closes FastCrest#53

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mvanhorn mvanhorn requested a review from rylinjames as a code owner June 7, 2026 16:03
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.

[Numerical] Add Cosine Similarity to Parity Reports

1 participant