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

Big speedup #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Big speedup #55

wants to merge 3 commits into from

Conversation

panzi
Copy link

@panzi panzi commented Oct 19, 2023

With these changes I could speed up execution a lot. On my machine instead of over 2 minutes it now takes about 14 seconds (including saving the plot as SVG, 12 seconds without that).

The changes are:
Because the expression tree is always exactly the same (when not batching) it can be re-used and instead of re-creating the whole tree every time the new refresh() method recalculates all the values in-place. This method also sets grad to 0.0 in every node, so zero_grad() isn't needed in the optimization loop anymore.

Note that for this improvement to work with batching you need a little bit more preparation. That is, you need to create Xb and yb dummy lists of batch size containing Value objects and use these to setup the calculations before the optimization loop. In the loss() function you then need make the random index selection and update the value.data attributes of all the objects in Xb and yb before running refresh(). I didn't include an example for that at the moment. I also added code to the demo that demonstrates batching.

@panzi panzi changed the title Non batch speedup Big speedup Oct 19, 2023
@ethanyanjiali
Copy link

Good idea but it also makes this project less intuitive with non-essential optimizations

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.

2 participants