← Back to Pull requests

[BUG] Validate v2 forecaster trainer and datamodule inputs early #2513

Open
unknown opened this pull request with 330 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 14, 2026 13:48 UTC
Author

Reference Issues/PRs

Fixes #2504.

What does this implement/fix? Explain your changes.

Reject invalid trainer and datamodule inputs before checkpoint configuration is read or training data and models are built. Previously a trainer dictionary could fail with an unrelated KeyError/AttributeError, and the wrong datamodule family could produce invalid model dimensions and a division by zero.

  • Reuse _check_type to accept only a configured Lightning Trainer or None.

  • Require a datamodule instance compatible with the concrete forecaster's get_datamodule_cls(), with a dedicated hint for passing a class instead of an instance. A separate hint covers passing the Trainer class.

  • Validate constructor arguments immediately and revalidate the effective trainer and stored datamodule at the start of fit, including parameters changed after construction.

  • Preserve None defaults, compatible subclasses, constructor trainer cloning, and per-fit trainer overrides.

  • Narrow the base datamodule annotation and document the expected instance.
  • What should a reviewer concentrate their feedback on?

    The validation timing and error messages, particularly wrong-family datamodules and class-versus-instance mistakes. The datamodule requirement comes from each concrete forecaster rather than a hard-coded model family.

    Did you add any tests for the change?

    Yes. The focused suite now has five cases covering invalid constructor trainers and datamodules plus an invalid fit(trainer=...) override.

  • All 5 cases passed locally with a temporary runtime import alias for pytorch_forecasting.base._base_pkg. A plain pytest run still fails during collection because that module is missing on v2-dev. The previous Read the Docs build failed on the same import. Related import cleanup is tracked in #2503.

  • Ruff lint and format checks, trailing whitespace, end-of-file, and AST checks passed when run directly on the two changed files. pre-commit run --files could not finish setting up its pinned hooks because the environment could not fetch them from GitHub.
  • Environment: Python 3.13, torch 2.8.0 CPU, Lightning 2.6.6.

    Any other comments?

    Targets v2-dev. Thanks to @karthik-0306 for the detailed report and proposed use of the existing validation helper. No dependency changes.

    PR checklist

  • The PR title starts with [BUG].

  • Added/modified tests.

  • Used pre-commit hooks when committing. Hook setup was blocked by network access. See the direct checks above.
  • Diff: 330 lines (+247 / -83) across 4 files Reviewer: phoeenniixx Review duration: 23205m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 330 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.347
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2513"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.4% · Safe to merge
    22.4%