Skip to content

[tmva][sofie] Support Clad forward mode in generated inference code - #23077

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:sofie-clad-forward-mode
Aug 14, 2026
Merged

[tmva][sofie] Support Clad forward mode in generated inference code#23077
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:sofie-clad-forward-mode

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

Emit "_pushforward" custom derivatives for the standalone helper functions (Gemm_Call, Copy, Fill, Relu) next to the existing pullbacks, so that clad::differentiate() works on the generated code — and with it Hessians, which Clad computes by reverse differentiating the forward derivative code.

Also generate a Session::SetWeightsToZero() method for building the zero-weight tangent Sessions that forward-mode differentiation needs (the weights are constants, not inputs).

Add a TestCladAutodiff test on a Gemm+Sigmoid model that validates forward-mode directional derivatives against the reverse mode gradient, and a full Hessian, computed via exact Hessian-vector products (reverse-over-forward), against finite differences of the exact gradient. The Clad limitations and workarounds all this rests on are documented in the emitted code and in the test.

🤖 Done with the help of AI

This is needed for full analytic Hessian support of RooFit models that include ONNX functions.

Emit "_pushforward" custom derivatives for the standalone helper
functions (Gemm_Call, Copy, Fill, Relu) next to the existing pullbacks,
so that clad::differentiate() works on the generated code — and with it
Hessians, which Clad computes by reverse-differentiating the forward
derivative code.

Also generate a Session::SetWeightsToZero() method for building the
zero-weight tangent Sessions that forward-mode differentiation needs
(the weights are constants, not inputs).

Add a TestCladAutodiff test on a Gemm+Sigmoid model that validates
forward-mode directional derivatives against the reverse-mode gradient,
and a full Hessian, computed via exact Hessian-vector products
(reverse-over-forward), against finite differences of the exact
gradient. The Clad limitations and workarounds all this rests on are
documented in the emitted code and in the test.

🤖 Done with the help of AI
@github-actions

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 15h 12m 33s ⏱️
 3 856 tests  3 855 ✅ 0 💤 1 ❌
78 579 runs  78 577 ✅ 1 💤 1 ❌

For more details on these failures, see this check.

Results for commit 90026a6.

@lmoneta lmoneta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@guitargeek
guitargeek merged commit 85aee28 into root-project:master Aug 14, 2026
40 of 42 checks passed
@guitargeek
guitargeek deleted the sofie-clad-forward-mode branch August 14, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants