← Back to Pull requests

Skip pushforward lookup for non-differentiable calls #2211

Open
Vedant2005goyal opened this pull request with 22 lines diff across 2 files
View on GitHub
Vedant2005goyal Vedant2005goyal commented on Sep 27, 2026 13:23 UTC
Author

In reverse mode, Clad tried to look up custom derivatives for calls marked as non-differentiable. This caused errors for integer arguments because built-in pushforwards expect floating-point types.
For example:

  double result = 0.5 * std::log(2);

Clad tried to find a pushforward for std::log<int>, which failed to match the standard log_pushforward<T> and caused compilation to fail. Since non-differentiable calls have zero derivatives, the pushforward is not needed. This patch skips the lookup for such calls and avoids the compilation error.

Diff: 22 lines (+21 / -1) across 2 files Reviewer: vgvassilev Review duration: 15523m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.23) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.23 · 22 lines diff across 2 files
0.23
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
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.188
Real PR Conversation Timeline
8 items
github-actions[bot] github-actions[bot] commented on code on Sep 27, 2026 13:26 UTC
Code Review
lib/Differentiator/DiffPlanner.cpp:1
@@ -1851,7 +1851,9 @@ static QualType GetDerivedFunctionType(const CallExpr* CE) {
         E->getDirectCallee();
     bool shouldUseRestoreTracker =
         utils::shouldUseRestoreTracker(request.Function);
-    bool hasCustomPullback = LookupCustomDerivativeDecl(request);
+    bool hasCustomPullback =
+        !(nonDiff && request.Mode == DiffMode::pushforward) &&

warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]

        (!nonDiff || request.Mode != DiffMode::pushforward) &&

github-actions[bot] github-actions[bot] commented on Sep 27, 2026 13:26 UTC
Reviewer

clang-tidy made some suggestions

codecov[bot] codecov[bot] commented on Sep 27, 2026 19:46 UTC
Bot

Codecov Report


:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

vgvassilev vgvassilev commented on code on Sep 28, 2026 17:17 UTC
Code Review
lib/Differentiator/DiffPlanner.cpp:1
@@ -1852,7 +1852,9 @@ static QualType GetDerivedFunctionType(const CallExpr* CE) {
         E->getDirectCallee();
     bool shouldUseRestoreTracker =
         utils::shouldUseRestoreTracker(request.Function);
-    bool hasCustomPullback = LookupCustomDerivativeDecl(request);
+    bool hasCustomPullback =

Worth a line saying why this guard is here.

A call whose arguments are all literals is marked non-differentiable further up, and the built-in pushforwards are templated on a floating-point type -- so the lookup finds log<int>, fails to match, and reports a mismatch for a derivative that would never be called. None of that is recoverable from the expression, and the next reader cannot tell whether the mode test is essential or incidental.

vgvassilev vgvassilev commented on Sep 28, 2026 17:18 UTC
Reviewer

Sound as far as I can check without building: the failure reproduces on master, fn36 fails without the change, and neither consumer of hasCustomPullback shifts. One remark inline.

Also, make sure you address the clang-tidy suggestions.

This review came from ai-vgvassilev.

github-actions[bot] github-actions[bot] commented on Sep 30, 2026 11:04 UTC
Bot

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] github-actions[bot] commented on Sep 30, 2026 11:07 UTC
Bot

clang-tidy review says "All clean, LGTM! :+1:"

Reviewers
Assignees
Vedant2005goyal Vedant2005goyal
Labels
risk: low confidence: 91.3% 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: 23.2% (LOW) · Higher = larger blast radius
23.2%
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: 91.3% · Lower = rushed or shallow review
91.3%
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: 2% · Safe to merge
2%