fastai / course-v3

The 3rd edition of course.fast.ai
https://course.fast.ai/
Apache License 2.0
4.91k stars 3.57k forks source link

Fixing slow and difficult to read operation with simple matmul #566

Closed ludvik-martin closed 3 years ago

ludvik-martin commented 3 years ago

The (inp.unsqueeze(-1) * out.g.unsqueeze(1)).sum(0) is actually doing the same thing as inp.T @ out.g, but much slower. The only reason for the operation with unsqueeze() is to exercise the broadcasting. Compared with %timeit - the method with @ is nearly order of magnitude faster (on my machine)

review-notebook-app[bot] commented 3 years ago

Check out this pull request on  ReviewNB

Review Jupyter notebook visual diffs & provide feedback on notebooks.


Powered by ReviewNB

ludvik-martin commented 3 years ago

Actually, at the end of jupyter the notebook Jeremy refactores the code in the same way... Should have read it properly to the end :)