-
-
Notifications
You must be signed in to change notification settings - Fork 154
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Replace C-code generation and compilation backend #312
Comments
Totally agree. I suppose we first need some functionality to enable usage of Cython. |
It's not actually that difficult to use Cython-generated code in Aesara right now. For instance, an My impression is that this approach isn't the best because it doesn't use Aesara's C-based thunk machinery. This machinery is assumedly faster than the corresponding pure Python machinery, perhaps due to reduced Python-to-C and C-to-Python overhead—among other things. Aesara graph evaluation primer
For anyone who's not familiar with the idea of a "thunk" in Aesara, this paragraph might help. Simply put, a "thunk" is an argumentless function that calls an Here's a simple example: inputs = [1, 2]
outputs = [None]
class SomeOp(Op):
def perform(self, inputs, outputs):
outputs[0] = inputs[0] + inputs[1]
def a_thunk(inputs=inputs, outputs=outputs):
SomeOp().perform(inputs, outputs)
a_thunk()
# `outputs` should contain `3` Those storage arrays make up the graph's memory model, and they're stored inside a thunk function's closure. When the thunk is evaluated those output arrays are populated with the computed values. A thunk is created for each node/ Continuing from the previous example: other_outputs = [None]
class SomeOtherOp(Op):
def perform(self, inputs, outputs):
outputs[0] = inputs[0]**2
def another_thunk(inputs=outputs, outputs=other_outputs):
SomeOtherOp().perform(inputs, outputs)
# This thunk depends on the output of the previous thunk
another_thunk() This allows Here's what # Using the example thunks above, we can create a function
# that computes the graph for `(a + b)**2`
def compiled_graph_fn(a, b):
inputs[0] = a
inputs[1] = b
for thunk in [a_thunk, another_thunk]:
thunk()
return other_outputs[0] The How compiled C code is usedThere are a few places where the C and Python thunks are clearly distinguished. In the From the Python side (e.g. when graph evaluation is performed using the pure Python From what I can tell, Regarding those thunk pointers, they seem to come from |
For anyone who wants to try this (e.g. @aseyboldt for #327), take a look at how |
Actually, it looks like it might be as simple as creating an The The first two values (i.e. the |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
The text-based C-code generation and compilation backend in Aesara is difficult to use, debug, maintain, and extend. We need to fix that ASAP.
Cython is a well established Python-to-C transpiler that provides a much cleaner, automatic means of generating the same kind of Python C API code that's written by hand in Aesara. Here are some possible benefits to replacing our current C implementations with Cython-generated C code:
Op
implementations, resulting in more C-only code (i.e. fewer calls to-and-from Python/C during graph evaluation)Subtensor*
/indexing operations with a little bit of Cython (instead of our very limited C implementations for only certain types of indexing)This general idea has been brought up in numerous different locations, so I'm creating this issue as a means of collecting all the relevant details, ideas, discussions, requirements, etc., into one place.
Related issues:
Function
evaluation code #306The text was updated successfully, but these errors were encountered: