Skip to content

Handle vectorization of Alloc nodes#1943

Merged
ricardoV94 merged 1 commit intopymc-devs:mainfrom
ricardoV94:alloc_vectorize
Mar 6, 2026
Merged

Handle vectorization of Alloc nodes#1943
ricardoV94 merged 1 commit intopymc-devs:mainfrom
ricardoV94:alloc_vectorize

Conversation

@ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Mar 6, 2026

This started being a problem in the marginalRV logp for backends that hate shapes (guess who), reported by @jessegrabowski

Incredibly we had managed all this time without a specific handling other than the useless Blockwise

old_val, *old_shape = node.inputs
[old_alloc] = node.outputs

assert len(shape) == len(old_shape), (
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the number of dims have to change for a vectorize 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Alloc takes each dimension length as an input, there's no way to make a new input out of thin air with vectorization, at most you can have sone of the dimension lengths come with batch dims

)

if not all(all(s.broadcastable) for s in shape):
# May imply a non-square Alloc
Copy link
Member

Choose a reason for hiding this comment

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

what does "non-square" alloc mean

Copy link
Member Author

Choose a reason for hiding this comment

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

n = lscalar()
out = alloc(1.0 ,n)

batch_n = lvector(shape=(2,))
batch_out = vectorize_graph(out, {n: batch_n})
batch_out.eval({batch_n: [3, 6]})

@ricardoV94 ricardoV94 merged commit d84cd64 into pymc-devs:main Mar 6, 2026
66 checks passed
@ricardoV94 ricardoV94 deleted the alloc_vectorize branch March 6, 2026 21:25
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