Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuse CAReduces and Elemwises #1116

Closed
brandonwillard opened this issue Aug 15, 2022 · 1 comment · Fixed by #1285
Closed

Fuse CAReduces and Elemwises #1116

brandonwillard opened this issue Aug 15, 2022 · 1 comment · Fixed by #1285
Labels

Comments

@brandonwillard
Copy link
Member

We aren't currently converting CAReduces of Elemwises into single CAReduces:

import aesara
import aesara.tensor as at


x = at.vector("x")
y = at.exp(x).sum()

y_fn = aesara.function([x], y)

aesara.dprint(y_fn)
# Sum{acc_dtype=float64} [id A] 1
#  |Elemwise{exp,no_inplace} [id B] 0
#    |x [id C]

As the example shows, we first compute the Elemwise then immediately reduce it. Instead, we could fuse the CAReduce and Elemwise scalar Ops (i.e. create a Composite scalar Op corresponding to add(exp(x), exp(y))) and use that in a single CAReduce node that avoids the need for intermediate storage.

The rewrites required to do this would incorporate most of the same logic from aesara.tensor.basic_opt.FusionOptimizer, but, instead of producing another Elemwise, it would result in a new CAReduce.

@brandonwillard
Copy link
Member Author

brandonwillard commented Aug 15, 2022

This was originally proposed in Theano/Theano#1167 and mentioned in #1089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant