aesara-devs / aesara

Aesara is a Python library for defining, optimizing, and efficiently evaluating mathematical expressions involving multi-dimensional arrays.
https://aesara.readthedocs.io
Other
1.18k stars 153 forks source link

Reduce `aesara.compile.builders.infer_shape`'s recursions #1117

Open brandonwillard opened 2 years ago

brandonwillard commented 2 years ago

aesara.compile.builders.infer_shape recurses in a way that's not optimal for large graphs. This is especially problematic for large Scan graphs, since Scan.infer_shape uses the aforementioned infer_shape function.

anirudhacharya commented 2 years ago

@brandonwillard can you please share an example of a large Scan graph with which I can replicate this issue locally? I would like to attempt to solve this bug.

brandonwillard commented 2 years ago

@brandonwillard can you please share an example of a large Scan graph with which I can replicate this issue locally? I would like to attempt to solve this bug.

A useful MWE in this situation would, for example, demonstrate how aesara.compile.builders.infer_shape is stack bound (e.g. turn the issue into a bug via a RecursionError). Such an example could also serve as a good unit test for the changes requested by this issue.

Unfortunately, I don't have one on hand, but, regardless, creating one would serve as good first steps toward solving this issue, especially since it could clarify some details regarding exactly when/how the current approach becomes problematic.