← Back to Pull requests

[BUG] fix AggregationMetric target weighting when y_pred has an extra dimension #2541

Closed
unknown closed this pull request without merging on Nov 28, 2026 15:23 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 21:03 UTC
Author

LLM generated content, by Claude Opus 5.5. Credit is shared: the agent found and diagnosed the bug, drafted the issue and the test, and ran the checks; the human chose this bug among the candidates, filed the issue, and applied the fix and the test in the branch.

Reference Issues/PRs

Fixes #2540

What does this implement/fix? Explain your changes.

AggregationMetric._calculate_mean broadcast the weight to the shape of y_pred when weighting the target:

y_mean = (target * unsqueeze_like(weight, y_pred)).sum(0) / weight.sum(0)

When predictions have an extra dimension (quantiles, distribution parameters), the (B, T) target was multiplied by a (B, T, 1) or (B, 1, 1) weight. This raised a RuntimeError for B != T, and gave a wrongly shaped mean for B == T. The weight also exists without user weights: for a PackedSequence target the method uses the (B, T) length mask as the weight.

The weight is now broadcast to target for the target mean. The prediction mean is unchanged.

What should a reviewer concentrate their feedback on?

The one-line change in _calculate_mean, and whether the test's reference (weighted means of target and prediction computed by hand, then QuantileLoss) matches the intended semantics.

Did you add any tests for the change?

test_aggregation_metric_weighted_with_quantiles, parametrized over (B, T) and (B,) weights, with B=4, T=3, 7 quantiles and random weights:

  • on main: both cases fail with RuntimeError: The size of tensor a (4) must match the size of tensor b (3);

  • with the fix: both pass, and tests/test_metrics.py passes (72 passed, 6 skipped, the skips are the cpflows soft dependency).
  • pre-commit passes on the changed files.

    PR checklist

  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG].

  • Added/modified tests

  • Used pre-commit hooks when committing to ensure that code is compliant with hooks.
  • 🤖 Generated with Claude Code

    Diff: 253 lines (+189 / -64) across 3 files Reviewer: fnhirwa Review duration: 6859m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.44) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 253 lines diff across 3 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.331
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #2541"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44% (MEDIUM) · Higher = larger blast radius
    44%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.4% · Safe to merge
    17.4%