Skip to content

Add PDMats extension#3030

Open
oschulz wants to merge 2 commits into
EnzymeAD:mainfrom
oschulz:pdmats-extension
Open

Add PDMats extension#3030
oschulz wants to merge 2 commits into
EnzymeAD:mainfrom
oschulz:pdmats-extension

Conversation

@oschulz

@oschulz oschulz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

PDMats' scalar accumulation loops don't trace, use broadcasted reductions instead.

Came across this on while making MGVI.jl Reactant-compatible (in flight, depends on this PR).

AI-generated (Claude Fable at max effort), human reviewed.

oschulz added 2 commits July 8, 2026 07:37
Traced values captured by closures that are called (but not otherwise
referenced) inside @trace while/for bodies became block arguments of
the while regions without matching while-loop operands, failing MLIR
verification with 'expect operands to be compatible with body block
arguments'. Treat single-name function calls in the loop condition and
body as external symbols, so such closures become loop-carried
arguments and the traced values they capture become proper while-loop
operands.

Created by generative AI.
PDMats.wsumsq and PDMats.invwsumsq use scalar accumulation loops, which
degrade to one op per element under tracing (and fail under
allowscalar(false)). They underlie e.g. the logpdf of diagonal-covariance
MvNormal distributions. Provide broadcasted reductions for traced arrays
via a package extension.

Created by generative AI.
@oschulz

oschulz commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@wsmoses is this acceptable, in principle?

# closure captures of the generated body function (which would result in
# region block arguments without matching operands). Only plain names can
# refer to local callables:
for symbols_state in (cond_symbols, body_symbols)

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.

# region block arguments without matching operands). Only plain names can
# refer to local callables:
for symbols_state in (cond_symbols, body_symbols)
for fn in symbols_state.funccalls

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.

@oschulz the pdmats extension looks pretty easy to give a quick approve to, this part here requires more scrutiny

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please make another pr for that change if not strictly required here. Also I would maybe apply that only if !isdefined(__module__, only(fn.parts)) to limit the number of arguments to each closures

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.

3 participants