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

PyTensor intro walkthrough #34

Merged
merged 4 commits into from
Mar 3, 2025
Merged

PyTensor intro walkthrough #34

merged 4 commits into from
Mar 3, 2025

Conversation

ricardoV94
Copy link
Member

Closes #12
Closes #13

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@ricardoV94
Copy link
Member Author

One thing that may be useful is to wrap up with an applied simple example. Logistic regression with a naive gradient descent?

@jessegrabowski jessegrabowski marked this pull request as ready for review March 2, 2025 14:58
@jessegrabowski
Copy link
Member

@ricardoV94 ping for review on your own PR

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

Typo: hackabel


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

fused log add is incorrect (as we'll eventually mention fusion optimizations one way or another). The owner is log, which takes as input the output of an add operation


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

Line #2.    y = np.exp(x)

Do you want to use np.exp?


Reply via ReviewNB

Copy link
Member

Choose a reason for hiding this comment

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

Nope!

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

I wouldn't use the word side effects.Perhaps say it will change the meaning of the graph_


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

Should print shape to show something changed, and I would call x,x_vec


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

A bit odd to have this between the vectorization and scalarization?


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

Vectorization was one such case of graph-to-graph-transformation as well?


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

loop lifting -> loop fusion

More interesting is cos writing directly on the squeezed output. In numpy this would be doing the optimiztaino np.cos(x, out=x) which quickly becomes unreadable. Also squeeze is a view of CGemv so no intermediate allocation there either, but we can omit that. If you want to show use print_memory_map in the new version that shows both the destroy and view maps


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

typo audiance


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

The use of two functions inadvertently highlights one of the advantages of the pytensor graph-way of building computations. You don't need to think in advance how to define intermediate functions so that you can get intermediate outputs from specific inputs to JIT (as you would need to in Numba/JAX). You just grab the relevant variable and plug them as inputs/outputs. May be worth to mention.


Reply via ReviewNB

@@ -0,0 +1,2873 @@
{
Copy link
Member Author

@ricardoV94 ricardoV94 Mar 2, 2025

Choose a reason for hiding this comment

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

There's no second step, we just pass exp(new_input) instead of old_input . I just called that log_x because once you exponentiate it you get x (old input)


Reply via ReviewNB

Copy link
Member

Choose a reason for hiding this comment

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

I think it's too big brain, I simplified it.

@ricardoV94
Copy link
Member Author

Looks good @jessegrabowski , left some small notes

@ricardoV94
Copy link
Member Author

Left one minor comment, looks great otherwise

@ricardoV94 ricardoV94 merged commit 986a0da into main Mar 3, 2025
@ricardoV94 ricardoV94 deleted the intro branch March 3, 2025 08:49
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.

One minute example Conceptual intro
2 participants