Skip to content

Fix Jacobian for dynamic-to-fixed transforms - #1442

Open
yebai wants to merge 6 commits into
mainfrom
fix/issue-1407-logjac
Open

Fix Jacobian for dynamic-to-fixed transforms#1442
yebai wants to merge 6 commits into
mainfrom
fix/issue-1407-logjac

Conversation

@yebai

@yebai yebai commented Aug 22, 2026

Copy link
Copy Markdown
Member

Return target forward Jacobians, add a DynamicLink-to-FixedTransform regression test

Fix #1407

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.84%. Comparing base (a8b0145) to head (47431f5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1442      +/-   ##
==========================================
+ Coverage   81.70%   81.84%   +0.13%     
==========================================
  Files          50       50              
  Lines        3581     3581              
==========================================
+ Hits         2926     2931       +5     
+ Misses        655      650       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

DynamicPPL.jl documentation for PR #1442 is available at:
https://TuringLang.github.io/DynamicPPL.jl/previews/PR1442/

@shravanngoswamii shravanngoswamii 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.

Can we say inv_logjac is now dead in the FixedTransform? -- needs some docs update, is it fine if I push few commits to your PR?

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Benchmarks @ 47431f5

Performance Ratio: gradient time divided by log-density time.

For very small models these ratios are noisy across runs and machines; raw primal and gradient timings are more reliable. The benchmarks are aimed at DynamicPPL developers and mainly catch obvious allocation or type-stability regressions. See benchmark notes for details.

===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     4.63 ns       12.73    1471.34       40.50     12.38
Simple assume observe*         1      true     4.63 ns       12.54    1716.71       40.18     12.14
Smorgasbord                  201     false      6.0 μs       66.30     133.52        6.93      9.71
Smorgasbord                  201      true     7.59 μs       76.12     143.70        6.35      7.03
Loop univariate 1k          1000     false     17.5 μs      982.79     307.90        8.26      6.66
Loop univariate 1k          1000      true     19.0 μs     1483.43     286.34        7.64      6.18
Multivariate 1k             1000     false     21.9 μs      355.34      79.18        9.55      2.79
Multivariate 1k             1000      true     27.1 μs      267.36      56.16        8.12      2.97
Loop univariate 10k        10000     false    172.0 μs    12079.17     329.25        8.55      6.72
Loop univariate 10k        10000      true    186.0 μs    11879.77     308.99        7.91      6.17
Multivariate 10k           10000     false    194.0 μs     5747.98      91.95       11.64      2.30
Multivariate 10k           10000      true    197.0 μs     5688.03      90.05       11.42      2.29
Dynamic                       15     false     1.36 μs         err      44.49       14.89     12.02
Dynamic                       10      true     1.92 μs        1.79      61.00       22.21     20.36
Submodel*                      1     false     4.64 ns       12.60    1749.19       40.41     12.38
Submodel*                      1      true     4.64 ns       12.60    1882.50       40.46     12.26
LDA                           12      true     23.8 μs        0.45       1.94       33.51       err
===================================================================================================
Main @ a8b0145
===================================================================================================
                                               eval                       gradient                 
                                            ----------  -------------------------------------------
Model                        dim    linked      primal     FwdDiff    RvsDiff    Mooncake    Enzyme
---------------------------------------------------------------------------------------------------
Simple assume observe*         1     false     4.63 ns       12.63    1561.33       39.65     12.43
Simple assume observe*         1      true     4.63 ns       12.64    1718.38       39.92     12.30
Smorgasbord                  201     false      6.0 μs       66.66     133.34        6.94      9.46
Smorgasbord                  201      true     7.61 μs       66.45     152.95        6.21      6.98
Loop univariate 1k          1000     false     17.6 μs      942.60     310.17        8.43      6.73
Loop univariate 1k          1000      true     19.0 μs     1461.31     284.67        7.66      6.14
Multivariate 1k             1000     false     22.1 μs      355.85      79.90        8.83      2.96
Multivariate 1k             1000      true     32.0 μs      332.81      51.81        7.18      3.30
Loop univariate 10k        10000     false    173.0 μs    12519.57     353.50        8.67      6.88
Loop univariate 10k        10000      true    186.0 μs    12732.46     322.63        8.34      6.36
Multivariate 10k           10000     false    205.0 μs     5161.69      85.75       11.73      2.41
Multivariate 10k           10000      true    206.0 μs     5102.01      89.43       11.27      2.57
Dynamic                       15     false     1.41 μs         err      43.50       14.75     11.69
Dynamic                       10      true     1.97 μs        1.88      62.59       18.36     24.82
Submodel*                      1     false     4.63 ns       12.64    1743.24       39.98     12.40
Submodel*                      1      true     4.63 ns       12.69    1900.02       40.27     12.34
LDA                           12      true     23.3 μs        0.63       2.06       34.08       err
===================================================================================================
Environment
Julia Version 1.11.9
Commit 53a02c0720c (2026-02-06 00:27 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 7763 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

The existing assertion uses `dist`'s own link transform as the target, so the
target's forward Jacobian and the source's come out numerically identical and
either would satisfy it. `other_ft` tells them apart.
The table claimed a `FixedTransform` input errors against a `DynamicLink` or
`Unlink` target. Both convert fine; only a mismatched `FixedTransform` target
errors. It also had no column for `FixedTransform` targets, which is the path
this branch changes. Spelling out that the log-Jacobian is the target's alone
makes the contract the fix restores explicit.
Covers the bug where it counted: `InitFromParams` handing linked values to a
fixed-transform strategy. The unit tests exercise `apply_transform_strategy`
branch by branch, which is how the doubled Jacobian slipped through.
@shravanngoswamii

Copy link
Copy Markdown
Member

@yebai Ready to merge, I will release it if you allow merging!

@yebai

yebai commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

It's better to have a look from a fresh perspective. @sunxd3

@sunxd3

sunxd3 commented Aug 23, 2026

Copy link
Copy Markdown
Member

Sorry it took me a while, chasing a ghost that's turned out to be nothing. The changes here look good to me. Thanks for working on this!

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.

apply_transform_strategy returns wrong logjac for DynamicLink → FixedTransform

3 participants